Same service to more items not works

Hello!

icinga2, three machines:

  • server: VM, Roxy Linux 8, 2.13.2-1
  • client1: Physical, Debian 12.5, 5 disks, r2.14.2-1
  • client2: RPI, raspbian bookworm, 2 disks. r2.13.6-1

A SMART check would run on all of them.

object CheckCommand "check_smart_command" {
    import "plugin-check-command"
    command = [ "/bin/sudo", CustomPluginDir  + "/check_smart.pl" ]
    timeout = 1m
    arguments += {
        "-i" = {
            description = "Interface"
            value = "$checksmartinterface$"
                }
            
        "-d" = {
            description = "Device Name"
            value = "$checksmartdevice$"
                }
    }
    vars.check_address = {
        arguments = [  ]
        deprecated = false
        name = "<anonymous>"
        side_effect_free = false
        type = "Function"
    }
}

(command: https://www.claudiokuenzler.com/monitoring-plugins/check_smart.pl )

eervice template:

template Service "check_smart_linux_service" {
    check_command = "check_smart_command"
    check_period = "Everytime"
    command_endpoint = host_name
    host.vars.checksmartinterface = "auto"
    host.vars.checksmartdevice = ""
}

and service apply , now only for pi:

apply Service "SMART_LINUX_SDA"   {
    assign where "raspberrypi" == host.name
    import "check_smart_linux_service"
    command_endpoint = host_name
    host.vars.checksmartdevice = "/dev/sda"
    zone = "icinga2"
}


apply Service "SMART_LINUX_SDB"   {
    assign where "raspberrypi" == host.name
    import "check_smart_linux_service"
    command_endpoint = host_name
    host.vars.checksmartdevice = "/dev/sdb"
    zone = "icinga2"
}

both check run on first disk ( if i have 5 disks - even only the first disk. If change sequence in sercvice.conf (first check sdb, second check sda), both check run in sdb. If rename /dev/sda to qwert and /dev/sdb to asdf - both check run on qwert (ok, non-existent, but try)

[2024-02-25 12:32:22 +0100] notice/Process: Running command '/bin/sudo' '/usr/local/lib/nagios/plugins/check_smart.pl' '-d' '/dev/sda' '-i' 'auto': PID 24653
[2024-02-25 12:32:23 +0100] notice/Process: PID 24653 ('/bin/sudo' '/usr/local/lib/nagios/plugins/check_smart.pl' '-d' '/dev/sda' '-i' 'auto') terminated with exit code 0
[2024-02-25 12:32:25 +0100] notice/Process: Running command '/bin/sudo' '/usr/local/lib/nagios/plugins/check_smart.pl' '-d' '/dev/sda' '-i' 'auto': PID 24662
[2024-02-25 12:32:26 +0100] notice/Process: PID 24662 ('/bin/sudo' '/usr/local/lib/nagios/plugins/check_smart.pl' '-d' '/dev/sda' '-i' 'auto') terminated with exit code 0

[Service Problems]

Soft 1/3 [SMART_LINUX_SDA]
Could not find any valid block/character special device for device qwert !
UNKNOWN

Soft 1/3 [SMART_LINUX_SDB]
Could not find any valid block/character special device for device qwert !

change the sequence in services.conf:

apply Service "SMART_LINUX_SDB"   {
    assign where "raspberrypi" == host.name
    import "check_smart_linux_service"
    command_endpoint = host_name
    host.vars.checksmartdevice = "asdf"
    zone = "icinga2"
}



apply Service "SMART_LINUX_SDA"   {
    assign where "raspberrypi" == host.name
    import "check_smart_linux_service"
    command_endpoint = host_name
    host.vars.checksmartdevice = "qwert"
    zone = "icinga2"
}

Service: SMART_LINUX_SDA
Could not find any valid block/character special device for device asdf !

Service: SMART_LINUX_SDB
Could not find any valid block/character special device for device asdf !

WHY? why does it only consider the parameter passed to the first one?

thanks for answer

Currently you are setting the variable host.vars.checksmartdevice in the first service definition and the overwrite it in the next, as it is not bound to the service due to the host. part.

If you change all your host.vars. to just vars. it should be fine, as the variable is now bound to the Service objects

oh…thx, i’ll try it. Not too simple, like nagios3 :slight_smile: