Icinga / icinga2

The core of our monitoring platform with a powerful configuration language and REST API.
https://icinga.com/docs/icinga2/latest
GNU General Public License v2.0
1.99k stars 573 forks source link

Support parameter delimiters other than whitespace for check execution #6277

Closed plastikat closed 2 years ago

plastikat commented 6 years ago

apt command definition in itl/command-plugins.conf is currently half-broken. This is because the check_apt plugin seems to have a unique arguments parsing logic. For example --upgrade option requires an equals sign (and no spaces) between the option and its value. And even if you use a short variant -d it again requires no spaces between an option and its value. Just try to run check_apt directly specifying "-o 'Debug::NoLocking=true' -s -qq" (which is the default) as the value for the options mentioned above. The same applies to --dist-upgrade option. At the same time --include, --exclude and --critical seem to work without an equals sign.

Possible Solution

As far as I understand, the current arguments parsing logic in Icinga2 always puts a space between an option and its value. One way to solve it could probably be to join these without any delimiter and put the necessary delimiter inside option name - but this would require the change in all commands definitions...

Your Environment

Copyright (c) 2012-2017 Icinga Development Team (https://www.icinga.com/) License GPLv2+: GNU GPL version 2 or later http://gnu.org/licenses/gpl2.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

Application information: Installation root: /usr Sysconf directory: /etc Run directory: /run Local state directory: /var 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

System information: Platform: Ubuntu Platform version: 16.04.4 LTS (Xenial Xerus) Kernel: Linux Kernel version: 4.4.0-122-generic Architecture: x86_64

Build information: Compiler: GNU 5.3.1 Build host: 9c880c2f42f5

Crunsher commented 6 years ago

As far as I understand, the current arguments parsing logic in Icinga2 always puts a space between an option and its value.

That is correct. It should be possible to work around this with the help of skip_key and macros, but there is no icinga functionality that makes it easier. Which is why I took the liberty of expanding the scope of your issue.

dnsmichi commented 6 years ago

@Crunsher I would keep this workaround hidden in the ITL, and not bloat up the process class here. I'm strongly against changing this.

dnsmichi commented 5 years ago

Seen this here as well: https://community.icinga.com/t/problem-migrating-a-check-from-nagios-to-icinga2-handover-arg1/1637/9?u=mfriedrich

Al2Klimov commented 4 years ago

Hello @plastikat and thank you for reporting!

Please tell whether this fits your need:

https://github.com/Icinga/icinga2/blob/984534b5ef2dcbadb6d5fe24a9b844e59a5a0969/itl/command-plugins.conf#L1925-L1934

Best, AK

plastikat commented 4 years ago

@Al2Klimov, thank you for the refinement, it looks good to me!

Please let me know if any further action is expected on my side.

Linuxfabrik commented 3 years ago

This is also true for at least all check-plugins that work with python's argparse library. Example is this executable python script called negative-option-value.py (doesn't matter if you use Python 2 or Python 3):

#!/usr/bin/env python3

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-w', '--warning', dest='WARN')
args = parser.parse_args()
print(args)

Suppose we want to test for a Nagios-range that contains negative values. This works:

$ ./negative-option-value.py --warning=-60:10
Namespace(WARN='-60:10')

Pay attention to the equal sign between option and value. It is needed because the following variant does not work:

$ ./negative-option-value.py --warning -60:10
negative-option-value.py: error: argument -w/--warning: expected one argument

The possibility to specify parameter separators other than spaces for the check execution would be more than helpful.

Linuxfabrik commented 2 years ago

Generally the --parameter=value style of options will be more robust against any wildcard expansion. This now also has impact on Windows if running Python checks compiled with Nuitka/MinGW64 with cmd.exe (see https://github.com/Nuitka/Nuitka/issues/1370 for details).

lippserd commented 2 years ago

ref/IP/38043