/usr/share/munin/plugins/lpstat is in munin-node 1.4.6-3ubuntu3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | #!/usr/bin/perl
# -*- perl -*-
=head1 NAME
lpstat - Plugin to graph the queue size for the list of printers
available through the command "lpstat"
=head1 CONFIGURATION
No configuration
=head1 AUTHORS
Anstat Pty Ltd
Nikolai Langfeldt
=head1 LICENSE
Gnu GPL
=head1 NOTES
This script was initially developed by Anstat Pty Ltd for internal use
and has kindly been made available to the Open Source community for
redistribution and further development under the terms of the
GNU General Public License: http://www.gnu.org/licenses/gpl.html
Readapted to munin by Nikolai Langfeldt for Oslo Airport
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
use strict;
use Getopt::Std;
my $printer;
my @printers;
my $status;
my @jobs;
my $n_jobs;
my @exclude; # Should take this from environment.
# Force C output from lpstat
$ENV{'LC_MESSAGES'} = "C";
# This is a dumb-down. Should take hostname(s) from environment or
# as wildcard plugin.
my $host = '127.0.0.1';
my $lpstat = exists $ENV{lpstat} ? $ENV{lpstat} : '';
# If the envvar is not set, look for lpstat
if (!$lpstat) {
# Still not found? Check obvious places
my @dirs = split(':',$ENV{PATH});
push (@dirs, qw(/usr/bin /usr/sbin /usr/local/bin /usr/local/sbin) );
until ($lpstat or @dirs == 0) {
my $dir = shift @dirs;
my $path = $dir.'/lpstat';
$lpstat = $path if -x $path;
}
} elsif (! -x $lpstat) {
# If it is set, verify it
warn "Predefined lpstat ($lpstat) is not a executable\n";
undef $lpstat;
}
if ($ARGV[0] eq 'autoconf') {
if( ! -x $lpstat ) {
print "no (lpstat not found)\n";
exit 0;
}
if( ! open(LPSTAT_R, "$lpstat $host -r 2>/dev/null |") ) {
print "no (could not execute lpstat)\n";
exit 0;
}
$_ = <LPSTAT_R>;
if (! m/is running/mi) {
print "no (scheduler is not running)\n";
exit 0;
}
print "yes\n";
exit 0;
}
####################################################
# Check printers are accepting jobs
####################################################
# Get list of printers, showing which are accepting jobs...
if( ! open(LPSTAT_A, "$lpstat $host -a|") ) {
print "graph_title Could not execute lpstat command\n";
exit -1;
}
while(<LPSTAT_A>) {
chomp;
/(\S+) (.*) since/mi ;
$printer = $1;
$status = $2;
if( grep /^$printer$/, @exclude ) {
next;
}
if( /accepting/ ) {
@printers = ( @printers, $printer );
}
}
close(LPSTAT_A);
####################################################
# Check printers are enabled
####################################################
# Get list of printers, showing which are enabled/disabled...
if( ! open(LPSTAT_P, "$lpstat $host -p|") ) {
print "graph_title Could not execute lpstat command\n";
exit -1;
}
my %jobs = ();
while(<LPSTAT_P>) {
if ( /^printer\s+(\S+)\s.*disabled/mi ) {
$printer=$1;
if( grep /^$printer$/, @exclude ) {
next;
}
}
}
close(LPSTAT_P);
# Get list of jobs for each printer...
foreach $printer ( @printers ) {
if( grep /^$printer$/, @exclude ) {
next;
}
if( ! open(LPSTAT, "$lpstat $host -o $printer|") ) {
print STDERR "Could not execute command: '$lpstat -o $printer' \n";
exit 2;
}
@jobs = ( <LPSTAT> );
$jobs{$printer}=$n_jobs || 0;
}
if ($ARGV[0] eq 'config') {
print "graph_title Print queues
graph_args --base 1000
graph_vlabel Queued jobs
graph_category printing
";
foreach my $printer (sort(keys %jobs)) {
print "$printer.label $printer\n";
print "$printer.type COUNTER\n";
}
exit 0;
}
foreach my $printer (sort(keys %jobs)) {
print "$printer.value ",$jobs{$printer},"\n";
}
|