Ad Widget

Collapse

External check

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mike13
    Member
    • Apr 2010
    • 30

    #1

    External check

    Hi,

    I wrote a script to check the reachability of my MPLS VPN devices. When i run my script manually it returns the correct value( device alive=1, unreachable=0). But, i can't figure out why zabbix always returns the value 0 weather the host is reacheble or not.

    The script:
    Code:
    #!/bin/sh
    fping -q -I $1 $2 > /dev/null 2>&1
    if [ $? == 0 ]; then
    	echo 1
    	exit 1
    else
    	echo 0
    	exit 0
    
    fi
    Item:
    Host: Test
    Description: check
    Type: External check
    Key: check.sh[eth1.153,{IPADDRESS}]



    Tigger:
    Name: {HOSTNAME} is Unreachable
    Expression (Toggle input method): {Test:check.sh[eth1.153,{IPADDRESS}].last(90)}=0
    Comments: Can not Ping {HOSTNAME} 3 times in last 1 minute 30


    The zabbix log file shows:
    Code:
    762:20100624:114705.651 In substitute_simple_macros (data:'check.sh[eth1.153,{IPADDRESS}]')
    762:20100624:114705.651 End substitute_simple_macros (result:'check.sh[eth1.153,192.168.49.124]')
    762:20100624:114705.651 In get_value() key:'check.sh[eth1.153,{IPADDRESS}]'
    762:20100624:114705.651 In get_value_external() key:'check.sh[eth1.153,{IPADDRESS}]'
    762:20100624:114705.651 DEBUG [check.sh]
    762:20100624:114705.651 params [eth1.153,192.168.49.124]
    762:20100624:114705.651 /etc/zabbix/externalscripts/check.sh 192.168.49.124 eth1.153,192.168.49.124
    762:20100624:114705.657 Result [0]
    762:20100624:114705.657 End of get_value():SUCCEED
    Does anyone know how to do this?
    Many thanks,

    Mike,
    Last edited by mike13; 24-06-2010, 11:34.
  • ruswold
    Senior Member
    • Mar 2010
    • 210

    #2
    Originally posted by mike13
    Hi,

    I wrote a script to check the reachability of my MPLS VPN devices. When i run my script manually it returns the correct value( device alive=1, unreachable=0). But, i can't figure out why zabbix always returns the value 0 weather the host is reacheble or not.

    The script:
    Code:
    #!/bin/sh
    fping -q -I $1 $2 > /dev/null 2>&1
    if [ $? == 0 ]; then
    	echo 1
    	exit 1
    else
    	echo 0
    	exit 0
    
    fi
    Item:
    Host: Test
    Description: check
    Type: External check
    Key: check.sh[eth1.153,{IPADDRESS}]



    Tigger:
    Name: {HOSTNAME} is Unreachable
    Expression (Toggle input method): {Test:check.sh[eth1.153,{IPADDRESS}].last(90)}=0
    Comments: Can not Ping {HOSTNAME} 3 times in last 1 minute 30


    The zabbix log file shows:
    Code:
    762:20100624:114705.651 In substitute_simple_macros (data:'check.sh[eth1.153,{IPADDRESS}]')
    762:20100624:114705.651 End substitute_simple_macros (result:'check.sh[eth1.153,192.168.49.124]')
    762:20100624:114705.651 In get_value() key:'check.sh[eth1.153,{IPADDRESS}]'
    762:20100624:114705.651 In get_value_external() key:'check.sh[eth1.153,{IPADDRESS}]'
    762:20100624:114705.651 DEBUG [check.sh]
    762:20100624:114705.651 params [eth1.153,192.168.49.124]
    762:20100624:114705.651 /etc/zabbix/externalscripts/check.sh 192.168.49.124 eth1.153,192.168.49.124
    762:20100624:114705.657 Result [0]
    762:20100624:114705.657 End of get_value():SUCCEED
    Does anyone know how to do this?
    Many thanks,

    Mike,
    First parameter in zabbix is host or ip address of host, therefore try use in code script
    fping -q -I $2 $1 > /dev/null 2>&1

    and item key
    check.sh[eth1.153]

    Comment

    • mike13
      Member
      • Apr 2010
      • 30

      #3
      Originally posted by ruswold
      First parameter in zabbix is host or ip address of host, therefore try use in code script
      fping -q -I $2 $1 > /dev/null 2>&1

      and item key
      check.sh[eth1.153]
      Hi,

      First of all thank you for your answer. I made the modification as you said, but it still sends the value 0.

      The log file:
      Code:
       4165:20100624:162724.621 In substitute_simple_macros (data:'check.sh[eth1.155]')
        4165:20100624:162724.621 In get_value() key:'check.sh[eth1.155]'
        4165:20100624:162724.621 In get_value_external() key:'check.sh[eth1.155]'
        4165:20100624:162724.621 DEBUG [check.sh]
        4165:20100624:162724.621 params [eth1.155]
        4165:20100624:162724.621 /etc/zabbix/externalscripts/check.sh 192.168.49.124 eth1.155
        4165:20100624:162724.628 Result [0]
        4165:20100624:162724.628 End of get_value():SUCCEED
      Could you please give me some advice?

      Thanks
      Mike

      Comment

      • ruswold
        Senior Member
        • Mar 2010
        • 210

        #4
        try use /path_to_fping/fping -q -I $2 $1 > /dev/null 2>&1
        example /usr/sbin/fping -q -I $2 $1 > /dev/null 2>&1

        Comment

        • jthakrar
          Member
          • Oct 2009
          • 43

          #5
          Just a quick note -
          when I wrote some of my own external scripts, if the exit status was 1, then it would bring down the zabbix server (I was doing external checks on the server). It seems if the "zabbix poller" gets a return value of 1, it assumes there was some error and exits with error.

          To return to your problem, try using the full path for fping as ruswold suggested.

          Remember, even if you login as user zabbix and the command is accessible, it may not be so for the zabbix server, since it is started as a daemon from init (or whatever mechanism you have chosen).

          Comment

          • mike13
            Member
            • Apr 2010
            • 30

            #6
            Originally posted by ruswold
            try use /path_to_fping/fping -q -I $2 $1 > /dev/null 2>&1
            example /usr/sbin/fping -q -I $2 $1 > /dev/null 2>&1
            Originally posted by jthakrar
            Just a quick note -
            when I wrote some of my own external scripts, if the exit status was 1, then it would bring down the zabbix server (I was doing external checks on the server). It seems if the "zabbix poller" gets a return value of 1, it assumes there was some error and exits with error.

            To return to your problem, try using the full path for fping as ruswold suggested.

            Remember, even if you login as user zabbix and the command is accessible, it may not be so for the zabbix server, since it is started as a daemon from init (or whatever mechanism you have chosen).
            Hi,

            Thank you everyone for your answers. However the problem still remains.
            I've even tried giving permission "chown zabbix:zabbix /usr/sbin/fping", and still no success.

            Can anyone please help me out?

            I shall be really thankful,

            Mike

            Comment

            • ruswold
              Senior Member
              • Mar 2010
              • 210

              #7
              May by problem is that script output to STDERR, but zabbix-agent get output from STDOUT
              try make script in a perl


              #!/usr/bin/perl -w

              open(PIPE,'/usr/sbin/fping -qc3 $ARGV[1] 2>&1 |');

              while(<PIPE>){
              print $_;
              }

              Comment

              • mike13
                Member
                • Apr 2010
                • 30

                #8
                Originally posted by ruswold
                May by problem is that script output to STDERR, but zabbix-agent get output from STDOUT
                try make script in a perl


                #!/usr/bin/perl -w

                open(PIPE,'/usr/sbin/fping -qc3 $ARGV[1] 2>&1 |');

                while(<PIPE>){
                print $_;
                }
                Hi ruswold,

                I'm a novice when it comes to perl so any help much appreciated. When i run the script on the shell returns nothing. How to test it?


                Do you have any idea?

                Many thaks,
                Mike

                Comment

                • ruswold
                  Senior Member
                  • Mar 2010
                  • 210

                  #9
                  run script.pl IP_address
                  $ARGV[1] - first argument

                  Comment

                  • mike13
                    Member
                    • Apr 2010
                    • 30

                    #10
                    Originally posted by ruswold
                    run script.pl IP_address
                    $ARGV[1] - first argument
                    I’m sorry I miscommunicated to you. I known how to run the script. The script runs, but it returns nothing on the shell screen.

                    Could you help me?

                    Thanks,
                    Mike

                    Comment

                    • ruswold
                      Senior Member
                      • Mar 2010
                      • 210

                      #11
                      Originally posted by mike13
                      I’m sorry I miscommunicated to you. I known how to run the script. The script runs, but it returns nothing on the shell screen.

                      Could you help me?

                      Thanks,
                      Mike
                      1. i'm sorry, i was wrong, try whis

                      #!/usr/bin/perl

                      open(PIPE,"/usr/sbin/fping $ARGV[0] 2>&1|");
                      while(<PIPE>){
                      #print $_;
                      if (/^(\S+).*unreachable/){
                      print "0";
                      }
                      elsif (/^(\S+) is alive/){
                      print "1";
                      }
                      elsif (/^(\S+)\s+address\s+not\s+found/){
                      print "-1";
                      }
                      }
                      close(PIPE);

                      run script.pl HOST

                      2. I don't undestand options -I of fping
                      on my FreeBSD whis option is wrong

                      Comment

                      • mike13
                        Member
                        • Apr 2010
                        • 30

                        #12
                        Originally posted by ruswold
                        1. i'm sorry, i was wrong, try whis

                        #!/usr/bin/perl

                        open(PIPE,"/usr/sbin/fping $ARGV[0] 2>&1|");
                        while(<PIPE>){
                        #print $_;
                        if (/^(\S+).*unreachable/){
                        print "0";
                        }
                        elsif (/^(\S+) is alive/){
                        print "1";
                        }
                        elsif (/^(\S+)\s+address\s+not\s+found/){
                        print "-1";
                        }
                        }
                        close(PIPE);

                        run script.pl HOST

                        2. I don't undestand options -I of fping
                        on my FreeBSD whis option is wrong
                        Hi ruswold,

                        Your script is working fine, however i need to use the option fping -I in order to send the ping via a specific network interface. On my server each interface is attached to a different mpls vrf. Thus, i need to use the option fping -I to check the reachability of a host in a specific vrf.

                        On my debian the option fping -I is supported. I've modified the script as follow:

                        Code:
                        open(PIPE,"/usr/sbin/fping -I " . $ARGV[1]. " ".$ARGV[0]. " 2>&1|");
                        When i run it from shell it works fine. But zabbix says "not supported".



                        And my item is:
                        Host: Test
                        Description: check
                        Type: External check
                        Key: check.sh[eth1.155]


                        The log file:

                        Code:
                        [COLOR="black"] 20496:20100628:143524.910 In substitute_simple_macros (data:'pping.pl[eth1.155]')
                         20496:20100628:143524.910 In get_value() key:'pping.pl[eth1.155]'
                         20496:20100628:143524.911 In get_value_external() key:'pping.pl[eth1.155]'
                         20496:20100628:143524.911 DEBUG [pping.pl]
                         20496:20100628:143524.911 params [eth1.155]
                         20496:20100628:143524.911 /etc/zabbix/externalscripts/pping.pl 192.168.49.124 eth1.155
                         20516:20100628:143524.911 In process_escalations()
                         20516:20100628:143524.911 Query [txnlev:0] [select escalationid,actionid,triggerid,eventid,r_eventid,esc_step,status from escalations where status in (0,1) and nextcheck<=1277728524 and escalationid between 000000000000000 and 099999999999999]
                         20516:20100628:143524.911 Escalator spent 0.000410 seconds while processing escalation items. Nextcheck after 3 sec.
                         20496:20100628:143524.918 Item [hpcable:pping.pl[eth1.155]] error: Script /etc/zabbix/externalscripts/pping.pl returned nothing.
                         20496:20100628:143524.918 In zabbix_log()
                         20496:20100628:143524.918 In DCconfig_get_items() hostid:0 key:'zabbix[log]'
                         20496:20100628:143524.918 End of DCconfig_get_items():0
                         20496:20100628:143524.918 End of zabbix_log()
                         20496:20100628:143524.918 End of get_value():NOTSUPPORTED
                         20496:20100628:143524.918 Parameter [hpcable:pping.pl[eth1.155]] is not supported by agent Old status [0][/COLOR]
                        Do you have any idea?
                        Could you please give me some advice?

                        Many thaks,
                        Mike

                        Comment

                        • ruswold
                          Senior Member
                          • Mar 2010
                          • 210

                          #13
                          1. You make item with key check.sh[eth1.155], but in log i see pping.pl[eth1.155].

                          I see in log that script return nothing, this is because you ping unreacheble host
                          try use timeout like this

                          Code:
                          #!/usr/bin/perl -w
                          
                          #timeout in seconds
                          my $timeout = 15;
                          eval {
                              local $SIG{ALRM} = sub { die "alarm\n" };
                              alarm $timeout;
                          
                              open(PIPE,"/usr/sbin/fping $ARGV[1] 2>&1|");
                              alarm 0;
                              while(<PIPE>){
                                  if (/^(\S+).*unreachable/){
                                      print "0";
                                      }
                              if (/^(\S+) is alive/){
                                      print "1";
                                      }
                              elsif (/^(\S+)\s+address\s+not\s+found/){
                                  print "-1";
                                  }
                              }
                          
                          };
                          if ($@) {
                              #timeout get value
                               print "0";
                              }
                                                                                                                                  close(PIPE);
                          And you must set in zabbix_server.conf timeout = 29 (max 30) seconds.
                          Last edited by ruswold; 28-06-2010, 15:43.

                          Comment

                          • mike13
                            Member
                            • Apr 2010
                            • 30

                            #14
                            Originally posted by ruswold
                            1. You make item with key check.sh[eth1.155], but in log i see pping.pl[eth1.155].

                            I see in log that script return nothing, this is because you ping unreacheble host
                            try use timeout like this

                            Code:
                            #!/usr/bin/perl -w
                            
                            #timeout in seconds
                            my $timeout = 15;
                            eval {
                                local $SIG{ALRM} = sub { die "alarm\n" };
                                alarm $timeout;
                            
                                open(PIPE,"/usr/sbin/fping $ARGV[1] 2>&1|");
                                alarm 0;
                                while(<PIPE>){
                                    if (/^(\S+).*unreachable/){
                                        print "0";
                                        }
                                if (/^(\S+) is alive/){
                                        print "1";
                                        }
                                elsif (/^(\S+)\s+address\s+not\s+found/){
                                    print "-1";
                                    }
                                }
                            
                            };
                            if ($@) {
                                #timeout get value
                                 print "0";
                                }
                                                                                                                                    close(PIPE);
                            And you must set in zabbix_server.conf timeout = 29 (max 30) seconds.
                            I'm sorry, i've just copied the wrong item. But the log file is the correct one.

                            Here is my item:

                            Host: Test
                            Description: hpcable
                            Type: External check
                            Key: pping.pl[eth1.155]


                            And i've integrated your modification.

                            Code:
                            #!/usr/bin/perl
                            
                            #timeout in seconds
                            my $timeout = 15;
                            eval {
                                local $SIG{ALRM} = sub { die "alarm\n" };
                                alarm $timeout;
                            open(PIPE,"/usr/sbin/fping -I " . $ARGV[1]. " ".$ARGV[0]. " 2>&1|");
                            while(<PIPE>){
                            #print $_;
                            	if (/^(\S+).*unreachable/){
                            		print "0";
                            	}
                            	elsif (/^(\S+) is alive/){
                            		print "1";
                            	}
                            	elsif (/^(\S+)\s+address\s+not\s+found/){
                            		print "-1";
                            	}
                            }
                            close(PIPE);
                            };
                            if ($@) {
                                #timeout get value
                                 print "0";
                                }

                            The script works fine in shell:
                            Code:
                            root@tcy:/etc/zabbix/externalscripts# ./pping.pl 192.168.49.124 eth1.155
                            1root@tcy:/etc/zabbix/externalscripts#

                            The log file:

                            Code:
                            20496:20100628:160824.401 In substitute_simple_macros (data:'pping.pl[eth1.155]')
                             20496:20100628:160824.401 In get_value() key:'pping.pl[eth1.155]'
                             20496:20100628:160824.401 In get_value_external() key:'pping.pl[eth1.155]'
                             20496:20100628:160824.401 DEBUG [pping.pl]
                             20496:20100628:160824.401 params [eth1.155]
                             20496:20100628:160824.401 /etc/zabbix/externalscripts/pping.pl 192.168.49.124 eth1.155
                             20496:20100628:160824.408 Item [comcable:pping.pl[eth1.155]] error: Script /etc/zabbix/externalscripts/pping.pl returned nothing.
                             20496:20100628:160824.408 In zabbix_log()
                             20496:20100628:160824.408 In DCconfig_get_items() hostid:0 key:'zabbix[log]'
                             20496:20100628:160824.408 End of DCconfig_get_items():0
                             20496:20100628:160824.409 End of zabbix_log()
                             20496:20100628:160824.409 End of get_value():NOTSUPPORTED
                             20496:20100628:160824.409 Parameter [comcable:pping.pl[eth1.155]] is not supported by agent Old status [0]
                            Still the same "not supported" message.



                            Do you have any idea?

                            Many thaks,
                            Mike
                            Last edited by mike13; 28-06-2010, 16:24.

                            Comment

                            • ruswold
                              Senior Member
                              • Mar 2010
                              • 210

                              #15
                              1. Are you set in zabbix_server.conf timeout = 30 seconds?
                              And restart zabbix_server after changes in config file

                              This script work in my zabbix

                              2. If it's not help for you try set value type of item as text and say any changes.
                              3. Try run script as user zabbix, in freeBSD like: su zabbix -c 'pping.pl 192.168.49.124 eth1.155'. Work?
                              Last edited by ruswold; 28-06-2010, 18:10.

                              Comment

                              Working...