• Antelope Release 5.5 Mac OS X 10.8.5 2015-04-21

 

NAME

parse_ranges, categorize_return_value - utilities for Nagios plugins

SYNOPSIS

use nagios_antelope_utils qw(&categorize_return_value
	&parse_ranges %ERRORS $VERBOSE);

($warn_at, $warn_hi, $warn_low, $crit_at, $crit_hi, $crit_low)
	= parse_ranges($warning_input, $critical_input)
($error_code, $description) = categorize_return_value($return_value,
	$warn_at, $warn_hi, $warn_low, $crit_at, $crit_hi, $crit_low)
print_version($VERSION, $AUTHOR);
print_results($service_name, $result_code, $result_perf_val, $result_descr);

SUPPORT


Contributed code: NO BRTT support.
THIS PIECE OF SOFTWARE WAS CONTRIBUTED BY THE ANTELOPE USER COMMUNITY. BRTT DISCLAIMS ALL OWNERSHIP, LIABILITY, AND SUPPORT FOR THIS PIECE OF SOFTWARE.

FOR HELP WITH THIS PIECE OF SOFTWARE, PLEASE CONTACT THE CONTRIBUTING AUTHOR.

DESCRIPTION

parse_ranges reads in user input to -w and -c options and parses the fields into a set of variables that are easier to use. The format for the warn and critical input is the standard Nagios range grammar as described in the Nagios plugin development guide: [@]start:end Notes: - start > end> - start and ":" is not required if start=0 - if range is of format "start:" and end is not specified, assume end is infinity - to specify negative infinity, use "~" - alert is raised if metric is outside start and end range (inclusive of endpoints) - if range starts with "@", then alert if inside this range (inclusive of endpoints) categorize_return_values takes the retrieved value from and sorts it into a valid Nagios plugin return code given the warning and critical ranges that were input. The arguments include the return value that needs to be sorted, along with the values that make up the output of the parse_ranges subroutine. print_version prints a version banner with version number and author to STDOUT. print_results prints to STDOUT a Nagios-friendly string with the service name, a result code, a performance value, and a description of that value. %ERRORS is an associative array to be used for generating return values. It is defined as follows:
%ERRORS=('OK'=>0,'WARNING'=>1,
               'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);

EXAMPLE

For parsing ranges, one might use a section of code that appears as follows:
    if ((defined $opt_warn) && (defined $opt_crit))
    {
        ($warn_at, $warn_hi, $warn_low, $crit_at, $crit_hi, $crit_low) =
            parse_ranges($opt_warn, $opt_crit);
        if ((!defined $warn_at) || (!defined $warn_hi)
	     || (!defined $warn_low)
             || (!defined $crit_at) || (!defined $crit_hi)
             || (!defined $crit_low))
        {
             print "Error in threshold ranges!\n";
             exit $ERRORS{'UNKNOWN'};
        }
    }

One might then obtain a value to check, and categorize it with the following:
{
    ...
    return categorize_return_value($time_difference, $warn_at,
    				   $warn_hi, $warn_low,
				   $crit_at, $crit_hi, $crit_low);
}

RETURN VALUES

parse_ranges returns a set of variables indicating the range of data that was parsed. This includes an @ sign in the $warn_at and $crit_at variables if one was entered. The $warn_hi and $crit_hi variables get the upper bound of the range, and the $warn_low and $crit_low variables get the lower bound of the range. If there were errors parsing, an empty list is returned. categorize_return_value returns an error code suitable for exiting with, along with the return value that was checked.

DIAGNOSTICS

To obtain more info on STDOUT about the parsing and values obtained, set the $nagios_antelope_utils::VERBOSE flag to 1.

SEE ALSO

nagios_check_orbstat(1)

AUTHOR

Steve Foley
Institute of Geophysics and Planetary Physics
Scripps Institution of Oceanography
Antelope User Group Contributed Software
Printer icon