This repository has been archived by the owner on Mar 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
check_snmp_printer.sh
executable file
·386 lines (334 loc) · 10.1 KB
/
check_snmp_printer.sh
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#!/bin/sh
###############################################################################
# +-------------------------------------------------------------------------+
# | Copyright (C) 2007 S&L Netzwerktechnik |
# | |
# | This program is free software; you can redistribute it and/or |
# | modify it under the terms of the GNU General Public License |
# | as published by the Free Software Foundation; either version 2 |
# | of the License, or (at your option) any later version. |
# | |
# | This program is distributed in the hope that it will be useful, |
# | but WITHOUT ANY WARRANTY; without even the implied warranty of |
# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
# | GNU General Public License for more details. |
# +-------------------------------------------------------------------------+
# |Monitoring Solution: The Complete Network Monitoring Solution :) |
# +-------------------------------------------------------------------------+
# | This code is designed, written, and maintained by the Serge Mueller/ S&L|
# +-------------------------------------------------------------------------+
# | http://www.monitoring-solution.de/ |
# +-------------------------------------------------------------------------+
###############################################################################
#
# check_snmp_printer - printer/consumables monitoring plugin for Nagios
# Version: 0.2.0
#
###############################################################################
#
# CHANGE LOG
#
# 2007-05-23 - Script creation
# 2007-06-06 - Added CONSUM ALL functionality
# 2016-11-07 - remove all non sh standard and indented
#
###############################################################################
#
# COMMENTS
# The Papertray stuff may need some attention...
# Most printers' output sucks there
#
#
###############################################################################
#
# DEPENDS On
# snmpwalk - if needet change variable below
# snmpget - see above
#
###############################################################################
HOSTIP=$1
COMMUNITY=$2
SNMPGET="/usr/bin/snmpget"
SNMPWALK="/usr/bin/snmpwalk"
# checks whether dependencies are installed
fcheckdeps(){
type $SNMPGET > /dev/null 2>&1 && type $SNMPWALK > /dev/null 2>&1 || {
(>&2 echo "$SNMPGET or $SNMPWALK not found. Please make sure they are installed.")
exit 11
}
}
fmodel(){
MODEL=`$SNMPGET -v 1 -c $COMMUNITY $HOSTIP host.hrDevice.hrDeviceTable.hrDeviceEntry.hrDeviceDescr.1 2>/dev/null|cut -d " " -f4-`
echo $MODEL
exit 0
}
fmessages(){
MESSAGES=`$SNMPWALK -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.18.1.1.8|cut -d " " -f4- |tr -d "\""|tr -d "\n"`
echo $MESSAGES
exit 0
}
fpagecount(){
PC=`$SNMPGET -v 1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.10.2.1.4.1.1 2>/dev/null|cut -d " " -f4-`
echo "OK Pagecount is $PC|Pages=$PC;;;"
exit 0
}
fconsumables(){
##testfrage
if [ "$1" = "TEST" ]
then
echo "Consumables you may Monitor:"
$SNMPWALK -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.6.1 2>/dev/null |cut -d " " -f4-
#echo -e $OUTPUT
exit 0
else
###massenabfrage
if [ "$1" = "ALL" ]
then
EXITCODE=0
EXITSTRING=''
PERFDAT=''
for ID in `$SNMPWALK -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.6.1 2>/dev/null |egrep -oe '[[:digit:]]+\ ='|cut -d " " -f1`
do
NAME=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.6.1.$ID 2>/dev/null |cut -d " " -f4- |tr -d "\""`
if [ -z "$NAME" ]
then
(>&2 echo "Error OID not found,maybe your Printer does not support checking this device, call me with Option CONSUM TEST or see help")
exit 3
fi
STATUS=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.9.1.$ID 2>/dev/null |cut -d " " -f4- |tr -d "\""`
FULL=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.8.1.$ID 2>/dev/null |cut -d " " -f4- |tr -d "\""`
####debug
#echo found $ID with name $NAME , full state: $FULL , actual state: $STATUS
if [ "$FULL" -gt 0 ] && [ "$STATUS" -gt 0 ]
then
STATUS=$((STATUS * 100 / FULL))
if [ "$STATUS" -gt "30" ]
then
EXITSTRING="$EXITSTRING OK,$NAME is at $STATUS%"
PERFDAT="$PERFDAT $NAME=$STATUS;;$FULL;"
else
if [ "$STATUS" -lt "30" ] && [ "$STATUS" -gt "10" ]
then
EXITSTRING="$EXITSTRING, WARNING,$NAME is at $STATUS%"
PERFDAT="$PERFDAT $NAME=$STATUS;;$FULL;"
if [ "$EXITCODE" -lt 1 ]
then
EXITCODE=1
fi
else
if [ "$STATUS" -lt "10" ]
then
EXITSTRING="$EXITSTRING CRITICAL,$NAME is at $STATUS%"
PERFDAT="$PERFDAT $NAME=$STATUS;;$FULL;"
EXITCODE=2
fi
fi
fi
else
if [ "$STATUS" = "-3" ]
then
EXITSTRING="$EXITSTRING OK,$NAME is FULL"
else
if [ "$STATUS" = "-2" ]
then
EXITSTRING="$EXITSTRING WARNING,$NAME is at WARNING Level"
if [ "$EXITCODE" -lt 1 ]
then
EXITCODE=1
fi
else
if [ "$STATUS" = "0" ]
then
EXITSTRING="$EXITSTRING CRITICAL,$NAME is at CRITICAL Level"
EXITCODE=2
fi
fi
fi
fi
done
echo "$EXITSTRING|$PERFDAT"
exit $EXITCODE
###einzelne abfrage
else
ID=`$SNMPWALK -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.6.1 2>/dev/null |egrep -i -e "$1"|cut -d "=" -f1|cut -d "." -f8`
fi
fi
NAME=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.6.1.$ID 2>/dev/null |cut -d " " -f4- |tr -d "\""`
if [ -z "$NAME" ]
then
(>&2 echo "Error OID not found,maybe your Printer does not support checking this device, call me with Option CONSUM TEST or see help")
exit 3
fi
STATUS=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.9.1.$ID 2>/dev/null |cut -d " " -f4- |tr -d "\""`
FULL=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.8.1.$ID 2>/dev/null |cut -d " " -f4- |tr -d "\""`
if [ "$FULL" -gt 0 ] && [ "$STATUS" -gt 0 ]
then
STATUS=$((STATUS * 100 / FULL))
if [ "$STATUS" -gt "30" ]
then
echo "OK,$NAME is at $STATUS%|$NAME=$STATUS;;$FULL;"
exit 0
else
if [ "$STATUS" -lt "30" ] && [ "$STATUS" -gt "10" ]
then
echo "WARNING,$NAME is at $STATUS%|$NAME=$STATUS;;$FULL;"
exit 1
else
if [ "$STATUS" -lt "10" ]
then
echo "CRITICAL,$NAME is at $STATUS%|$NAME=$STATUS;;$FULL;"
exit 2
fi
fi
fi
else
if [ "$STATUS" = "-3" ]
then
echo "$NAME is OK"
exit 0
else
if [ "$STATUS" = "-2" ]
then
echo "$NAME is at warning level"
exit 1
else
if [ "$STATUS" = "0" ]
then
echo "$NAME is at critical level"
exit 2
fi
fi
fi
fi
}
fpaper1(){
PAPERSTATUS1=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.8.2.1.10.1.1|cut -d " " -f4- |tr -d "\""`
if [ "$PAPERSTATUS1" = "-3" ]
then
echo "TRAY1 is OK"
exit 0
else
if [ "$PAPERSTATUS1" = "-2" ]
then
echo "TRAY1 is at warning level"
exit 1
else
if [ "$PAPERSTATUS1" = "0" ]
then
echo "TRAY1 is at critical level"
exit 2
fi
fi
fi
}
fpaper2(){
PAPERSTATUS2=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.8.2.1.10.1.2|cut -d " " -f4- |tr -d "\""`
if [ "$PAPERSTATUS2" = "-3" ]
then
echo "TRAY2 is OK"
exit 0
else
if [ "$PAPERSTATUS2" = "-2" ]
then
echo "TRAY2 is at warning level"
exit 1
else
if [ "$PAPERSTATUS2" = "0" ]
then
echo "TRAY2 is at critical level"
exit 2
fi
fi
fi
}
fpaper3(){
PAPERSTATUS3=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.8.2.1.10.1.3|cut -d " " -f4- |tr -d "\""`
if [ "$PAPERSTATUS3" = "-3" ]
then
echo "TRAY3 is OK"
exit 0
else
if [ "$PAPERSTATUS3" = "-2" ]
then
echo "TRAY3 is at warning level"
exit 1
else
if [ "$PAPERSTATUS3" = "0" ]
then
exit "TRAY3 is at critical level"
exit 2
fi
fi
fi
}
ferror(){
echo "
usage is:
$0 <HOSTIP> <COMMUNITY> <CHECK>
where CHECK can be:
MESSAGES
MODEL
CONSUM TEST
CONSUM ALL
CONSUM <String>
PAPER1
PAPER2
PAPER3
PAGECOUNT
CONSUM TEST, will give you the exact Names of installed Consumables like:
\"Black Toner Cartridge HP C4191A\"
For monitoring this consumable you\'ll call me like this:
$0 <HOSTIP> <COMMUNITY> CONSUM black
The string just needs to be unique
CONSUM ALL will give you all the Stuff at once..."
}
fcheckdeps
if [ "$#" -lt 3 ]
then
ferror
exit 3
fi
if [ "$3" = "MESSAGES" ]
then
fmessages
else
if [ "$3" = "MODEL" ]
then
fmodel
else
if [ "$3" = "CONSUM" ]
then
fconsumables $4
else
if [ "$3" = "PAPER1" ]
then
fpaper1
else
if [ "$3" = "PAPER2" ]
then
fpaper2
else
if [ "$3" = "PAPER3" ]
then
fpaper3
else
if [ "$3" = "PAGECOUNT" ]
then
fpagecount
else
if [ "$3" = "TEST" ]
then
fconsumables $3
else
ferror
exit 3
fi
fi
fi
fi
fi
fi
fi
fi
(>&2 echo "UNKNOWN something went wrong while checking the stats")
exit 3