Check multiple processes with arguments


(Bogdan Stoica) #1

I have the following commands definitions in Icinga2:

object CheckCommand "nrpe-process" {
        import "nrpe-common"
        vars.nrpe_command = "check_process"
        vars.nrpe_args = [ "$process_name$" ]
}

object CheckCommand "nrpe-processwitharg" {
        import "nrpe-common"
        vars.nrpe_command = "check_processwitharg"
        vars.nrpe_args = [ "$process_name$", "$process_withargument$" ]
}

object CheckCommand "nrpe-processarg" {
        import "nrpe-common"
        vars.nrpe_command = "check_processarg"
        vars.nrpe_args = [ "$process_argument$" ]
}

object CheckCommand "nrpe-processregexp" {
        import "nrpe-common"
        vars.nrpe_command = "check_processregexp"
        vars.nrpe_args = [ "$process_pattern$" ]
}

And this is the service definition:

apply Service "process-nrpe-linux-" for (identifier => process in host.vars.processes) {
  import "generic-service"

  if (!process.proc_warn) { process.proc_warn = "1" }
  if (!process.proc_crit) { process.proc_crit = "0" }

  vars.proc_warn = process.proc_warn
  vars.proc_crit = process.proc_crit

  display_name = identifier + " Processes"

  if (process.argument) {
    vars.process_name += identifier
    vars.process_argument = process.argument

    check_command = "nrpe-processarg"

  } else if (process.withargument) {
    vars.process_name += identifier
    vars.process_withargument = process.withargument

    check_command = "nrpe-processwitharg"

  } else if (process.pattern) {
    vars.process_pattern = process.pattern

    check_command = "nrpe-processregexp"

  } else {
    vars.process_name += identifier

    check_command = "nrpe-process"
  }

  assign where host.vars.os == "Linux" && host.vars.is_nrpe
  ignore where !host.vars.processes
}

That’s what I have in my nrpe config file:

command[check_process]=/bin/sudo /usr/lib64/nagios/plugins/check_procs -c 1: -C "$ARG1$"
command[check_processwitharg]=/bin/sudo /usr/lib64/nagios/plugins/check_procs -c 1: -C "$ARG1$" -a "$ARG2$"
command[check_processarg]=/bin/sudo /usr/lib64/nagios/plugins/check_procs -c 1: -a "$ARG1$"
command[check_processregexp]=/bin/sudo /usr/lib64/nagios/plugins/check_procs -c 1: --ereg-argument-array=$ARG1$

Now for a host, I do this:

  vars.processes["chronyd"] = { }
  vars.processes["java"] = { argument = "logstash" }
  vars.processes["java"] = { argument = "elasticsearch" }

The problem here is that, if I define multiple processes with arguments, only the last process with argument is taken into consideration and a check is issued for it. Meaning that, in the above scenario, I only get a check for java with elasticsearch argument whilst the logstash process is ignored so it’s not checked.

How should I adapt my service defintion so I can check both processes with arguments? I want to be able to check both elasticsearch and logtsash processes.

Thanks!


#2

You overwrite you first “java” entry with the second, because they both have the same identifier.
Try something like

vars.processes["java-logstash"] = {
  process_name = "java"
  argument = "logstash"
}
vars.processes["java-elasticsearch"] = {
  process_name = "java"
  argument = "elasticsearch"
}

and then in your service definition use:

vars += process

This is not tested, but I hope you get the idea. Each different combination of process and argument needs a separate identifier. The name of the process can be the same, but not the identifier.


(Bogdan Stoica) #3

Thank you! It works like a charm!