Ad Widget

Collapse

run script on agent if the server is not available

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pedrofmp
    Junior Member
    • Jul 2013
    • 3

    #1

    run script on agent if the server is not available

    Hi guys,

    I'm not even sure if this is feasible, but i have a remote site connected thru a cellular modem. The problem is, sometimes the modem goes down and the only way to get back the communication is rebooting it.
    I was just wondering if there's a way for the agent to detect if the server is down for more than, lets say, 5 minutes and then trigger a script to reboot the modem.

    server --> modem --> station running the agent

    if server has no communication with agent then station run script to reboot the modem.
    i've tried active agent but i cannot run an action if the agent is not available.
  • Pada
    Senior Member
    • Apr 2012
    • 236

    #2
    If the modem is on the same machine as your zabbix server, then you should be able to reboot the modem with a script quite easily.

    First add an Zabbix agent (active) item to your "station", with a key: agent.ping

    First add a trigger to your "station", with an expression like follow:
    Code:
    {station.yourdomain.com:agent.ping.nodata(5m)}=1
    * This trigger will go off as soon as it hasn't received any data from the active agent in 5 minutes. Change 5m to be like at least 3x bigger than your agent.ping's update interval.

    Now go and add the script under Administration > Media Types, and then assign that new media type to a user.

    Now you can go and add an Configuration > Action, that is only triggered by that specific trigger. Have this trigger run a script (by letting it notify the user with the new media type) that reboots your modem.

    I hope this is detailed enough for you.

    Comment

    • pedrofmp
      Junior Member
      • Jul 2013
      • 3

      #3
      Hi Pada,

      Thanks for your reply.
      Unfortunately, the modem is attached to the remote system, not the server.
      if i understand correctly, the action will be taken by the server and not the remote agent, so i guess i cant run the script on the agent if the connection is down.
      I'll use cron instead.

      Thanks again.

      Comment

      • Pada
        Senior Member
        • Apr 2012
        • 236

        #4
        Yes, unfortunately the action would be taken by the Zabbix server and not by the client like you'd want in your situation.

        If you run a VPN between the two sites, then you can probably modify their ifdown script to also reboot your modem. I know you can do this when you run OpenVPN on the linux machine.

        If you're not using a VPN and you can ping the server from the client, then have a look at fping, because with fping you can set like an exponential backoff factor, interval between the ping attempts, etc.
        fping will return with exit code of 0 when it had 1 successful ping (eg. even if it had 99% packet loss).

        For example you can use the following script in a cron job that runs every minute:
        Code:
        #!/bin/sh
        ip=172.30.30.242
        fping -B 2 -r 3 -p 1000 -t 1000 $ip
        if [ $? -ne 0 ]; then
                echo "Connection lost"
                # run script to reboot modem
        fi
        fping man pages: http://linux.die.net/man/8/fping

        Comment

        • pedrofmp
          Junior Member
          • Jul 2013
          • 3

          #5
          I was trying to avoid scripts on cron but it seems the way to go.
          Thank you very much for your help ( and for the code as well)

          Comment

          Working...