Personal tools
HylaFAX The world's most advanced open source fax server

Monitor your fax queue with Nagios

Revision as of 17:54, 19 December 2005 by Paul (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is a plugin that can be used with Nagios, a service and host monitoring program. See http://www.nagios.org/ for more info on how to set up Nagios.

This perl script requires the Net::FTP module, but I think this comes standard with perl these days. If not, go to http://search.cpan.org/ and find it there.

Save this file as check_hylafax in your plugins folder (usually /usr/lib/nagios/plugins or /usr/local/nagios/libexec), and make sure it is executable.

#! /usr/bin/perl -wT

use strict;
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_H $opt_P $opt_w $opt_c $opt_l $opt_p $PROGNAME);
use lib "/usr/lib/nagios/plugins" ;
use utils qw(%ERRORS &print_revision &support &usage);
use Net::FTP;

$PROGNAME = "check_hylafax";

sub print_help ();
sub print_usage ();

$ENV{'PATH'}='';
$ENV{'BASH_ENV'}=''; 
$ENV{'ENV'}='';

Getopt::Long::Configure('bundling');
GetOptions
	("V"   => \$opt_V, "version"    => \$opt_V,
	 "h"   => \$opt_h, "help"       => \$opt_h,
	 "w=s" => \$opt_w, "warning=s"  => \$opt_w,
	 "c=s" => \$opt_c, "critical=s" => \$opt_c,
	 "H=s" => \$opt_H, "hostname=s" => \$opt_H,
	 "P=i" => \$opt_P, "port=i" => \$opt_P,
	 "l=s" => \$opt_l, "login=s" => \$opt_l,
	 "p=s" => \$opt_p, "password=s" => \$opt_p,
);

if ($opt_V) {
	print_revision($PROGNAME,'$Revision: 1.0 $');
	exit $ERRORS{'OK'};
}

if ($opt_h) {print_help(); exit $ERRORS{'OK'};}

my $host = ($opt_H ? $opt_H : "localhost");
usage("Invalid host: $opt_H\n") unless $host =~ /^[-.A-Za-z0-9]+$/;

my $port = ($opt_P ? $opt_P : "4559");
usage("Invalid port: $opt_P\n") unless ($port > 1 and $port < 32767);

usage("Warning threshold not specified\n") if not $opt_w;
my $warning = $opt_w;
usage("Invalid warning threshold: $opt_w\n") unless $warning =~ /^\d+$/;

usage("Critical threshold not specified\n") if not $opt_c;
my $critical = $opt_c;
usage("Invalid critical threshold: $opt_c\n") unless $critical =~ /^\d+$/;

#($opt_c) || usage("Critical threshold not specified\n");
#my $critical = $1 if ($opt_c =~ /([0-9]{1,2}|100)/);
#($critical) || usage("Invalid critical threshold: $opt_c\n");

my $sig=0;
my $ftp = Net::FTP->new($host, Port => $port);
if (not $ftp) {
	print "ERROR: Can't connect to $opt_h: $@\n";
	exit $ERRORS{'UNKNOWN'};
}
if (not $ftp->login($opt_l, $opt_p)) {
	print "ERROR: Can't login to $opt_h: $@\n";
	exit $ERRORS{'UNKNOWN'};
}
my @jobs = $ftp->ls("sendq");
$ftp->quit;
$sig = scalar(@jobs);

my $err = "OK";
if ($sig >= $critical) {
	$err = "CRITICAL";
} elsif ($sig >= $warning) {
	$err = "WARNING";
}
print "$err: $sig jobs in queue\n";
exit $ERRORS{$err};

sub print_usage () {
	print "Usage: $PROGNAME [-H host] [-P port] [-l login] [-p password] -w <warn> -c <crit>\n";
	print "\n";
	print "Required Arguments:\n";
	print "  -w, --warning==INTEGER\n";
	print "     generate warning state if job count is greater than this number\n";
	print "  -c, --critical==INTEGER\n";
	print "     generate critical state if job count is greater than this number\n";
	print "\nOptional Arguments:\n";
	print "  -H, --hostname=STRING\n";
	print "     connect to this host. Default is localhost.\n";
	print "  -P, --port=INTEGER\n";
	print "     connect to this port. Default is 4559.\n";
	print "  -l, --login=STRING\n";
	print "     connect using this login name.\n";
	print "  -p, --password=STRING\n";
	print "     connect using this password.\n";
	print "\n";
}

sub print_help () {
	print_revision($PROGNAME,'$Revision: 1.0 $');
	print "Created by Adam Fox, November 2004

This plugin reports how many jobs are in a HylaFAX fax queue.

";
	print_usage();
	support();
}


Powered by MediaWiki
Attribution-ShareAlike 2.5

Project hosted by iFAX Solutions