Problem for writing command check with attributes without values

I am trying to migrate a validation command from nagios to Icinga2.
The command for check: [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd [-X pass -L <authp>, <privp>) [-p <port>] -n <name in desc_oid> [-i -a -D] [-r] [-f [eSyY]] [-k [qBMGu] -g -w <warning levels> -c <crit levels> -d <delta>] [-o <octet_length>] [-t <timeout>] [-s] - label [-V]

The final option for me: -H localhost -C VerySecretPwd -2 -g -r -B -kM -f -n enp0s3 -w '10,10 '-c '20,20'

The sequence of parameters (order) should be just that.

I can’t write check_command the team for verification, it does not work. Can someone tell me how to do this?

On nagios server:
/usr/lib64/nagios/plugins/ -H localhost -C VerySecretPwd -2 -g -r -B -kM -f -n enp0s3 -w '10,10' -c '20,20'

Output with perfdata:
enp0s3:UP (0.0Mbps/0.1Mbps):1 UP: OK | 'enp0s3_in_octet'=1429111167c 'enp0s3_out_octet'=884078065c

Hi & welcome to the icinga community,

I’ve created this as an example (but not tested):

object CheckCommand "snmp-int" {
   command = [ PluginDir + "/" ]

   arguments = {
      "-H" = "$address$"
      "-C" = "$host.vars.snmp_community$"
      "-2" = ""
      "-g" = ""
      "-r" = ""
      "-B" = ""
      "-kM" = ""
      "-f" = ""
      "-n" = "$host.vars.interface$"
      "-w" = "$host.vars.snmp_int_warning$"
      "-c" = "$host.vars.snmp_int_critical$"
1 Like

Do I understand correctly that a parameter with a zero (empty) value will be passed?

Sorry, but I didn’t think of it :slight_smile:

Yes it will, just try it.


if you need a switch its like

"-s" = {
    set_if = "$bloolean_value"


1 Like

I made a little different notation (by the way, I didn’t understand which entry is preferable)

object CheckCommand "net_check_snmp" {
  import "plugin-check-command"
  command = [ PluginDir + "/" ]
  arguments = {
     "-H" = {
       value = "$net_address$"
       required = true
       order = 1
     "-C" = {
       value = "$net_community$"
       required = true
       order = 2
     "-2" = {
       value = ""
       required = true
       order = 3
     "-g" = {
       value = ""
       required = true
       order = 4
... ommited

Work fine.
Another question.
The service is installed as:

apply the service "net: enp0s3" {
    import "generic service"
    check_command = "net_check_snmp"
    vars.net_community = "VerySecretPwd"
    vars.net_interface = "enp0s3"
    vars.net_warn = "10.10"
    vars.net_crit = "20.20"
  command_endpoint = host.vars.agent_endpoint
  assign where host.vars.agent_endpoint

And applied at the end point (‘host.vars.agent_endpoint’)
How can I make an additional refinement of this point, to a node with a specific name (ip address)?

object Host "confluent.local" {
  import "kafka-server"
  check_command = "hostalive" //check is executed on the master
  address = ""
  vars.os = "Linux"
  vars.disks["disk /"] = {
    disk_partitions = "/"
  vars.dirs["dirLog_confluent"] = {
    directory = "/var/log/confluent/"
  vars.dirs["dirLog_kafka"] = {
    directory = "/var/log/kafka/"
  vars.procs_warning = 800
  vars.procs_critical = 900
  vars.agent_endpoint = name 

I’d recommend to not define host specific values e.g. SNMP community in your service definition. Best practice is to define it at your host e.g.:

vars.snmp_community = “YourSecretPW”

and reuse this with your command object as I’ve shown in my example.

For assigning services to hosts I prefer to use host templates. Using variables at your host and assign via that variable is another useful method e.g.

vars.snmp_int = true

assign where host.vars.snmp_int

If a host has more than one interface to be checked I’d recommend to use Apply For instead.

1 Like

I fixed everything in accordance with the recommendations.
Thanks for the documentation link.

PS. It happens that the description in the documentation is not entirely obvious. I would post more consistent examples in the documentation sections. This is just a wish :). Often after reading the full picture of the applyence does not always add up.

Hello and welcome to the community!

If someone helped you get to the bottom of your issue, please mark the answer as the “solution” :slight_smile:
This helps others who have a similar issue to get to the most helpful answer faster.
(And maybe even leave a little :heart: on the posts that helped you out as well :slight_smile: )

About the documentation: If you want to you could do those corrections yourself and submit a pull request? As a starting point, you can edit the file from here :slight_smile:
Your memory is still fresh and you seem to have an idea on what to change too, so your help would be greatly appreciated!
Alternatively, you can also open an issue about it here.

Have a wonderful day!

1 Like

If you do it like this, the Parameters will always set, even if they are not needed. Better use the (set_if)[] to make this plugin work correctly. Icinga2 != (Nagios|Icinga1) where you have to define the same command again and again with different parameters.


1 Like

I know. This was just an example as requested.

Then better teach them to do it right.

I’m sorry, I don’t get your point and I don’t like to discuss this here.

Collegues. Many thanks for help me.

Another question.

In Nagios system i used pnp4nagios by Joerg Linge for build graphics like:

For do this, in RRD i use derective : DERIVE

I know that I can put pnp4 into Icinga2, but now I have InfluxDB + Grafana.
Who can tell how to display such graphs correctly (now they are displayed on an accrual basis)

I did it. I created an additional panel in the Grafana dashboard (base-metrics), where I used in select data the nonNegativeDerivative function. Then arranged a separate graphic in the Grafan plugin, indicating this panel(ID) for a network service. It turned out like this:

Maybe there are other ways?