Escape quotes on nrpe arguments

Hi all,

I need to execute the following command as an icinga2 service:

# /usr/lib/nagios/plugins/check_nrpe -H 10.0.0.100 -c check_tasksched -a "filter=enabled eq 1 AND title eq 'PKI-Health'" 'crit=exit_code ne 0' show-all 'detail-syntax= Der Job %(title) hat den Exitode %(exit_code)'
 Der Job PKI-Health hat den Exitode 0|'PKI-Health_exit_code'=0;0;0

As in the service definition here

 apply Service "check_checktask_PKI-Health" {
     import "generic-service"
     display_name = "checktask PKI-Health"
     check_command = "nrpe"
     vars.nrpe_command = "check_tasksched"
     vars.nrpe_arguments = "\"filter=enabled eq 1 AND title eq 'PKI-Health'\" 'crit=exit_code ne 0' show-all 'detail-syntax= Der Job %(title) hat den Exitode %(exit_code)'"
     assign where regex("pki", host.name)
    }

The service fails with
Invalid command line: unrecognised option '"filter=enabled eq 1 AND title eq 'PKI-Health'" 'crit=exit_code ne 0' show-all 'detail-syntax= Der Job %(title) hat den Exitode %(exit_code)''

But its exactly what it has to be. Copy/paste the “unrecognised option” to the shell command passes OK.
How do I have to quote the arguments above in the “vars.nrpe_arguments” variable?
Thank you and best regards

Ralf

icinga2 --version

icinga2 - The Icinga 2 network monitoring daemon (version: r2.10.3-1)

Copyright (c) 2012-2019 Icinga GmbH (https://icinga.com/)
License GPLv2+: GNU GPL version 2 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

System information:
  Platform: Ubuntu
  Platform version: 18.04.2 LTS (Bionic Beaver)
  Kernel: Linux
  Kernel version: 4.15.0-46-generic
  Architecture: x86_64

Build information:
  Compiler: GNU 7.3.0
  Build host: 5746b2511d14

Application information:

General paths:
  Config directory: /etc/icinga2
  Data directory: /var/lib/icinga2
  Log directory: /var/log/icinga2
  Cache directory: /var/cache/icinga2
  Spool directory: /var/spool/icinga2
  Run directory: /run/icinga2

Old paths (deprecated):
  Installation root: /usr
  Sysconf directory: /etc
  Run directory (base): /run
  Local state directory: /var

Internal paths:
  Package data directory: /usr/share/icinga2
  State path: /var/lib/icinga2/icinga2.state
  Modified attributes path: /var/lib/icinga2/modified-attributes.conf
  Objects path: /var/cache/icinga2/icinga2.debug
  Vars path: /var/cache/icinga2/icinga2.vars
  PID path: /run/icinga2/icinga2.pid

Perhaps this one might help.

BTW: Please use formatting tags (see FAQ for details) as it enhances readability.

1 Like

Hi Wolfgang,

i actually used formatting but a “preview post” function would help me to improve the post. :slight_smile:
Regarding your link that is not my recent problem. The arguments itself are passed.

That behaviour happens when I need to escape quotes on some agruments on the commandline as the check itself needs this syntax on the target.
Kind regards

Ralf

Aditionally I see, that the vars.nrpe_arguments are not correctly shown here.
Here you see it better (found the preview :slight_smile: ):

   apply Service "check_checktask_PKI-Health" {
     import "generic-service"
     display_name = "checktask PKI-Health"
     check_command = "nrpe_legacy"
     vars.nrpe_command = "check_tasksched"
     vars.nrpe_arguments = "\"filter=enabled eq 1 AND title eq 'PKI-Health'\" 'crit=exit_code ne 0' show-all 'detail-syntax= Der Job %(title) hat den Exitode %(exit_code)'"
     assign where regex("pki", host.name)
    }

Looking at the documentation and the other post it should be something like

 apply Service "check_checktask_PKI-Health" {
     import "generic-service"
     display_name = "checktask PKI-Health"
     check_command = "nrpe_legacy"
     vars.nrpe_command = "check_tasksched"
     vars.nrpe_arguments = [ "-a \"filter=enabled eq 1 AND title eq 'PKI-Health'\" 'crit=exit_code ne 0' show-all 'detail-syntax= Der Job %(title) hat den Exitcode %(exit_code)'"
     assign where regex("pki", host.name)
1 Like

Good morning,

thank you for you reply.
According to the command definition in /usr/share/icinga2/include/command-plugins.conf I cannot confirm this:

 object CheckCommand "nrpe" {
        import "ipv4-or-ipv6"

        command = [ PluginDir + "/check_nrpe" ]

        arguments = {
                ...
                "-a" = {
                        value = "$nrpe_arguments$"
                        repeat_key = false
                        order = 1
                }

Changing that behaviour would lead to have more than 1000 services to be rewritten on my side.
Regards

Ralf

Any further Ideas? I think this is a common topic since lot of services base on NSCP/NRPE arguments.

How does the executed command line from Icinga itself look like?

Cheers,
Michael

Hi Michael,

meanwhile I got it working. I need to use the quoted arguments as comma separated array

apply Service "check_checktask_PKI-Health" {
 import "generic-service"
 display_name = "checktask PKI-Health"
 check_command = "nrpe_legacy"
 vars.nrpe_command = "check_tasksched"
 vars.nrpe_arguments = [ "filter=enabled eq 1 AND title eq 'PKI-Health'", "crit=exit_code ne 0", "show-all", "detail-syntax= Der Job %(title) hat den Exitode %(exit_code)" ]
 assign where regex("pki", host.name)
}

Thanks @all for the hints
Cheers
Ralf

1 Like