-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck_ibm_ts_tape.pl
260 lines (245 loc) · 10.4 KB
/
check_ibm_ts_tape.pl
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
#!/usr/bin/perl -w
#########################################################################
# Script: check_ibm_ts_tape.pl #
# Author: Claudio Kuenzler www.claudiokuenzler.com #
# Purpose: Monitor IBM System Storage TS Tape Libraries #
# Compatible: TS3100, TS3200,TS3310 #
# License: GPLv2 #
# History: #
# 20120316 Finished first version (my very first perl script, yay!)#
# 20120822 Tape Drive needs cleaning with different code (22) #
# 20120901 Different approach to check for cleaning state #
# 20140826 Nick Jeffrey - add support for TS3310 #
# 20140826 Move all variable declaration to top -remove excess "my"#
#########################################################################
my $version = '20140826';
#########################################################################
use strict;
use Getopt::Long;
use Net::SNMP;
use Switch;
#########################################################################
# Variable Declaration
my ($oid_base,$oid_hostname,$oid_uptime,$oid_productname,$oid_vendorname);
my ($oid_productid,$oid_serialnumber,$oid_firmware,$oid_globalstatus);
my ($oid_drivenumber,$oid_cartridges,$oid_faulterror);
my ($oid_faultseverity,$oid_faultdesc,$oid_cleanstate);
my ($oid_online_p,$oid_online_l,$oid_iodoor,$oid_driveonline,$oid_robotonline);
my $hostname = '';
my $community = '';
my $model = '';
my $type = '';
my $help = '';
#my $warn = '';
#my $crit = '';
my $session = '';
my $error = '';
my $vendorname = '';
my $productname = '';
my $productid = '';
my $serialnumber = '';
my $firmware = '';
my (@oidlist,$result);
my ($globalstatus,$faulterror,$faultdesc);
my (%value,$key,$drivestoclean);
#########################################################################
# User Input
if ( @ARGV > 0 ) {
GetOptions(
'H=s' => \$hostname,
'C:s' => \$community,
'm=s' => \$model,
't=s' => \$type,
'help' => \$help,
);
}
#########################################################################
# Check if user asks for help
if ( $help ne '' ) {
help(); exit 0;
}
# Set community if not set by user
if ( $community eq '' ) {
$community = "public";
}
# Check if model was set
if ( ($model ne "ts3100") && ($model ne "ts3200") && ($model ne "ts3310") ) {
print "Model must be either ts3100 or ts3200 or ts3310.\n";
exit 2;
}
#########################################################################
# OID Definition
if ( $model eq "ts3100" ) {
$oid_base = '.1.3.6.1.4.1.2.6.210'; #unique OID for ts3100
$oid_hostname = ".1.3.6.1.2.1.1.5.0";
$oid_uptime = ".1.3.6.1.2.1.1.3.0";
$oid_productname = "$oid_base.1.1.0";
$oid_vendorname = "$oid_base.1.3.0";
$oid_productid = "$oid_base.3.1.1.8.1";
$oid_serialnumber = "$oid_base.3.1.1.10.1";
$oid_firmware = "$oid_base.3.1.1.9.1";
$oid_globalstatus = "$oid_base.2.1.0";
$oid_drivenumber = "$oid_base.3.1.1.11.1";
$oid_cartridges = "$oid_base.3.1.1.12.1";
$oid_faulterror = "$oid_base.3.1.1.22.1";
$oid_faultseverity = "$oid_base.3.1.1.23.1";
$oid_faultdesc = "$oid_base.3.1.1.24.1";
$oid_cleanstate = "$oid_base.3.2.1.2";
}
if ( $model eq "ts3100" ) {
$oid_base = '.1.3.6.1.4.1.2.6.211'; #unique OID for ts3200
$oid_hostname = ".1.3.6.1.2.1.1.5.0";
$oid_uptime = ".1.3.6.1.2.1.1.3.0";
$oid_productname = "$oid_base.1.1.0";
$oid_vendorname = "$oid_base.1.3.0";
$oid_productid = "$oid_base.3.1.1.8.1";
$oid_serialnumber = "$oid_base.3.1.1.10.1";
$oid_firmware = "$oid_base.3.1.1.9.1";
$oid_globalstatus = "$oid_base.2.1.0";
$oid_drivenumber = "$oid_base.3.1.1.11.1";
$oid_cartridges = "$oid_base.3.1.1.12.1";
$oid_faulterror = "$oid_base.3.1.1.22.1";
$oid_faultseverity = "$oid_base.3.1.1.23.1";
$oid_faultdesc = "$oid_base.3.1.1.24.1";
$oid_cleanstate = "$oid_base.3.2.1.2";
}
if ( $model eq "ts3310" ) {
$oid_base = '.1.3.6.1.4.1.3764.1.10.10'; #unique OID for ts3310
$oid_hostname = ".1.3.6.1.2.1.1.5.0";
$oid_uptime = ".1.3.6.1.2.1.1.3.0";
$oid_productname = "$oid_base.1.10.0";
$oid_vendorname = "$oid_base.1.4.0";
$oid_productid = "$oid_base.1.7.0";
$oid_serialnumber = "$oid_base.1.5.0";
$oid_firmware = "$oid_base.1.11.0";
$oid_globalstatus = "$oid_base.1.8.0"; # libraryGlobalStatus 1=good 2=? 4=? 8=?
$oid_drivenumber = "$oid_base.3.1.1.11.1"; #not used anywhere else in this script
$oid_cartridges = "$oid_base.3.1.1.12.1"; #not used anywhere else in this script
$oid_faulterror = "$oid_base.11.1.0"; #OID not used for this model. Dummy in overallPhDriveReadinessStatus 1=online
$oid_faultseverity = "$oid_base.11.1.0"; #OID not used for this model. Dummy in overallPhDriveReadinessStatus 1=online
$oid_faultdesc = "$oid_base.11.1.0"; #OID not used for this model. Dummy in overallPhDriveReadinessStatus 1=online
$oid_cleanstate = "$oid_base.11.3.1.12"; # CleaningStatus 1=required 2=notRequired 3=immediate
#$oid_online_p = "$oid_base.14.1.0"; # physical library 1=online 0=offline
#$oid_online_l = "$oid_base.13.2.1.8"; # logical library 1=online 0=offline (may be multiple logical libraries)
#$oid_iodoor = "$oid_base.14.3.0"; # I/O station door 1=opened 2=closedAndLocked 3=closedAndUnLocked
#$oid_driveonline = "$oid_base.11.3.1.10"; # tape drives online/offline 1=online 2=offline
#$oid_robotonline = "$oid_base.14.30.2.0"; # robotic arm ready 1=ready 0=?
}
#########################################################################
# Subs
sub help {
print "check_ibm_ts_tape.pl (c) 2012 Claudio Kuenzler (published under GPL License)
Version: $version\n
Usage: ./check_ibm_ts_tape.pl -H host [-C community] -m model -t checktype\n
Options:
-H\tHostname or IP address of tape library.
-C\tSNMP community name (if not set, public will be used).
-m\tModel of the tape library. Must be either ts3100 or ts3200.
-t\tType to check. See below for valid types.
--help\tShow this help/usage.\n
Check Types:
info -> Show basic information of the tape library (hostname, serial number, etc)
status -> Checks the current status and outputs error codes if status is not ok
clean -> Checks all drives of tape library if cleaning is required\n";
}
#########################################################################
# SNMP Connection
($session,$error) = Net::SNMP->session(
-hostname => $hostname,
-community => $community,
-version => 1,
);
#########################################################################
# Plugin Checks
switch ($type) {
case "info" {
@oidlist = ($oid_hostname, $oid_productname, $oid_vendorname, $oid_productid, $oid_serialnumber, $oid_firmware);
$result = $session->get_request(-varbindlist => \@oidlist);
if (!defined($result)) {
printf("ERROR: Description table : %s.\n", $session->error);
if ($session->error =~ m/noSuchName/ || $session->error =~ m/does not exist/) {
print "Are you really sure the target host is a $model???!\n";
}
$session->close;
exit 2;
}
$hostname = $$result{$oid_hostname};
$vendorname = $$result{$oid_vendorname};
$vendorname =~ s/\s+$//;
$productname = $$result{$oid_productname};
$productid = $$result{$oid_productid};
$productid =~ s/\s+$//;
$serialnumber = $$result{$oid_serialnumber};
$firmware = $$result{$oid_firmware};
print "$hostname ($vendorname $productname) - Product-No: $productid - S/N: $serialnumber - running on Firmware $firmware\n";
exit 0;
}
case "status" {
@oidlist = ($oid_globalstatus, $oid_faulterror, $oid_faultdesc);
$result = $session->get_request(-varbindlist => \@oidlist);
if (!defined($result)) {
printf("ERROR: Description table : %s.\n", $session->error);
if ($session->error =~ m/noSuchName/ || $session->error =~ m/does not exist/) {
print "Are you really sure the target host is a $model???!\n";
}
$session->close;
exit 2;
}
$globalstatus = $$result{$oid_globalstatus};
$faulterror = $$result{$oid_faulterror};
$faultdesc = $$result{$oid_faultdesc};
if ( ($model eq "ts3100") || ($model eq "ts3200") ) {
switch ($globalstatus) {
case 1 { print "$model WARNING - Current status is: other - $faultdesc (error code: $faulterror)\n"; exit 1; }
case 2 { print "$model WARNING - Current status is: unknown - $faultdesc (error code: $faulterror)\n"; exit 1; }
case 3 { print "$model OK - Current status is: ok\n"; exit 0; }
case 4 { print "$model WARNING - Current status is: non-critical - $faultdesc (error code: $faulterror)\n"; exit 1; }
case 5 { print "$model CRITICAL - Current status is: critical - $faultdesc (error code: $faulterror)\n"; exit 2; }
case 6 { print "$model CRITICAL - Current status is: non-recoverable - $faultdesc (error code: $faulterror)\n"; exit 2; }
else { print "$model UNKNOWN - Unknown status code\n"; exit 3; }
}
}
if ( $model eq "ts3310" ) {
switch ($globalstatus) {
case 1 { print "$model OK - Current status is: ok\n"; exit 0; }
else { print "$model UNKNOWN - Unknown status code\n"; exit 3; }
}
}
}
case "clean" {
$result = $session->get_table(-baseoid => $oid_cleanstate);
if (!defined($result)) {
printf("ERROR: Description table : %s.\n", $session->error);
if ($session->error =~ m/noSuchName/ || $session->error =~ m/does not exist/) {
print "Are you really sure the target host is a $model???!\n";
}
$session->close;
exit 2;
}
%value = %{$result};
#$key;
$drivestoclean = 0;
foreach $key (keys %{$result}) {
#print "$value{$key}\n"; # debug
if ($value{$key} == 34) {
$drivestoclean = $drivestoclean + 1;
}
}
if ($drivestoclean > 0) {
print "$model WARNING - $drivestoclean tape drive needs to be cleaned\n";
exit 1;
}
else { print "$model OK - All tape drives are clean\n";
exit 0;
}
}
else {
print "Error: No type given. What do you want to check?\n";
exit 2;
}
}
#########################################################################
# Close SNMP Session
$session->close();
print "UNKNOWN - The script should have exited before this point\n";
exit 3