#!/bin/bash

RET=`/usr/lib/nagios/plugins/check_procs "$@"`
STATUS=$?

if [ $# -gt 2 ] && [ "$1" != "" ]; then
    getopts c:w: name "$@"
    eval $name=$OPTARG
    getopts c:w: name "$@"
    eval $name=$OPTARG
fi

if [[ "$RET" != *"|"* ]]; then
    VAL=`echo $RET | sed 's/^.*: \([0-9]*\) process.*$/\1/'`
    RET="$RET|procs=$VAL;$w;$c;0"
fi

echo "$RET"

exit $STATUS

__END__

=for stopwords
procs Nagios perf performance data remctl 

=head1 NAME

check_procs_perf - Nagios plugin wrapper for check_procs to output Nagios Performance Data

=head1 SYNOPSIS

B<check_procs_perf>

=head1 DESCRIPTION

This Nagios plugin calls C<check_procs> and passes the command line arguments
to that script if there are any.  It then parses the output for performance
data and appends it to the return value.  Please see the man page for check_procs
for all command line parameters.

=head1 EXIT STATUS

B<check_procs_perf> follows the standard Nagios exit status requirements.
This means that it will exit with status 0 if there are no problems or
with status 2 if the number of processes violates the check threshold. 
For other errors, such as invalid syntax, B<check_procs_perf> will exit 
with status 3.


=head1 AUTHORS

Originally pulled from https://github.com/vits/nagios-plugins/blob/master/check_procs_perf
Updated by

Lonlone Lee <lonlone@stanford.edu>

=cut
