wrap_multi

wrap_multi

This script runs the specified Nagios-plugin, captures stdout and reformats the performance-data to multi-label-format as specified by check_multi.

See the pod inside of wrap_multi.pl ( with perldoc wrap_multi.pl ) for further details.

INSTALLATION

Installation is not required to just run the script - this is a standalone-script. But you can use the standard-procedure as outlined below, which will install documentation as man-page and copy the script to the systems binary-path.

SUPPORT AND DOCUMENTATION

After installing, you can find documentation for this module with the man command.

derldoc wrap_multi.pl

FILENAME- and PATH of the WRAPPED CHECK-SCRIPT

In order to keep the script simple and independent, only usual file- and directory-names are supported.

This script probably will not work with delimiters other than forward- slashes.

SYNOPSIS

This script runs the specified Nagios-plugin, captures stdout and reformats the performance-data to multi-label-format as specified by check_multi.

EXAMPLE

$ wrap_multi.pl 'check_disk.pl' '-H host' free_space

This prints

DISK OK - free space: / 3326 MB (56%); | 'check_disk::multi_label::instances'=4
/ 15272 MB (77%);
/boot 68 MB (69%);
/home 69357 MB (27%);
/var/log 819 MB (84%); | '/::check_disk::free_space'=2643MB;5948;5958;0;5968
'/boot::check_disk::free_space'=68MB;88;93;0;98 '/home::check_disk::free_space'=69357MB;253404;253409;0;253414 '/var/log::check_disk::free_space'=818MB;970;975;0;980

instead of the following (output without wrap_multi):

DISK OK - free space: / 3326 MB (56%); | '/'=2643MB;5948;5958;0;5968
/ 15272 MB (77%);
/boot 68 MB (69%);
/home 69357 MB (27%);
/var/log 819 MB (84%); | '/boot'=68MB;88;93;0;98
'/home'=69357MB;253404;253409;0;253414
'/var/log'=818MB;970;975;0;980

SYNTAX

BASIC

This wrapper-script receives three parameter, the name of the check script to wrap, its arguments and a label:

wrap_multi.pl check_script arguments label
ADVANCED

An optional 4th parameter prefixes the instance-names and makes them unique in case of having several checks, retrieving different metrics from the same instance. (f.e. usage- and snapshot-data from the volumes)

wrap_multi.pl check_disk.pl 'H host' free fs-

This prints

DISK OK - free space: / 3326 MB (56%); | 'check_disk::multi_label::instances'=4
/ 15272 MB (77%);
/boot 68 MB (69%);
/home 69357 MB (27%);
/var/log 819 MB (84%); | 'fs-/::check_disk::free'=2643MB;5948;5958;0;5968 'fs-/boot::check_disk::free'=68MB;88;93;0;98 'fs-/home::check_disk::free'=69357MB;253404;253409;0;253414 'fs-/var/log::check_disk::free'=818MB;970;975;0;980

IMPLEMENTATION

This script executes whatever is defined by the first argument. Stdout is captured, stderr is send to /dev/null.

MULTI-LINE HEADER (INSTANCE COUNTER)

The number of perf-data elements is counted and used to construct the first multi-label-perfelement in the following format:

'{check-name}::multi_label::{label}'={number of instances}

So the number of perf-elements is taken as the number of instances. If there is no perf-data, the counter is zero.

NEWLINES VS. BLANKS

The Nagios-documentation allows newlines to separate perf-data-elements. The Perl-Module Nagios::Plugin uses blanks. This scripts does the latter and follows what most plugins will do: Separate the perf-elements by blanks. So some of the above examples do not reflect 100% correct what this script will output.

Example:

This input (second part of perf-data in multi-line output)

some message | a=1
b=2
c=3

will get changed to:

some message | 'a::some_check::lab'=1 'b::some_check::lab'=2 'c::some_check::lab'=3

FORMAT DEFINITIONS

STANDARD NAGIOS PERFDATA (INPUT)

This script can process both the Nagios 2.x service-output and the newer Nagios 3.x multiline service-output.

TEXT OUTPUT | OPTIONAL PERFDATA
LONG TEXT LINE 1
LONG TEXT LINE 2
...
LONG TEXT LINE N | PERFDATA LINE 2
PERFDATA LINE 3
...
PERFDATA LINE N

This definition has been taken from nagios.org on 13th of April 2010.

MULTI-LABEL-FORMAT (OUTPUT)
{Instance-Name}::{Plugin}::{Label}={Value[;warn;crit;min;max]}

FORMAT DEFINITION:
Part Description
Instance-Name The string left of each = in the original perf-output
Plugin The file-name of the called script w/o extension (anything left of the last '.')
Label The label is to set to the command-lines second parameter.
Example - this results in 'size_used' as label:

wrap_multi.pl some_check.pl size_used
Value Value, including thresholds and min/max values without any change.

####INSTANCE-LINE The wrapper-script counts the number of instances and adds it as perfdata in front of the first perfdata.
'{Plugin}::multi_label::instances'={count of instances}
Example - if four volumes have been checked by check_disk.pl the first line of the perfdata would be:
'check_disk::multi_label::instances'=4
See also the example above. ####Changelog: 0.0.1 - 2010-04-19 - First version, Alpha but tested. 0.0.2 - 2010-04-22 - Second version, can cope with checks w/o extension, some fine-tuning (spell-checked, perl-critic, documentation) debug-sections commented out (should speed it up) 1.0.0 - 2010-05-28 - First stable version after successfull user acceptance testing 1.0.1 - 2010-07-08 - Bugfixing release addressing shift 8 problem of return-code and perl 5.6 compatibility. ####COPYRIGHT AND LICENCE Copyright (C) 2010 Bacher Systems GmbH. Author: [Ingo Lantschner](http://perl.lantschner.name) This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. For Perl Licence see http://dev.perl.org/licenses/