ubuntumonit

How to run a command if ping fails over monit?


Hi everyone i'm trying to do a CloudFlaire IP failovr with monit

actually i'm using this but unfortunately this strings doesn't look to works when monit runs there is any mistake from my side ?

check host x.x.x.x with address x.x.x.x
  if failed icmp type echo count 3 with timeout 3 seconds for 2 cycles then exec "/bin/bash -c /etc/monit/SecondaryIP.sh"
  else if succeeded for 2 cycles then exec "/bin/bash -c /etc/monit/NativeIP.sh"

Solution

  • From my point of view, your sample looks good.

    check host Testhost with address 192.168.1.6
    #  if failed ping4 count 3 with timeout 3 seconds for 2 cycles then exec "/usr/local/etc/monit/scripts/script.sh"
      if failed icmp type echo count 3 with timeout 3 seconds for 2 cycles then exec "/usr/local/etc/monit/scripts/script.sh"
         else if succeeded for 2 cycles then exec "/usr/local/etc/monit/scripts/script.sh"
    

    As long as you start Monit in a "root" environment, every thing works well. A snippet from the monit.log file.

    'Testhost' ping test succeeded [response time 5.046 ms]
    'Testhost' exec: '/usr/local/etc/monit/scripts/script.sh'
    
    'Testhost' ping test failed
    'Testhost' exec: '/usr/local/etc/monit/scripts/script.sh'
    

    You should check your monit.log and the used scripts. Try "ping4" instead of "icmp type echo" in your test.