script/volume-status.pl untested

filter: Statementstmt 0.0% 0 / 80 Branchbran 0.0% 0 / 64 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 24 Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 208 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl -w
2  
3 use strict;
4  
5 use Getopt::Std;
6 use Time::Local;
7  
8 my %opts;
9 getopts('?rdclsgpuUaAfFe:m:', \%opts);
10  
11 use NBU;
12 NBU->debug($opts{'d'});
13  
14 NBU::Media->populate(1);
15 NBU::Media->loadErrors;
16  
17 print "\"".join('","',
18 "id", "pool", "group", "errors", "mounts", "limit", "expires",
19 "robot", "slot").
20 "\"\n" if ($opts{'c'});
21  
22 while (<STDIN>) {
23 next if (/^[\s]*\#/);
24  
25 chop;
26 my $mediaID = $_;
27 my $volume = NBU::Media->byID($mediaID);
28  
29 my $reportOn = 1;
30  
31 my $status = "$mediaID: ";
32 if (!defined($volume)) {
33 $status .= "? not in volume database!";
34 $volume = NBU::Media->new($mediaID);
35 $reportOn = 0 unless exists($opts{'U'});
36 }
37 else {
38 $reportOn = 0 if exists($opts{'U'});
39 }
40 {
41 $status .= sprintf("%3d", $volume->mountCount);
42 $status .= sprintf("/%3d", $volume->maxMounts) if ($volume->maxMounts);
43 $status .= " mounts: ";
44 if ($opts{'p'}) {
45 $status = $volume->pool->name.": ".$status;
46 }
47 if ($opts{'g'}) {
48 my $g = defined($volume->group) ? $volume->group : "NONE";
49 $status = $g.": ".$status;
50 }
51  
52 if (exists($opts{'m'})) {
53 if ($opts{'m'} >= 0) {
54 $reportOn &&= ($volume->mountCount >= $opts{'m'});
55 }
56 else {
57 $reportOn &&= ($volume->mountCount < -$opts{'m'});
58 }
59 }
60  
61 if ($volume->errorCount) {
62 $status .= $volume->errorCount." errors: ";
63 }
64 if (exists($opts{'e'}) && defined($volume->errorCount)) {
65 if ($opts{'e'} == 0) {
66 $reportOn &&= ($volume->errorCount == 0)
67 }
68 elsif ($opts{'e'} > 0) {
69 $reportOn &&= ($volume->errorCount >= $opts{'e'})
70 }
71 else {
72 $reportOn &&= ($volume->errorCount < -$opts{'e'})
73 }
74 }
75  
76 if ($volume->suspended) {
77 $status .= "Suspended: ";
78 }
79  
80 if ($volume->frozen) {
81 $status .= "Frozen: ";
82 }
83 $reportOn &&= $volume->frozen if (exists($opts{'f'}));
84 $reportOn &&= !$volume->frozen if (exists($opts{'F'}));
85  
86 if ($volume->robot) {
87 $status .= "in R".$volume->robot->id.".".sprintf("%03d", $volume->slot);
88 }
89 else {
90 }
91  
92 if ($volume->allocated) {
93 $status .= "Allocated to ".$volume->mmdbHost->name.": ";
94 if ($volume->expires > time) {
95 $status .= "Expires ".localtime($volume->expires).": ";
96 }
97 else {
98 $status .= "Expired ".localtime($volume->expires).": ";
99 }
100 $status .= "Retention level ".$volume->retention->level." " if ($opts{'r'});
101 }
102 $reportOn &&= $volume->allocated if (exists($opts{'a'}));
103 $reportOn &&= !$volume->allocated if (exists($opts{'A'}));
104 }
105  
106 if ($reportOn) {
107 if ($opts{'c'}) {
108 print "\"".join('","', $volume->id, $volume->pool->name, $volume->group,
109 $volume->errorCount, $volume->mountCount, $volume->maxMounts,
110 $volume->allocated ? substr(localtime($volume->expires), 4) : "",
111 $volume->robot ? $volume->robot->id : "",
112 $volume->robot ? $volume->slot : "",
113 ).
114 "\"\n";
115 }
116 else {
117 print "$status\n";
118 if ($opts{'l'} && $volume->allocated) {
119 my $n = 1;
120 foreach my $fragment ($volume->tableOfContents) {
121 printf(" %3u:", $n);
122  
123 my $image = $fragment->image;
124 print "Fragment ".$fragment->id." of ".$image->class->name." from ".$image->client->name.": ";
125 print "Expires ".localtime($image->expires)."\n";
126  
127 $n++;
128 }
129 }
130 }
131 }
132  
133 if ($opts{'s'} && ($volume->errorCount > 1)) {
134 $volume->freeze;
135 }
136 }
137  
138 =head1 NAME
139  
140 volume-status.pl - Volume attribute analysis tool
141  
142 =head1 SYNOPSIS
143  
144 volume-status.pl [-c] [-pgr] [-lsU] [-fF] [-aA] [-e error-threshold] [-m mount-threshold]
145  
146 =head1 DESCRIPTION
147  
148 For each volume label provided on standard input, subject to numerous options, the
149 following information is printed on STDOUT:
150  
151 =over 4
152  
153 =item volume label
154  
155 =item mount count
156  
157 =item volume pool only if B<-p> is set
158  
159 =item volume group only if B<-g> is set
160  
161 =item error count (if non-zero)
162  
163 The error count assigned to a volume is simply read from the file /usr/local/etc/media-errors.csv;
164 it is up to the local system administrators to gather the output of the tool L<volstats.pl|volstats.pl> from
165 each media server and concatenate the data-sets into the above mentioned file.
166  
167 =item suspended or frozen status
168  
169 =item robot number if the volume is currently in a robot
170  
171 =back
172  
173 The following information only applies to volumes that are currently in use:
174  
175 =over 4
176  
177 =item expiration status
178  
179 =item retention level only if B<-r> is set
180  
181 =back
182  
183 =head1 SEE ALSO
184  
185 =over 4
186  
187 =item L<volume-list.pl|volume-list.pl>, L<toc.pl|toc.pl>
188  
189 =back
190  
191 =head1 AUTHOR
192  
193 Winkeler, Paul pwinkeler@pbnj-solutions.com
194  
195 =head1 COPYRIGHT
196  
197 Copyright (C) 2002 Paul Winkeler
198  
199 =cut