Removed /usr/local from CDPATH
[clearscm.git] / clearadm / systems.cgi
1 #!/usr/local/bin/perl
2
3 =pod
4
5 =head1 NAME $RCSfile: systems.cgi,v $
6
7 Systems
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.15 $
20
21 =item Created:
22
23 Mon Oct 25 11:10:47 PDT 2008
24
25 =item Modified:
26
27 $Date: 2011/02/14 14:54:59 $
28
29 =back
30
31 =head1 SYNOPSIS
32
33  Usage systems.cgi: [-u|sage] [-ve|rbose] [-d|ebug]
34
35  Where:
36    -u|sage:               Displays usage
37    -v|erbose:             Be verbose
38    -d|ebug:               Output debug messages
39
40 =head2 DESCRIPTION
41
42 This script displays all known systems
43
44 =cut
45
46 use strict;
47 use warnings;
48
49 use FindBin;
50 use Getopt::Long;
51 use CGI qw(:standard :cgi-lib *table start_Tr end_Tr start_td end_td);
52 use CGI::Carp 'fatalsToBrowser';
53
54 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
55
56 use Clearadm;
57 use ClearadmWeb;
58 use Display;
59 use Utils;
60
61 my $VERSION  = '$Revision: 1.15 $';
62   ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
63   
64 my $subtitle = 'Systems Status: All Systems';
65
66 my $clearadm;
67
68 sub DisplaySystems() {
69   display start_table {cellspacing => 1, class => 'main'};
70   
71   display start_Tr;
72     display th {class => 'labelCentered'}, 'Action';
73     display th {class => 'labelCentered'}, 'Name';
74     display th {class => 'labelCentered'}, 'Alias';
75     display th {class => 'labelCentered'}, 'Admin';
76     display th {class => 'labelCentered'}, 'Type';
77     display th {class => 'labelCentered'}, 'Last Contacted';
78     display th {class => 'labelCentered'}, 'Current load';
79     display th {class => 'labelCentered'}, 'Threshold';
80     display th {class => 'labelCentered'}, 'Load Avg';
81   display end_Tr;
82   
83   for ($clearadm->FindSystem) {
84     my %system = %{$_};
85   
86     $system{alias}  = setField $system{alias},  'N/A';
87     $system{region} = setField $system{region}, 'N/A';
88
89     my $admin = ($system{email})
90               ? a {href => "mailto:$system{email}"}, $system{admin}
91               : $system{admin};
92   
93     my $alias = ($system{alias} !~ 'N/A')
94               ? a {
95                   href => "systemdetails.cgi?system=$system{name}"
96                 }, $system{alias}
97               : $system{alias};
98       
99     my %load = $clearadm->GetLatestLoadavg ($system{name});
100
101     $load{loadavg}   ||= 0;
102     $load{timestamp} ||= 'unknown';
103     
104     my $class         = $load{loadavg} < $system{loadavgThreshold} 
105                       ? 'data'
106                       : 'dataAlert';
107     my $classRight    = $load{loadavg} < $system{loadavgThreshold} 
108                       ? 'dataRight'
109                       : 'dataRightAlert';
110     my $classRightTop = $load{loadavg} < $system{loadavgThreshold}
111                       ? 'dataRightTop'
112                       : 'dataRightAlertTop';                      
113
114     display start_Tr;
115       display start_td {class => 'data'};
116
117       my $areYouSure = 'Are you sure you want to delete this system?\n'
118                      . 'Doing so will remove all records related to '
119                      . $system{name}
120                      . '\nincluding filesystem records and history as well as '
121                      . 'loadavg history.';
122   
123       display start_form {
124         method => 'post',
125         action => "processsystem.cgi",
126       };
127         
128       display input {
129         name  => 'name',
130         type  => 'hidden',
131         value => $system{name},
132       };
133         
134       display input {
135         name    => 'delete',
136         type    => 'image',
137         src     => 'delete.png',
138         alt     => 'Delete',
139         title   => 'Delete',
140         value   => 'Delete',
141         onclick => "return AreYouSure ('$areYouSure');"
142       };
143       display input {
144         name    => 'edit',
145         type    => 'image',
146         src     => 'edit.png',
147         alt     => 'Edit',
148         title   => 'Edit',
149         value   => 'Edit',
150       };
151       display checkbox {
152         disabled => 'disabled',
153         checked  => $system{active} eq 'true' ? 1 : 0,
154       };    
155           
156       if ($system{notification}) {
157         display a {href => "alertlog.cgi?system=$system{name}"}, img {
158           src    => 'alert.png',
159           border => 0,
160           alt    => 'Alert!',
161           title  => 'This system has alerts', 
162         };
163       } # if
164                       
165       display end_form;
166        
167       display end_td;    
168       display td {class => $class},
169         a {href => "systemdetails.cgi?system=$system{name}"}, $system{name};
170       display td {class => $class}, $alias;
171       display td {class => $class}, $admin;
172       display td {class => $class}, $system{type};
173       
174       my $lastheardfromClass = 'dataCentered';
175       my $lastheardfromData  = $system{lastheardfrom};
176   
177       unless ($clearadm->SystemAlive(%system)) {
178         $lastheardfromClass = 'dataCenteredAlert';
179         $lastheardfromData  = a {
180           href  => "alertlog.cgi?system=$system{name}",
181           class => 'alert',
182           title => "Have not heard from $system{name} for a while"
183         }, $system{lastheardfrom};
184         $system{notification} = 'Heartbeat';
185       } # unless
186       
187       display td {class => $lastheardfromClass}, "$lastheardfromData ",
188         font {class => 'dim' }, "<br>Up: $load{uptime}";
189       display td {class => $classRightTop}, "$load{loadavg} ",
190         font {class => 'dim' }, "<br>$load{timestamp}";
191       display td {class => $classRightTop}, $system{loadavgThreshold};
192
193       my $image = $system{loadavgsmall}
194         ? "data:image/png;base64,$system{loadavgsmall}"
195         : "plotloadavg.cgi?system=$system{name}&tiny=1";
196
197       display td {class => $class}, 
198         a {
199           href => 
200             "plot.cgi?type=loadavg&system=$system{name}&scaling=Hour&points=24"
201         }, img {
202           src    => $image,
203           border => 0,
204         };
205     display end_Tr;
206   } # for
207
208   display end_table;
209   
210   display p {class => 'center'}, a {
211     href => 'processsystem.cgi?action=Add',
212   }, 'New system', img {
213     src    => 'add.png',
214     border => 0,
215   };
216   
217   return;
218 } # DisplaySystems
219
220 # Main
221 GetOptions(
222   usage   => sub { Usage },
223   verbose => sub { set_verbose },
224   debug   => sub { set_debug },
225 ) or Usage 'Invalid parameter';
226
227 # Announce ourselves
228 verbose "$FindBin::Script v$VERSION";
229
230 $clearadm = Clearadm->new;
231
232 heading $subtitle;
233
234 display h1 {class => 'center'}, $subtitle;
235
236 DisplaySystems;
237
238 footing;
239
240 =pod
241
242 =head1 CONFIGURATION AND ENVIRONMENT
243
244 DEBUG: If set then $debug is set to this level.
245
246 VERBOSE: If set then $verbose is set to this level.
247
248 TRACE: If set then $trace is set to this level.
249
250 =head1 DEPENDENCIES
251
252 =head2 Perl Modules
253
254 L<CGI>
255
256 L<CGI::Carp|CGI::Carp>
257
258 L<FindBin>
259
260 L<Getopt::Long|Getopt::Long>
261
262 =head2 ClearSCM Perl Modules
263
264 =begin man 
265
266  Clearadm
267  ClearadmWeb
268  Display
269  Utils
270
271 =end man
272
273 =begin html
274
275 <blockquote>
276 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
277 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/ClearadmWeb.pm">ClearadmWeb</a><br>
278 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
279 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
280 </blockquote>
281
282 =end html
283
284 =head1 BUGS AND LIMITATIONS
285
286 There are no known bugs in this script
287
288 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
289
290 =head1 LICENSE AND COPYRIGHT
291
292 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
293
294 =cut