0

Let's say a given host, FooHost, is running Apache2. Icinga2 runs a check by ssh command and discovers that Apache2 is not running, which triggers a critical alert.

Is it possible to have Icinga2 execute a script on this event? In this example, I would like to write a script that does an SSH remote execute of systemctl restart apache2.

In the alternative, we could write a watchdog script that could be deployed on all servers, but it makes MUCH more sense to write it on the Icinga2 box, and use ssh remote execute because that allows central control.

I see no reason to have to have an engineer log in to fix this unless this restart failed also.

DrDamnit
  • 4,736
  • 4
  • 23
  • 38

2 Answers2

2

You can use Event Commands (like Event Handlers in Icinga 1.x / Nagios) to achieve this.

The documentation show the following example, which is using a custom shell script to perform the restart operations:

object EventCommand "restart_service" {
  command = [ PluginDir + "/restart_service" ]

  arguments = {
    "-s" = "$service.state$"
    "-t" = "$service.state_type$"
    "-a" = "$service.check_attempt$"
    "-S" = "$restart_service$"
  }

  vars.restart_service = "$procs_command$"
}

object Service "Process httpd" {
  check_command = "procs"
  event_command = "restart_service"
  max_check_attempts = 4

  host_name = "icinga2-client1.localdomain"
  command_endpoint = "icinga2-client1.localdomain"

  vars.procs_command = "httpd"
  vars.procs_warning = "1:10"
  vars.procs_critical = "1:"
}
0

as far as i know it is not possible but you can use an nagios nrpe command or a cronjob which is execute command like this

pgrep apache2 || /bin/systemctl restart apache2 > /dev/null 2>&1

or

/bin/systemctl status apache2 || /bin/systemctl restart apache2

which means if the apache2 service is not running it will be restarted.

Daniel Gohlke
  • 91
  • 1
  • 4