Big update of Clearadm
[clearscm.git] / clearadm / clearadmscrub.pl
1 #!/usr/bin/env perl
2
3 =pod
4
5 =head1 NAME $RCSfile: clearadmscrub.pl,v $
6
7 Scrub Clearadm records
8
9 =head1 VERSION
10
11 =over
12
13 =item Author
14
15 Andrew DeFaria <Andrew@ClearSCM.com>
16
17 =item Revision
18
19 $Revision: 1.9 $
20
21 =item Created:
22
23 Sun Jan  2 19:40:28 EST 2011
24
25 =item Modified:
26
27 $Date: 2012/11/09 06:45:36 $
28
29 =back
30
31 =head1 SYNOPSIS
32
33  Usage clearadmscrub.pl: [-u|sage] [-ve|rbose] [-deb|ug]
34
35  Where:
36    -u|sage:     Displays usage
37  
38    -ve|rbose:   Be verbose
39    -deb|ug:     Output debug messages
40    
41 =head1 DESCRIPTION
42
43 This script will scrub all old records in the Clearadm database
44
45 =cut
46
47 use strict;
48 use warnings;
49
50 use FindBin;
51 use Getopt::Long;
52
53 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
54
55 use Clearadm;
56 use DateUtils;
57 use Display;
58 use TimeUtils;
59 use Utils;
60
61 my $VERSION  = '$Revision: 1.9 $';
62   ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
63
64 my $clearadm  = Clearadm->new;
65
66 my ($host, $fs);
67
68 # Main
69 GetOptions (
70   'usage'   => sub { Usage },
71   'verbose' => sub { set_verbose },
72   'debug'   => sub { set_debug },
73 ) or Usage "Invalid parameter";
74
75 Usage 'Extraneous options: ' . join ' ', @ARGV
76   if @ARGV;
77
78 # Announce ourselves
79 verbose "$FindBin::Script V$VERSION";
80
81 my ($err, $msg);
82
83 foreach my $system ($clearadm->FindSystem ($host)) {
84   ($err, $msg) = $clearadm->TrimLoadavg ($$system{name});
85   
86   if ($msg eq 'Records deleted' or $msg eq '') {
87     verbose "Scrub loadavg $$system{name}: $err $msg:";
88   } else {
89     error "#$err: $msg";
90   } # if
91   
92   foreach my $filesystem ($clearadm->FindFilesystem ($$system{name}, $fs)) {
93     ($err, $msg) = $clearadm->TrimFS ($$system{name}, $$filesystem{filesystem});
94     
95     if ($msg eq 'Records deleted' or $msg eq '') {
96       verbose "Scrub filesystem $$system{name}:$$filesystem{filesystem}: $err $msg";
97     } else {
98       error "#$err: $msg";
99     } # if
100   } # foreach
101 } # foreach
102
103 # TODO: These should be configurable
104 my $sixMonthsAgo = SubtractDays (Today2SQLDatetime, 180);
105
106 my %runlog = (
107   task    => 'Scrub',
108   started => Today2SQLDatetime,
109 );
110
111 # Scrub old alertlogs
112 ($runlog{status}, $runlog{message}) = 
113   $clearadm->DeleteAlertlog ("timestamp<='$sixMonthsAgo'");
114
115 verbose "$runlog{task} alertlog: $runlog{status} $runlog{message}";
116
117 $clearadm->AddRunlog (%runlog);
118
119 $runlog{started} = Today2SQLDatetime;
120
121 # Scrub old runlogs
122 ($runlog{status}, $runlog{message}) = 
123   $clearadm->DeleteRunlog ("started<='$sixMonthsAgo'");
124   
125 verbose "$runlog{task} runlog: $runlog{status} $runlog{message}";
126
127 $clearadm->AddRunlog (%runlog);
128
129 =pod
130
131 =head1 CONFIGURATION AND ENVIRONMENT
132
133 DEBUG: If set then $debug is set to this level.
134
135 VERBOSE: If set then $verbose is set to this level.
136
137 TRACE: If set then $trace is set to this level.
138
139 =head1 DEPENDENCIES
140
141 =head2 Perl Modules
142
143 L<FindBin>
144
145 L<Getopt::Long|Getopt::Long>
146
147 =head2 ClearSCM Perl Modules
148
149 =begin man 
150
151  Clearadm
152  DateUtils
153  Display
154  TimeUtils
155  Utils
156
157 =end man
158
159 =begin html
160
161 <blockquote>
162 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
163 <a href="http://clearscm.com/php/scm_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
164 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
165 <a href="http://clearscm.com/php/scm_man.php?file=lib/TimeUtils.pm">TimeUtils</a><br>
166 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
167 </blockquote>
168
169 =end html
170
171 =head1 BUGS AND LIMITATIONS
172
173 There are no known bugs in this script
174
175 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
176
177 =head1 LICENSE AND COPYRIGHT
178
179 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
180
181 =cut