Run script when host is down

How do you run a script upon a given failure?

What I am trying to do:
When I get a notification that “Linux server X” has updates, I know that apt update && apt -y upgrade needs to be run. It’s a waste of human time to do this. If Icinga could run a script or command after this alarm is triggered, this could be avoided.

I get that the command might fail, and I would have to deal with that in a different way. It’s just that right now, it seems like this should be very doable … and may be so obvious that I have missed it…

Would it be possible to implement something using NotificationCommand and change that to be something that accepts args, which could then use something else to run a command to the remote box via ssh? ssh root@hostwithproblem "apt update && apt -y upgrade" ?

Thanks in advance.

HI, this is what you are looking for: https://icinga.com/docs/icinga2/latest/doc/03-monitoring-basics/#event-commands :wink:

1 Like

Why not just modify cron-apt, which checks for updates, so that it installs
them as well?

See /usr/share/doc/cron-apt/README.gz for more details.

Antony.

I just chose to use apt as an example We have other things that will need this event command, but rather than talk about custom packages and setups, I chose something simple and somewhat universal. :slight_smile: