#!/usr/bin/perl -w
#
# BACKGROUND
# This checks the length of the queue.  You give it a warning and a critical level.
#
# OPERATION
# Run this with a warning and critical level... and that's it.
#
# CONFIGURATION
# Set the path for "bpdbjobs".
#
# ISSUES
#
# TODO
#
# AUTHOR
# Nicholas Tang <ntang@mail.communityconnect.com>

use strict;

#######################################################
# SET THIS PATH CORRECTLY OR YOUR LIFE IS FORFEIT
#######################################################
my $BPDBJOBS = "/usr/openv/netbackup/bin/admincmd/bpdbjobs -summary -all_columns";
#######################################################

#######################################################
# Please don't change these.
#######################################################
use constant OK		=> 0;
use constant WARNING	=> 1;
use constant CRITICAL	=> 2;
use constant UNKNOWN	=> 3;
use constant VERSION	=> 0.1;
#######################################################
use vars qw($status $output $warning $critical $queued);
#######################################################
$warning = 5;
$critical = 10;
#######################################################


$status = OK;

$output = `$BPDBJOBS`;
$output =~ /,QUEUED=(\d+)/;
$queued = $1;

#print $queued;
unless(defined($queued)) {
	die "Something is ver ver wrong with the netbackup server.\n";
}
if ( $queued < $warning) {
	print "OK - Queue is of normal size [$queued]\n";
	exit OK;
}
if ( $queued >= $warning && $queued < $critical ) {
	print "WARNING - Queue is $queued\n";
	exit WARNING;
}
if ( $queued >= $critical )  {
	print "CRITICAL - Queue is $queued\n";
	exit CRITICAL;
}
print "$1\n";	
#MASTER=bp83,QUEUED=59,REQUEUED=0,ACTIVE=2,SUCCESSFUL=191,PARTIALLY=0,FAILED=7,TOTAL=259
