Icinga2 exchange plugin for monitoring systemd services.


version !#/bin/bash Open Source Love

Icinga2 exchange plugin for monitoring systemd services.

This plugin checks status of systemd service and also can restart service if is not running. Returns exit codes based on nagios plugin api standard.


# installing dependencies
sudo apt update
sudo apt install git

# clone repository
git clone https://github.com/patrikskrivanek/icinga2-check_systemd_service.git

# run check_systemd_service program with help and learn how to use
check_systemd_service --help

# move the plugin check_systemd_service into your Icinga plugins dir on target hosts

How to integrate the plugin into the Icinga monitoring process?

# service.conf
apply Service for (service_name => config in host.vars.systemd) {
    import "generic-service"

    check_command = "systemd_service"
    display_name = config.friendly_name
    vars.systemd_service_name = service_name
    vars.systemd_restart = config.restart

    assign where host.vars.systemd != null

# commands.conf
object CheckCommand "systemd_service" {
    command = [ PluginDir + "/check_systemd_service" ]

    arguments = {
      "--service_name" = {
        value = "$systemd_service_name$"
        description = "Name of systemd service for check"
        skip_key = true
        required = true
        order = 1
      "--restart" = {
        set_if = "$systemd_restart$"
        description = "Restart service if is not running"
        required = false
        order = 2

# hosts.conf
object Host "your-host" {
  import "generic-host"

  address = "your-host.domain"

  vars.systemd["apache2"] = { friendly_name = "Apache Webserver", restart = true }
  vars.systemd["mysql"] = { friendly_name = "MySQL Database", restart = true }
  vars.systemd["cron"] = { friendly_name = "Cron Service", restart = false }

  # rest of the host config...


Argument Description Required
[service] Name of systemd service for check yes
--restart Restart service if is not running, root privileges needed [added in v1.1.0] optional
--inverse This flag uses !is-failed option as status, [added in v1.2.0] optional
--no-enable Does not if service is enabled or not, [added in v1.2.0] optional
-V --version Show program version optional
-h --help Show program help and usage optional


# check if mysql is running
check_systemd_service mysql

# check if cron is running, otherwise restart service
check_systemd_service cron --restart

# check if apache2 webserver is running
check_systemd_service apache2

# show program help
check_systemd_service cron --help

# show program version
check_systemd_service cron --version