Ad Widget

Collapse

How to monitor asterisk or other SIP servers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Unxs
    Junior Member
    • Sep 2010
    • 5

    #1

    How to monitor asterisk or other SIP servers

    I hacked sipsak to be able to use this very small and fast binary SIP tool to be able to be used directly as an external item.

    Here is the sipsak patch:

    Code:
    [root@rc3 ~]# diff -crB sipsak-0.9.6 sipsak-0.9.6-zabbix | more
    diff -crB sipsak-0.9.6/exit_code.c sipsak-0.9.6-zabbix/exit_code.c
    *** sipsak-0.9.6/exit_code.c    Sat Jan 28 15:11:50 2006
    --- sipsak-0.9.6-zabbix/exit_code.c     Wed Mar  9 15:40:45 2011
    ***************
    *** 43,48 ****
    --- 43,61 ----
                            else {
                                    exit(code);
                            }
    +               case EM_ZABBIX:
    +                       if (code == 0) {
    +                               printf("100\n");
    +                               exit(0);
    +                       }
    +                       else if (code == 4) {
    +                               printf("200\n");
    +                               exit(0);
    +                       }
    +                       else {
    +                               printf("400\n");
    +                               exit(0);
    +                       }
                    case EM_NAGIOS:
                            if (code == 0) {
                                    printf("SIP ok\n");
    diff -crB sipsak-0.9.6/exit_code.h sipsak-0.9.6-zabbix/exit_code.h
    *** sipsak-0.9.6/exit_code.h    Sat Jan 28 15:11:50 2006
    --- sipsak-0.9.6-zabbix/exit_code.h     Wed Mar  9 15:40:46 2011
    ***************
    *** 20,26 ****
      #ifndef SIPSAK_EXITCODE_H
      #define SIPSAK_EXITCODE_H
    
    ! enum exit_modes { EM_DEFAULT, EM_NAGIOS };
    
      extern enum exit_modes exit_mode;
    
    --- 20,26 ----
      #ifndef SIPSAK_EXITCODE_H
      #define SIPSAK_EXITCODE_H
    
    ! enum exit_modes { EM_DEFAULT, EM_NAGIOS, EM_ZABBIX };
    
      extern enum exit_modes exit_mode;
    
    diff -crB sipsak-0.9.6/sipsak.c sipsak-0.9.6-zabbix/sipsak.c
    *** sipsak-0.9.6/sipsak.c       Sat Jan 28 15:11:50 2006
    --- sipsak-0.9.6-zabbix/sipsak.c        Wed Mar  9 15:40:24 2011
    ***************
    *** 863,868 ****
    --- 863,921 ----
                            namebeg=0;
            }
            else {
    +
    +               //Special single arg version for Zabbix server external script
    +               //To avoid DNS resolve issues zabbix should use IP and not hostname
    +               if(argc==2)
    +               {
    +                       char cSIPServer[128]={""};
    +
    +                       sprintf(cSIPServer,"sip:%.123s",argv[1]);
    +
    +                       parse_uri(cSIPServer, &scheme, &user, &host, &port);
    +                       if (scheme == NULL) {
    +                               fprintf(stderr, "error: missing scheme in sip uri\n");
    +                               exit_code(2);
    +                       }
    +                       username = user;
    +                       if (host != NULL) {
    +                               domainname = host;
    +                       }
    +                       else {
    +                               fprintf(stderr, "error: missing hostname in sip uri\n");
    +                               exit_code(2);
    +                       }
    +                       if (port && !rport) {
    +                               rport = port;
    +                       }
    +                       if (is_ip(domainname)) {
    +                               address = getaddress(domainname);
    +                               if (transport == 0)
    +                                       transport = SIP_UDP_TRANSPORT;
    +                       }
    +                       else {
    +                               if (!rport && !address) {
    +                                       address = getsrvadr(domainname, &rport, &tsp);
    +                                       if (tsp != 0)
    +                                               transport = tsp;
    +                               }
    +                               if (!address) {
    +                                       address = getaddress(domainname);
    +                               }
    +                               if (!address){
    +                                       fprintf(stderr, "error:unable to determine the IP address for: %s\n", domainname);
    +                                       exit_code(2);
    +                               }
    +                       }
    +                       if (port != 0) {
    +                               backup = str_alloc(strlen(domainname)+1+6);
    +                               snprintf(backup, strlen(domainname)+6, "%s:%i", domainname, port);
    +                               domainname = backup;
    +                       }
    +                       uri_b=1;
    +                       exit_mode=EM_ZABBIX;
    +               }
    +
                    if (!uri_b) {
                            fprintf(stderr, "error: a spi uri is needed at least\n");
                            exit_code(2);
    If you need any help or have any questions about monitoring VOIP via Zabbix contact me.
  • retobuergi
    Junior Member
    • Jul 2013
    • 1

    #2
    Details

    Hello UNXS,
    do you have more details how implement sipsak to zabbix as an external script.

    regards
    Reto

    Comment

    • Unxs
      Junior Member
      • Sep 2010
      • 5

      #3
      I am on vacation at the moment. But when I get back to the office I can provide all the information. If I remember correctly it is a "per manual" external script. The only hard part is getting the sipsak binary to follow Zabbix API.

      Comment

      Working...