Parameters, Option Processing¶
Nagios-compatible reserved options, not to be used for other purposes: -a, --authentication (authentication password), -C, --community (SNMP community), -c, --critical (critical threshold), -h, --help, -H, --hostname, -l, --logname (login name), -p, --password, -p, --port (network port), -t, --timeout, -u, --url, -u, --username, -V, --version, -v, --verbose, -w, --warning (warning threshold).
Every plugin supports at least:
--help(-h): short usage, then all options with their defaults, ending with a link to the online documentation. Within 80 characters width. Exits withSTATE_UNKNOWN(3).--version(-V): plugin name and__version__. Exits withSTATE_UNKNOWN(3).
The documentation link comes from lib.args:
parser = argparse.ArgumentParser(
description=DESCRIPTION,
epilog=lib.args.epilog(__file__),
formatter_class=lib.args.HelpFormatter,
)
lib.args.epilog() derives the URL from the file name, lib.args.HelpFormatter keeps it on one line. Notification and event plugins name their family, e.g. lib.args.epilog(__file__, section='notification-plugins').
No positional arguments. All other options are long parameters only, words separated by -. Recommended names: --activestate, --alarm-duration, --always-ok, --argument, --authtype, --brief, --cache-expire, --command, --community, --config, --count, --critical (also --critical-count, -cpu, -maxchildren, -mem, -pattern, -regex, -slowreq, -steal), --database, --datasource, --date, --device, --donor, --filename, --filter, --full, --hide-ok, --hostname, --icinga-callback (also --icinga-password, -service-name, -url, -username), --idsite, --ignore, --input, --insecure, --instance, --interface, --interval, --ipv6, --key, --latest, --lengthy, --loadstate, --match, --message, --message-key, --metric, --mib, --mibdir, --mode, --module, --mount, --no-kthreads, --no-match-severity, --no-perfdata, --no-proxy, --no-summary, --node, --only-dirs, --only-files, --password, --path, --pattern, --per-cpu, --perfdata, --perfdata-key, --period, --port, --portname, --prefix, --privlevel, --response, --service, --severity, --snmp-version, --starttype, --state, --state-key, --status, --substate, --suppress-lines, --task, --team, --test, --timeout, --timerange, --token, --trigger, --type, --unit, --unitfilestate, --url, --username, --version, --virtualenv, --warning (with the same suffixes as --critical).
Usual parameter types: type=float, type=int, type=lib.args.csv, type=lib.args.float_or_none, type=lib.args.int_or_none, type=str (default), choices=[...], and action='store_true' / 'store_false' for switches.
Threshold parameters (--warning, --critical) in new plugins use type=str to support Nagios range expressions (80, 10:, ~:50, @10:20), evaluated with lib.base.get_state(value, args.WARN, args.CRIT, _operator='range'). See the example plugin and Threshold and Ranges.
Hints:
csvtype for complex tuples:--input='Name, Value, Warn, Crit'gives['Name', 'Value', 'Warn', 'Crit'].appendaction for repeating parameters (thedefaultmust be a list):--input=a --input=bgives['a', 'b']. Combined withcsv, a two-dimensional list.- For
appenddefaults, leavedefault=Noneinadd_argument()and fill in the default list afterparse_args()if the value is stillNone(see https://bugs.python.org/issue16399). - An
appendparameter with a non-empty default list gets an--extend-<name>companion that appends instead of replacing (seeexample). - Stay backwards compatible: keep renamed or dropped parameters, silently ignored, with
help=argparse.SUPPRESS, so hosts can be updated before the monitoring server. - Tolerate unknown parameters with
parser.parse_known_args(), so a new parameter in the service definition does not turn not-yet-updated hosts UNKNOWN.
Parameter Help Text Format¶
Help texts are consistent across all plugins. Each property goes on its own line (implicit string concatenation), in this order:
- Purpose (what the parameter does)
- List semantics of an
appendparameter with a default list ("Replaces the default list, ..." / "..., appended to ...") - Data type or format (if not obvious)
- Regex or case-sensitivity note (if applicable)
- Repeating note (if applicable)
- Nagios range support (if applicable)
- Example (if helpful)
- Default value (always last, always present if there is one)
Standard help texts live in lib.args.HELP_TEXTS; use lib.args.help('--parameter-name') wherever possible, write plugin-specific ones inline in the same format, or prefix the standard one:
parser.add_argument(
'--url',
help='GitLab health URL endpoint. ' + lib.args.help('--url'),
dest='URL',
default=DEFAULT_URL,
)
- Use
%(default)s, never a hardcoded value. Forappenddefaults, join theDEFAULT_Xconstant. No default forstore_true/store_falseswitches (--always-ok,--insecure,--no-perfdata,--no-proxy,--lengthy). - "Replaces the default list, use
--extend-<name>to append to it." / "..., appended to the default or the--<name>list." - Defaults and examples go on their own lines.
- "Can be specified multiple times." for
action='append'(not "(repeating)"). - "Supports Nagios ranges." when the value goes through
lib.base.get_state(). - Always state "Case-insensitive." or "Case-sensitive."
- "Uses Python regular expressions." when the parameter accepts a regex.
- End every help text with a period; a closing
Default: %(default)sneeds none, and neither does a closing code example (Example: `--warning=80`), where a copied period would end up in the value. - Identical parameters across plugins get identical help texts.
- The developer-only
--testis mapped toargparse.SUPPRESSinlib.args(accepted, but hidden from--help, READMEs and baskets). Declare it withhelp=lib.args.help('--test'), never inline.
Threshold and Ranges¶
The range syntax (start:end, ~, @, inclusive/exclusive) is documented in THRESHOLDS.md. In a plugin, keep type=str and evaluate with the library, never with a per-plugin range parser:
item_state = lib.base.get_state(value, args.WARN, args.CRIT, _operator='range')
state = lib.base.get_worst(state, item_state)
References with multiple metrics and per-row worst-state aggregation: check-plugins/procs/procs and example. Example --warning 2:100 --critical 1:150:
val 0 1 2 .. 100 101 .. 150 151
-w WA WA OK OK WA WA WA
-c CR OK OK OK OK OK CR
=> CR WA OK OK WA WA CR
Single-bound ranges (--warning 190: --critical 200:) aggregate the same way.
Ranges cover every bound the operator picks (a percentage, count, age, temperature). A parameter naming a fixed classification boundary defined outside the plugin keeps a plain numeric type with a direct comparison, e.g. a CVSS base score, where range syntax would mean nothing. Reference: --critical-cvss in wordpress-security-scan. Say so in the README, so the missing range support reads as a decision.