Apply Service in Icinga host with vars

Hi,

I hope someone can help here.
I’m using a service to check APT updates and I can set it up with options (script options) for nodes that are not the master (Icinga host) but when I try to configure the service for Icinga host it does not get the variables

The service is configured like this
object CheckCommand “check_apt” {
command = [ PluginDir + “/check_apt” ]
arguments = {
“-o” = { value = “$onlycritical$” }
“-l” = { value = “$list$” }
}

}

apply Service “apt” {
import “generic-service”

check_command = “apt”
vars = {
“onlycritical” = { value = “” }
“list” = { value = “” }
}

assign where host.name == NodeName
}

image

The configuration that works for other nodes (check via SSH) is
vars.by_ssh_command = [ “/usr/lib/nagios/plugins/check_apt” ]
vars.by_ssh_port = host.vars.ssh_port
vars.by_ssh_logname = host.vars.ssh_logname
vars.by_ssh_identity = “$icingaSshKey$”

vars.by_ssh_arguments = {
“-l” = {
value=""
},
“-o” = {
value = “”
}
}

Basically I do not know how to configure services that are applied to the Icinga host because it seems that any of the checks uses the script options.

Thanks in advance and thanks for your support

Best

I adapted your check command and your service
$list$ is a boolean so if your service gets a var list = true then the apt check will list the available updates.
same is valid for onlycritical

object Service "apt" {
    import "generic-service"
    check_command = "apt"
    vars.list = true
    vars.onlycritical = true
    assign where host.name == NodeName
}

object CheckCommand "check_apt" {
    import "plugin-check-command"
    command = [ PluginDir + "/check_apt" ]
    arguments += {
        "--list" = {
            description = "list the available updates"
            set_if = "$list$"
        }
        "--only-critical" = {
            description = "list the available updates"
            set_if = "$onlycritical$"
        }
    }
}

First of all, thanks for your quick reply.

So it now looks like this but it seems that is not working (still getting Warning when I should get OK)

object CheckCommand "check_apt" {
  import "plugin-check-command"
  command = [ PluginDir + "/check_apt" ]
  arguments += {
    "--list" = {
      description = "list the available updates"
      set_if = "$list$"
    }
    "--only-critical" = {
      description = "only critical updates"
      set_if = "$onlycritical$"
    }
  }
}
apply Service "apt" {
  import "generic-service"
  check_command = "apt"
  vars.list = true
  vars.onlycritical = true
   
  assign where host.name == NodeName
}

image
image

If I run the command directly I get “OK” but not in Icinga

do you have icinga director installed?
there is an inspect feature. so you can see the command that is executed on the system

did you restart / reload icinga after the changes in config?

We do not have Icinga Director and yes, I reloaded Icinga but nothing changed.
I will install Icinga Director (which I wanted to avoid)

Thanks!

you can install and also only use the inspect feature, someone here does exactly that, it helps debugging a lot

I installed it and found the issue. Thanks for your help!!!

The command being used was defined in /usr/share/icinga2/include/command-plugins.conf and not the one defined by me