script/drive-watch.pl untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 65 CC 3 SCAR 19.5
CC
3
Cov
0%
msg
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 7.0
1 #!/usr/local/bin/perl
2  
3 use strict;
4  
5 use Getopt::Std;
6  
7 my $interval = 5 * 60;
8  
9 my %opts;
10 getopts('dM:i:n:', \%opts);
11 if (defined($opts{'i'})) {
12 $interval = $opts{'i'};
13 }
14 my $notify = "";
15 $notify .= ",".$opts{'n'} if ($opts{'n'});
16  
17 use NBU;
18 NBU->debug($opts{'d'});
19  
20 my $master;
21 if ($opts{'M'}) {
22 $master = NBU::Host->new($opts{'M'});
23 }
24 else {
25 my @masters = NBU->masters; $master = $masters[0];
26 }
27 my @mediaManagers;
28 foreach my $server (NBU::StorageUnit->mediaServers($master)) {
29 if (NBU::Drive->populate($server)) {
30 push @mediaManagers, $server;
31 }
32 }
33  
34 sub msg {
35 my $self = shift;
36 my $state = shift;
37  
38 #
39 # Start counting down drives at one since we are about to be marked as such
40 my $down = 1;
41 my $total = 0;
42 for my $d (NBU::Drive->pool) {
43 next unless ($d->known);
44 $total++;
45 $down++ if ($d->down);
46 }
47  
48 open (PIPE, "| /usr/bin/mailx -s \"Drive ".$self->name." went $state\" $notify");
49 print PIPE "Drive ".$self->id." on ".$self->host->name." went $state, new state is ".$self->control."\n";
50 print PIPE "Its comment field read: ".$self->comment."\n";
51  
52 print PIPE "\nThere are now $down drives down out of $total\n";
53 close(PIPE);
54 }
55  
56 foreach my $d (NBU::Drive->pool) {
57 next unless $d->known;
58 $d->notifyOn("DOWN", \&msg);
59 }
60  
61 while (1) {
62 system("sleep $interval\n");
63  
64 foreach my $server (@mediaManagers) {
65 NBU::Drive->updateStatus($server);
66 }
67 }
68  
69 =head1 NAME
70  
71 drive-watch.pl - Monitor NetBackup Drive Status
72  
73 =head1 SYNOPSIS
74  
75 drive-watch.pl B<-n> <people-who-care> B<-i> <check-interval> &
76  
77 =head1 DESCRIPTION
78  
79 The tape drives in a NetBackup installation are prone to going DOWN for various and sundry
80 reasons. This script does not attempt to diagnose this situation but rather its goal is to
81 inform a set of people of such events.
82  
83 By running as a daemon the script can compare the status of each drive over time and only sent
84 its alerts out when a transition of interest occurs.
85  
86 Since a NetBackup environment can consist of many Media Managers, not all of which are active and
87 since each Media Manager may well have drives defined which are not active, drive-watch.pl will only report
88 on so-called "known" drives. The "known" attribute is assigned to drives which are:
89  
90 =over 4
91  
92 =item
93  
94 stand-alone drives referenced by a StorageUnit definition
95  
96 =item
97  
98 robotic drives housed in a robot referenced by a StorageUnit definition
99  
100 =back
101  
102 =head1 AUTHOR
103  
104 Winkeler, Paul pwinkeler@pbnj-solutions.com
105  
106 =head1 COPYRIGHT
107  
108 Copyright (C) 2002 Paul Winkeler
109  
110 =cut