Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / printer / snmp__hpclj @ 17f78427

Historique | Voir | Annoter | Télécharger (4,9 ko)

1 832a58c5 Kai
#!/usr/bin/perl -w
2
3
=head1 NAME
4
5
Monitor Consumables of HP Color LaserJet Printers.
6
Should also work on non-Color LaserJet Printers though.
7
8
=head1 AUTHOR
9
10
Kai Boenke
11
12
=head1 LICENSE
13
14
Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
15
16
=back
17
18
19
#####
20
# Enable SNMP-Discovery
21
###
22
=head1 MAGIC MARKERS
23
  #%# family=snmpauto
24
  #%# capabilities=snmpconf
25
=cut
26
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") {
27
	print "require 1.3.6.1.2.1.43.11.1.1.9.1.1\n";
28
	exit 0;
29
}
30
31
32
#####
33
# Initialize
34
###
35
use strict;
36
use Munin::Plugin::SNMP;
37
my $session = Munin::Plugin::SNMP->session();
38
39
40
#####
41
# Declare OIDs
42
###
43
use constant oid_black_max		=> ".1.3.6.1.2.1.43.11.1.1.8.1.1";
44
use constant oid_black_cur		=> ".1.3.6.1.2.1.43.11.1.1.9.1.1";
45
use constant oid_cyan_max		=> ".1.3.6.1.2.1.43.11.1.1.8.1.2";
46
use constant oid_cyan_cur		=> ".1.3.6.1.2.1.43.11.1.1.9.1.2";
47
use constant oid_magenta_max		=> ".1.3.6.1.2.1.43.11.1.1.8.1.3";
48
use constant oid_magenta_cur		=> ".1.3.6.1.2.1.43.11.1.1.9.1.3";
49
use constant oid_yellow_max		=> ".1.3.6.1.2.1.43.11.1.1.8.1.4";
50
use constant oid_yellow_cur		=> ".1.3.6.1.2.1.43.11.1.1.9.1.4";
51
use constant oid_tray1_max		=> ".1.3.6.1.2.1.43.8.2.1.9.1.1";
52
use constant oid_tray1_cur		=> ".1.3.6.1.2.1.43.8.2.1.10.1.1";
53
use constant oid_tray2_max		=> ".1.3.6.1.2.1.43.8.2.1.9.1.2";
54
use constant oid_tray2_cur		=> ".1.3.6.1.2.1.43.8.2.1.10.1.2";
55
use constant oid_tray3_max		=> ".1.3.6.1.2.1.43.8.2.1.9.1.3";
56
use constant oid_tray3_cur		=> ".1.3.6.1.2.1.43.8.2.1.10.1.3";
57
use constant oid_pagecount_total	=> ".1.3.6.1.2.1.43.10.2.1.4.1.1";
58
59
60
#####
61
# Config
62
###
63
if (defined $ARGV[0] and $ARGV[0] eq "config") {
64
	my ($host) = Munin::Plugin::SNMP->config_session();
65
	print "host_name $host\n" unless $host eq 'localhost';
66
	print "multigraph hpclj
67
graph_category printing
68
graph_title HP Printer Consumption Levels
69
graph_info This graph shows Consumption-Levels on HP Printers.
70
graph_vlabel %
71
graph_args --upper-limit 100 -l 0
72
graph_scale no
73
";
74
	print "black.label Black Toner Level
75
black.draw LINE2
76
black.type GAUGE
77
black.colour 000000
78
black.warning 10:
79
black.critical 3:
80
black.min 0
81
black.max 100
82
";
83
	if(oidExists(oid_cyan_max)){
84
		print "cyan.label Cyan Toner Level
85
cyan.draw LINE2
86
cyan.type GAUGE
87
cyan.colour 00FFFF
88
cyan.warning 5:
89
cyan.critical 1:
90
cyan.min 0
91
cyan.max 100
92
";
93
	}
94
	if(oidExists(oid_magenta_max)){
95
		print "magenta.label Magenta Toner Level
96
magenta.draw LINE2
97
magenta.type GAUGE
98
magenta.colour FF00FF
99
magenta.warning 5:
100
magenta.critical 1:
101
magenta.min 0
102
magenta.max 100
103
";
104
	}
105
	if(oidExists(oid_yellow_max)){
106
		print "yellow.label Yellow Toner Level
107
yellow.draw LINE2
108
yellow.type GAUGE
109
yellow.colour FFFF00
110
yellow.warning 5:
111
yellow.critical 1:
112
yellow.min 0
113
yellow.max 100
114
";
115
	}
116
	if(oidExists(oid_tray1_max)){
117
		print "tray1.label Tray1 Fill Level
118
tray1.draw LINE1
119
tray1.type GAUGE
120
tray1.colour 333333
121
tray1.min 0
122
tray1.max 100
123
";
124
	}
125
	if(oidExists(oid_tray2_max)){
126
		print "tray2.label Tray2 Fill Level
127
tray2.draw LINE1
128
tray2.type GAUGE
129
tray2.colour 666666
130
tray2.min 0
131
tray2.max 100
132
";
133
	}
134
	if(oidExists(oid_tray3_max)){
135
		print "tray3.label Tray3 Fill Level
136
tray3.draw LINE1
137
tray3.type GAUGE
138
tray3.colour 999999
139
tray3.min 0
140
tray3.max 100
141
";
142
	}
143 17f78427 Lars Kruse
144 832a58c5 Kai
	print "multigraph hpclj_pagecount
145
graph_category printing
146
graph_title HP Printer Page Counters
147
graph_info This graph shows Page-Counters for HP Printers.
148
graph_vlabel Pages
149
graph_args --base 1000 -l 0
150
";
151
	print "pagecount.label Printouts
152
pagecount.draw AREA
153
pagecount.colour 000000
154
";
155
	exit 0;
156
}
157
158
159
#####
160
# Get Values
161
###
162
print "multigraph hpclj\n";
163
printPercentageValue("black",	oid_black_cur,		oid_black_max);
164
printPercentageValue("cyan",	oid_cyan_cur,		oid_cyan_max);
165
printPercentageValue("magenta",	oid_magenta_cur,	oid_magenta_max);
166
printPercentageValue("yellow",	oid_yellow_cur,		oid_yellow_max);
167
printPercentageValue("tray1",	oid_tray1_cur,		oid_tray1_max);
168
printPercentageValue("tray2",	oid_tray2_cur,		oid_tray2_max);
169
printPercentageValue("tray3",	oid_tray3_cur,		oid_tray3_max);
170
171
print "multigraph hpclj_pagecount\n";
172
printValue("pagecount",		oid_pagecount_total);
173
174
175
#####
176
# Subroutines
177
###
178
sub printPercentageValue {
179
	if(not defined $_[0] || not defined $_[1] || not defined $_[2]) {
180
		exit 0;
181
	}
182
	my $field = $_[0];
183
	my $oid_cur = $_[1];
184
	my $oid_max = $_[2];
185 17f78427 Lars Kruse
186 832a58c5 Kai
	if(not oidExists($oid_cur) || not oidExists($oid_max)){
187
		return(0);
188
	}
189 17f78427 Lars Kruse
190 832a58c5 Kai
	my $val_max	= $session->get_single($oid_max) || 'U';
191
	my $val_cur	= $session->get_single($oid_cur);
192
	if ($val_max ne 'U') {
193
		print $field, ".value ", ($val_cur * 100 / $val_max), "\n";
194
	}
195
}
196
sub printValue {
197
	if(not defined $_[0] || not defined $_[1]) {
198
		exit 0;
199
	}
200
	my $field = $_[0];
201
	my $oid = $_[1];
202 17f78427 Lars Kruse
203 832a58c5 Kai
	if(not oidExists($oid)){
204
		return(0);
205
	}
206 17f78427 Lars Kruse
207 832a58c5 Kai
	my $val_cur	= $session->get_single($oid) || 'U';
208
	if ($val_cur ne 'U') {
209
		print $field, ".value ", $val_cur, "\n";
210
	}
211
}
212
sub oidExists {
213
	if(not defined $_[0]) {
214
		exit 0;
215
	}
216
	my $oid = $_[0];
217
	my $val = $session->get_single($oid);
218 17f78427 Lars Kruse
219 832a58c5 Kai
	if(!length $val || $val eq 'noSuchInstance' || $val eq 'U'){
220
		return(0);
221
	}else{
222
		return(1);
223
	}
224
}