Ad Widget

Collapse

Agent-initiated Ping

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bytesize
    Member
    • Aug 2005
    • 71

    #1

    Agent-initiated Ping

    Hi guys,

    I'm sure this is very simple but I can't get my head around it!

    I have a Zabbix agent running on a server in Office A. I want this agent to ping a server in Office B, which are connected together by a VPN tunnel. If the remote server in Office B does not return a ping, then I know the VPN tunnel is down.

    How do I configure this as a Ping check to run from the agent, instead of the monitoring server?

    Thanks!

    John
  • Nate Bell
    Senior Member
    • Feb 2005
    • 141

    #2
    You could write a script that runs on Computer A and pings Computer B. Set this script as a UserParameter in Computer A's zabbix_agentd.conf file, and add the item to your Zabbix server.

    Of course, you're going to need to make the script do a bit more than just ping the second computer. It has to send out a ping, get some sort of response back even if the second computer can't be reached, and parse this information into data that Zabbix can handle.

    Here's a simple script I wrote to do this, although I'm sure someone can come up with something better. This script takes an address as an argument, and sends a ping to that address. If some data is returned, then it sends a 1 to Zabbix, and if the address can't be pinged, it sends a 0.

    Code:
    #!/bin/bash
    ping -c3 -W10 $1 &> /tmp/ping.dmp
    grep received /tmp/ping.dmp | wc -l
    Hope that helps, or at least gives you some ideas.

    Nate

    Comment

    • bytesize
      Member
      • Aug 2005
      • 71

      #3
      Hi Nate,

      Thanks for the post, that scripts work great!

      It would be good to also collect the ICMP response times across the VPN, so I can see if the link is becoming really laggy; I dont suppose you could suggest an extention to your script which could do this?

      I had a go myself, but I'm getting loads of "broken pipe" and timeout errors, even though the script runs fine from the command line!

      Regards,

      John

      Comment

      • Nate Bell
        Senior Member
        • Feb 2005
        • 141

        #4
        That's actually a good idea. It gives a more descriptive output that way. I assume you were looking for the average response time for all the pings. If so, the script below will grab that data and report it (in ms). If the location you are trying to ping can not be pinged, it sends the value -1 to Zabbix, so you can easily set a trigger to go off.

        Code:
        #!/bin/bash
        ping -c3 -W10 $1 &> /tmp/ping.dmp
        status=$(grep received /tmp/ping.dmp | wc -l)
        if [ $status -eq "0" ]; then
           echo -1
        else
           grep avg /tmp/ping.dmp | cut -d" " -f4 | cut -d"/" -f2
        fi
        Nate

        Comment

        • bytesize
          Member
          • Aug 2005
          • 71

          #5
          Hmm, I'm still getting timeouts and "Broken Pipe" messages in the Zabbix agent log, even though the script is working fine from the command line when executed manually!

          Here is what I have in my zabbix_agentd.conf:

          UserParameter=vpn[officea-to-officeb],/usr/local/zabbix/scripts/ping-response.sh 192.168.1.1

          ...and then I have that parameter defined in the Zabbix server.

          Any ideas what might be causing these errors? I'm executing the script on a Mac server, but seen as it works from the command line I don't understand why Zabbix can't execute it!

          Thanks!

          John

          Comment

          • bytesize
            Member
            • Aug 2005
            • 71

            #6
            Aha, found the answer... for some reason Zabbix doesn't like the wait time between pings in the script. If I reduce the timeout to 1 second, then its happy!

            Here is the modified script (for mac users, note the flag has been changed for the wait time!)

            Code:
            #!/bin/bash
            ping -c3 -i1 $1 &> /usr/local/zabbix/tmp/ping.dmp
            status=$(grep received /usr/local/zabbix/tmp/ping.dmp | wc -l)
            if [ $status -eq "0" ]; then
               echo -1
            else
               grep avg /usr/local/zabbix/tmp/ping.dmp | cut -d" " -f4 | cut -d"/" -f2
            fi
            Thanks very much for the script though - works like a charm!

            Does anybody know where to extend the timeout in Zabbix to enable pauses between pinging?

            Regards,

            John

            Comment

            • Nate Bell
              Senior Member
              • Feb 2005
              • 141

              #7
              Blast! Beat me to it!
              Glad you found your answer. You can increase the time Zabbix is willing to wait for an item in the zabbix_agentd.conf file. The default is 3 seconds. I can't remember if you have to change the same value in the zabbix_server.conf file, but I suspect you do.

              As a side note, you might want to change your UserParameter syntax. If you change it to:
              Code:
              UserParameter=pingresponse[*],/usr/local/zabbix/scripts/ping-response.sh
              and create an item like:
              Code:
              Description: VPN connection from computer A to B
              
              Key: pingresponse[192.168.1.1]
              then you can reuse the pingresponse UserParameter to ping other addresses with that machine. For instance, creating an item with a key:
              Code:
               pingresponse[google.com]
              will let that computer ping google.com. Easier than making a new UserParameter.

              Nate

              Comment

              • bytesize
                Member
                • Aug 2005
                • 71

                #8
                Very, very efficient! Thanks Nate!

                I will give this a little more testing and tweaking, then type it up in the cookbook forum as I bet others are also interested in a similar solution!

                Thanks again!

                John

                Comment

                Working...