VBTK/Wrapper/DiskFree.pm untested

filter: Statementstmt 0.0% 0 / 77 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 112 CC 5 SCAR 18.9
CC
5
Cov
0%
new
12.0
addVBObj
12.0
BEGIN
2.0
CRAP 6.6
1 #############################################################################
2 #
3 # NOTE: This file under revision control using RCS
4 # Any changes made without RCS will be lost
5 #
6 # $Source: /usr/local/cvsroot/vbtk/VBTK/Wrapper/DiskFree.pm,v $
7 # $Revision: 1.10 $
8 # $Date: 2002/03/04 20:53:08 $
9 # $Author: bhenry $
10 # $Locker: $
11 # $State: Exp $
12 #
13 # Purpose: A an extension of VBTK::Wrapper used to monitor disk
14 # space on unix systems.
15 #
16 # Depends on: VBTK::Common, VBTK::Wrapper
17 #
18 # Copyright (C) 1996 - 2002 Brent Henry
19 #
20 # This program is free software; you can redistribute it and/or
21 # modify it under the terms of version 2 of the GNU General Public
22 # License as published by the Free Software Foundation available at:
23 # http://www.gnu.org/copyleft/gpl.html
24 #
25 # This program is distributed in the hope that it will be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 # GNU General Public License for more details.
29 #
30 #############################################################################
31 #
32 #
33 # REVISION HISTORY:
34 #
35 # $Log: DiskFree.pm,v $
36 # Revision 1.10 2002/03/04 20:53:08 bhenry
37 # *** empty log message ***
38 #
39 # Revision 1.9 2002/03/04 16:49:10 bhenry
40 # Changed requirement back to perl 5.6.0
41 #
42 # Revision 1.8 2002/03/02 00:53:56 bhenry
43 # Documentation updates
44 #
45 # Revision 1.7 2002/02/13 08:01:57 bhenry
46 # *** empty log message ***
47 #
48 # Revision 1.6 2002/02/13 07:36:14 bhenry
49 # Disabled RrdLogRecovery and removed use of @log
50 #
51  
52 package VBTK::Wrapper::DiskFree;
53  
54 use 5.6.0;
55 use strict;
56 use warnings;
57 # I like using undef as a value so I'm turning off the uninitialized warnings
58 no warnings qw(uninitialized);
59  
60 use VBTK::Common;
61 use VBTK::Wrapper;
62 use VBTK::Parser;
63  
64 # Inherit methods from VBTK::Wrapper;
65 our @ISA=qw(VBTK::Wrapper);
66  
67 our $VERBOSE = $ENV{VERBOSE};
68  
69 #-------------------------------------------------------------------------------
70 # Function: new
71 # Description: Object constructor. Allocates memory for all class members
72 # Input Parms:
73 # Output Parms: Pointer to class
74 #-------------------------------------------------------------------------------
75 sub new
76 {
77 my $type = shift;
78 my $self = {};
79 bless $self, $type;
80  
81 # Store all passed input name pairs in the object
82 $self->set(@_);
83  
84 # Setup defaults
85 my $stdHeader =
86 [ 'Time Mount MB Used Avail Pct',
87 '------------------ -------------------------- ------ ------ ------ ----' ];
88 my $stdDetail =
89 [ '@<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>> @>>>>> @>>>>> @>>>',
90 '$time, $data[5], int($data[1]/1024), int($data[2]/1024), int($data[3]/1024), $data[4]' ];
91  
92 # Setup a hash of default parameters
93 my $defaultParms = {
94 Interval => 300,
95 Execute => "df -k 2>&1",
96 SourceList => undef,
97 VBServerURI => $::VBURI,
98 VBHeader => $stdHeader,
99 VBDetail => $stdDetail,
100 LogFile => undef,
101 LogHeader => $stdHeader,
102 LogDetail => $stdDetail,
103 RotateLogAt => undef,
104 RotateLogOnEOF => undef,
105 Split => '[\s\%]+',
106 Filter => '^/dev|^[A-Za-z]:\s+',
107 Ignore => '/cdrom',
108 SkipLines => undef,
109 Timeout => 60,
110 TimeoutStatus => 'Fail',
111 Follow => undef,
112 FollowTimeout => undef,
113 FollowHeartbeat => undef,
114 NonZeroExitStatus => 'Warn',
115 DebugHeader => 'df'
116 };
117  
118 # Run a validation on the passed parms, using the default parms
119 $self->validateParms($defaultParms) || &fatal("Exiting");
120  
121 # Check to see if 'df' is executable
122 if($self->{Execute} =~ /^\s*(\S+).*\|\s*$/)
123 {
124 my $progName = $1;
125 unless (-x $progName)
126 {
127 &log("Can't execute '$progName', skipping");
128 return undef;
129 }
130 }
131  
132 # Initialize a wrapper object.
133 $self->SUPER::new() || return undef;
134  
135 # Store the defaults for later
136 $self->{defaultParms} = $defaultParms;
137  
138 ($self);
139 }
140  
141 #-------------------------------------------------------------------------------
142 # Function: addVBObj
143 # Description: Add a VB object to the wrapper object.
144 # Input Parms:
145 # Output Parms: None
146 #-------------------------------------------------------------------------------
147 sub addVBObj
148 {
149 my $self = shift;
150 my $Interval = $self->{Interval};
151 my %args = @_;
152  
153 my $expireAfterSec = int($Interval * 3);
154 my $description = qq(
155 This object uses the 'df' command to monitor the disk utilization
156 on $::HOST. It will set the status to 'Warning' or 'Failed' based on the
157 amount of free disk space on the local filesystems.
158 );
159  
160 # Setup a hash of default rules to be returned
161 my $defaultRules = {
162 VBObjName => ".$::HOST.diskfree",
163 TextHistoryLimit => 50,
164 ReverseText => 1,
165 Rules => {
166 '($data[4] > 90)' => 'Warn',
167 '($data[4] > 95)' => 'Fail' },
168 Requirements => undef,
169 StatusHistoryLimit => 30,
170 StatusChangeActions => undef,
171 StatusUpgradeRules => undef,
172 ExpireAfter => "$expireAfterSec seconds",
173 Description => $description,
174 BaselineDiffStatus => undef,
175 RrdTimeCol => undef,
176 RrdColumns => [ 'int($data[4])' ],
177 RrdFilter => undef,
178 RrdMin => 0,
179 RrdMax => undef,
180 RrdXFF => undef,
181 RrdCF => 'MAX',
182 RrdDST => undef,
183 };
184  
185  
186 # Run the validation
187 &validateParms(\%args,$defaultRules) || &fatal("Exiting");
188  
189 my ($row,$fsMount,$objName,@data,$result,$vbObj);
190  
191 # Clone the wrapper object and run the clone once so we can get a look at the
192 # output.
193 my $clone = $self->dclone;
194 $clone->set(Interval => undef);
195 &VBTK::runAll($clone);
196 my $lastRows = $clone->getLastRows;
197  
198 # Make sure we got some data back
199 if (@{$lastRows} < 1)
200 {
201 &error("Can't setup objects for VBTK::Wrapper::Diskfree, because no data " .
202 "was returned from call to $self->{Execute}");
203 return undef;
204 }
205  
206 # Store the base objectname so we can add to it
207 my $baseObjName = $args{VBObjName};
208  
209 my (@dataSourceList,@labels);
210  
211 # Create one VB object for each filesystem
212 foreach $row (@{$lastRows})
213 {
214 # Get the mount point
215 $fsMount = $objName = $row->[5];
216  
217 # Convert all the '/' to '-' so we don't have any '/' in the object name
218 $objName =~ s:^/::g;
219 $objName =~ s:/:-:g;
220 $objName = 'root' if ($objName eq '');
221  
222 # Override parms which vary between objects
223 $args{VBObjName} = "$baseObjName.$objName";
224 $args{Filter} = $args{RrdFilter} = "\$data[5] eq '$fsMount'";
225  
226 # Add the rule
227 $vbObj = $self->SUPER::addVBObj(%args) || return undef;
228  
229 # Now Define what graphs will show up with this object
230 $vbObj->addGraphGroup (
231 GroupNumber => 1,
232 DataSourceList => undef,
233 Labels => 'pct-utilization',
234 Title => "Disk Utilization on $::HOST, $fsMount",
235 CF => 'MAX',
236 );
237  
238 # Store some values to be used in graphGroup 2
239 push(@dataSourceList,"$baseObjName.$objName:0");
240 push(@labels,"$fsMount");
241 }
242  
243 # Now make an 'addGraphGroup' call to the wrapper object. This will pass
244 # along this graph definition to all the VB objects associated with it.
245 $self->addGraphGroup (
246 GroupNumber => 2,
247 DataSourceList => join(',',@dataSourceList),
248 Labels => join(',',@labels),
249 Title => "Disk Utilization on $::HOST",
250 CF => 'MAX'
251 );
252  
253 $self->{defaultRules} = $defaultRules;
254  
255 (0);
256 }
257  
258 1;
259 __END__