Check Uptime as service

Hi,

I added a new service to Icinga 2, to monitor the uptime of the machine. So far it is working but, the default plugin check unit is in minutes. The plugin itself supports an argument, with which you can change the unit to (seconds | minutes | hours | days).

Now my question is, how can I add arguments to the service? I tried the following, without success:

apply Service "uptime" {
  import "generic-service"

  check_command = "uptime"

  vars.uptime_arguments = [ "-u", "days" ]

  assign where host.name == NodeName
}

I guess I misunderstood the configuration documentation and have done something wrong but I can’t figure out what it could be.

Does anyone know how I could add the following arguments to that service or if there is another way of doing it?

Arguments:

-u (seconds | minutes | hours | days)
-w Warning Threshold (i.e. 280)
-c Critical Threshold (i.e 300)

Thank you in advance

Hello,
Service is the wrong place for this modification, you need to edit the related CheckCommand.
The problem is that uptime is part of the ITL (icinga template library, it’s basically default configuration provided with icinga), so i wouldn’t advise you to directly edit its definition since your modification can be erased by a future update.

So, what you can do instead is a wrapper check command, basically, define your check command uptime_custom and import uptime command in it in this way :

object CheckCommand "uptime_custom" {
    import "uptime"
        arguments += {
                "-u" = {
                        set_if = "$uptime_arguments$"
                        value = "$uptime_arguments$"
                        description = "custom description"
                }
        }

        vars.uptime_arguments = "days"
}

Also, you need to change your target check_command in your service.

I didn’t tested it but it should do the trick.

1 Like

Hi,

Thank you for the hint, as that helped me to sort the problem. This is how I have done it now and it works for us:

commands.conf

object CheckCommand "uptime_custom" {
    import "uptime"
        arguments += {
        "-u" = "$uptime_unit$"
        "-w" = "$uptime_warning$"
        "-c" = "$uptime_critical$"
        }
}

services.conf

apply Service "uptime" {
  import "generic-service"

  check_command = "uptime_custom"

  vars.uptime_unit = "days"
  vars.uptime_warning = "280"
  vars.uptime_critical = "300"

  assign where host.name == NodeName
}