Ad Widget

Collapse

Getting custom script(ping) working from zabbix server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zabbixfk
    Senior Member
    • Jun 2013
    • 256

    #1

    Getting custom script(ping) working from zabbix server

    Hello All,

    Problem statement: Get the packet loss/delay miliseconds using Ping.

    Tried Solution:
    I am trying to trigger custom script written, which just takes ip address as first argument, and returns number of delay in mili seconds. Below is my script.
    Code:
    #!/bin/bash
    echo -e "\n\n" >>/tmp/o.txt
    echo "received $1">>/tmp/o.txt
    if [ "$#" != 1 ];
    then
    	echo -e "YOU HAVE TO PASS THE IP ADDRESS OF THE MACHINE TO PING AS FIRST ARGUMENT...!!!\n";
    	exit -1
    fi
    	ip=$1
        stat=1
    
        if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
            OIFS=$IFS
            IFS='.'
            ip=($ip)
            IFS=$OIFS
            [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
            stat=$?
        fi
    	echo "returing $stat">>/tmp/o.txt
    	if [[ $stat == 0 ]];
    	then
    		echo "inside okay">>/tmp/o.txt
    		result=$(/bin/ping -c 5 $1 | grep -E "time=" | awk '{print $7}' | sed s/time=//g | xargs echo | sed -e 's/\s/ + /g' | sed -e 's/^/( /' | sed -e 's/$/ ) \/ 5/' | bc)
    		sleep 2
    		echo "$time|$result">>/tmp/o.txt
    		echo $result
    	else 
    		echo "inside no">>/tmp/o.txt
    		echo -e "OOPS, I CAN't VALIDATE YOUR IP ADDRESS... SORRY...!!!";
    		exit -2;
    	fi
    Now it is located under
    Code:
    /usr/local/etc/scripts/checkPing
    I have also created a symbolic link in
    Code:
    /etc/zabbix/externalscripts/
    to above.

    Also added this line under zabbix_agentd.conf on zabbix server
    Code:
    UserParameter=checkPing[*],  /usr/local/etc/scripts/checkPing $1
    And then in my template, added new item called
    item name : checkPing
    type as externalcheck
    Key as checkPing[{HOST.CONN}] ( tried {HOST.HOST} but it didn't work so used this key)

    Since this template is mixture of snmp and general ( snmp because i am trying to monitory a firewall with discovery rull, and item prototypes), Is there any other config involved?

    1). Do i need to make any changes to run this from zabbix server to firewall ping test (as above solution isn't working).
    2). If i want to run this on a client machine behind firewall and ping some other server to check the latency or connectivity what other changes to be done on this?

    zabbix server: Oracle Linux server 6.4 with kernel 2.6.39-400, zabbix server/ agent version: 2.0.6

    Any pointers are greatly helpful.

    Thanks
  • Heilig
    Senior Member
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Mar 2013
    • 366

    #2
    If you run the script from the command line with IP, what it returns?
    Originally posted by zabbixfk
    type as externalcheck
    Please try Zabbix Agent or Zabbix Agent (active) (details here https://www.zabbix.com/documentation...userparameters and here https://www.zabbix.com/documentation...xtending_agent)

    Comment

    • zabbixfk
      Senior Member
      • Jun 2013
      • 256

      #3
      [SOLVED] Getting custom script(ping) working from zabbix server

      Thanks for the reply. Now i am able to get this thing working. I had to remove the userparameter line from zabbix_agentd.conf on zabbix server, but created a symbolic link to existing script on
      Code:
      /etc/zabbix/externalscripts/
      , then i stated getting values.

      Comment

      Working...