Difference between revisions of "Monitor your fax queue with Nagios"
(get statistics of sent and received faxes, to nagios) |
(added spaces between output of performace variables, to allow correct graphs) |
||
Line 99: | Line 99: | ||
#print "$err: $sig jobs in queue\n"; | #print "$err: $sig jobs in queue\n"; | ||
### printing output with statistics, and performance data | ### printing output with statistics, and performance data | ||
− | print "$err: $sig jobs in queue ; ($sig_recebidos RECEIVED ; $sig_enviados SENT) | QUEUE=$sig,RECEIVED=$sig_recebidos,SENT=$sig_enviados\n"; | + | print "$err: $sig jobs in queue ; ($sig_recebidos RECEIVED ; $sig_enviados SENT) | QUEUE=$sig, RECEIVED=$sig_recebidos, SENT=$sig_enviados\n"; |
exit $ERRORS{$err}; | exit $ERRORS{$err}; | ||
Latest revision as of 15:16, 25 February 2016
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 ### my alteration gets also de sent faxes and received faxes statistics 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); ### getting statistics, by Andre Ramos my $sig_recebidos=0; my @jobs_recebidos = $ftp->ls("recvq"); #$ftp->quit; $sig_recebidos = scalar(@jobs_recebidos); my $sig_enviados=0; my @jobs_enviados = $ftp->ls("doneq"); $ftp->quit; $sig_enviados = scalar(@jobs_enviados); my $err = "OK"; if ($sig >= $critical) { $err = "CRITICAL"; } elsif ($sig >= $warning) { $err = "WARNING"; } #print "$err: $sig jobs in queue\n"; ### printing output with statistics, and performance data print "$err: $sig jobs in queue ; ($sig_recebidos RECEIVED ; $sig_enviados SENT) | QUEUE=$sig, RECEIVED=$sig_recebidos, SENT=$sig_enviados\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(); }