]>
jfr.im git - munin-plugins.git/blob - lpstat
9 lpstat - Plugin to graph the queue size for the list of printers
10 available through the command "lpstat"
27 This script was initially developed by Anstat Pty Ltd for internal use
28 and has kindly been made available to the Open Source community for
29 redistribution and further development under the terms of the
30 GNU General Public License: http://www.gnu.org/licenses/gpl.html
32 Readapted to munin by Nikolai Langfeldt for Oslo Airport
37 #%# capabilities=autoconf
49 my @exclude; # Should take this from environment.
51 # Force C output from lpstat
52 $ENV{'LC_MESSAGES'} = "C";
54 # This is a dumb-down. Should take hostname(s) from environment or
56 my $host = '127.0.0.1';
58 my $lpstat = exists $ENV{lpstat
} ? $ENV{lpstat
} : '';
60 # If the envvar is not set, look for lpstat
62 # Still not found? Check obvious places
63 my @dirs = split(':',$ENV{PATH
});
64 push (@dirs, qw(/usr/bin /usr/sbin /usr/local/bin /usr/local/sbin) );
66 until ($lpstat or @dirs == 0) {
67 my $dir = shift @dirs;
68 my $path = $dir.'/lpstat';
69 $lpstat = $path if -x
$path;
71 } elsif (! -x
$lpstat) {
72 # If it is set, verify it
73 warn "Predefined lpstat ($lpstat) is not a executable\n";
77 if (defined($ARGV[0]) && $ARGV[0] eq 'autoconf') {
79 print "no (lpstat not found)\n";
82 if( ! open(LPSTAT_R
, "$lpstat $host -v 2>/dev/null |") ) {
83 print "no (could not execute lpstat)\n";
87 if ( ! close(LPSTAT_R
) ) {
88 print "no (lpstat returned non-zero)\n";
92 if (! m/device for /mi) {
93 print "no (no printers configured)\n";
100 ####################################################
101 # Check printers are accepting jobs
102 ####################################################
103 # Get list of printers, showing which are accepting jobs...
104 if( ! open(LPSTAT_A
, "$lpstat $host -a|") ) {
105 print "graph_title Could not execute lpstat command\n";
111 /(\S+) (.*) since/mi ;
114 if( grep /^$printer$/, @exclude ) {
118 @printers = ( @printers, $printer );
123 ####################################################
124 # Check printers are enabled
125 ####################################################
126 # Get list of printers, showing which are enabled/disabled...
127 if( ! open(LPSTAT_P
, "$lpstat $host -p|") ) {
128 print "graph_title Could not execute lpstat command\n";
135 if ( /^printer\s+(\S+)\s.*disabled/mi ) {
137 if( grep /^$printer$/, @exclude ) {
144 # Get list of jobs for each printer...
145 foreach $printer ( @printers ) {
146 if( grep /^$printer$/, @exclude ) {
150 if( ! open(LPSTAT
, "$lpstat $host -o $printer|") ) {
151 print STDERR
"Could not execute command: '$lpstat -o $printer' \n";
154 @jobs = ( <LPSTAT
> );
156 $jobs{$printer}=$n_jobs || 0;
159 if ( defined($ARGV[0]) && $ARGV[0] eq 'config') {
160 print "graph_title Print queues
161 graph_args --base 1000
162 graph_vlabel Queued jobs
163 graph_category printing
165 foreach my $printer (sort(keys %jobs)) {
166 print "$printer.label $printer\n";
167 print "$printer.type GAUGE\n";
172 foreach my $printer (sort(keys %jobs)) {
173 print "$printer.value ",$jobs{$printer},"\n";