EventCommand for UPS?

Hello there,

I’m searching for a way to shutdown VMs (Linux,Windows) and Proxmox Nodes as soon as the battery capacity of the USP hits 50%.

I know that there are tools such as apcupsd and NUT, but would this also be possible by using EventCommands in Icinga?

At the moment I’m monitoring the battery capacity via SNMP. Could I use that output for a script that triggers the shutdown for the VMs and Proxmox nodes and if so, is there anybody who’s already done that? I’m still very new to monitoring and scripting :confused:

I appreciate any help!

Eventcommands are triggered by every execution, you can attach the current state of the service/host similar like it is done in a notification command.

So in the eventcommand script / binary you have to decide to how to continue with the data.

like:

  • host.state == 1 // (WARNING) → do nothing
  • host.state == 2 // (CRITICAL) → poweroff machine
  • you also should evaluate other things like softstate, hardstate and so on.

The event command runs on that machine that executed the check, if you check your UPS via your master you need to remoteshutdown your other machines. If your UPS check runs on an agent the agent will shutdown itself.

Also you need to take care of permissions?
Do you shut down your host via api? or do you execute a the poweroff locally? Is the icinga user allowed to do that?

If you are familiar with notifications you can misuse the notificaion feature.
here you can trigger script execution on specific states.
I the end you “notificaion script” could shutdown proxmox via api.
One thing to consider is that notificaions can be disabled in the gui for hosts/services/ or even the entire system. This can be good in case of maintenance and bad in case of disabling the emergenxy shutdown.

So yes it can be done.
You most likely need to implement something
but that is what icinga2 is for. it gives you every freedom to customize

Best Regards
Nicolas

Small correction/extension to

if one of these conditions matches:

The host/service is in a soft state
The host/service state changes into a hard state
The host/service state recovers from a soft or hard state to OK/Up

So the EventCommand script would not be triggered if the check remains OK.

@vplm : Check the docs. There is a detailed description inlcuding some basic examples.
EventCommands

The other points by Nicolas are very true. This is something you need to be sure about and implement correctly/strictly or else it might get ugly :wink:

Regarding the “misuse” of the notifications for this:
Notifications are always triggered by/executed on the master node(s).
If you run a distributed setup, where the UPS check is running on a satellite or even agent, and the master can’t reach the UPS directly, this way will most likely not be usable.

2 Likes

By default, yes. But adding && host.zone == ZoneName to the notification objects’ assign rules trigger notifications at satellite(s) instead of master(s).

1 Like