Removed /usr/local from CDPATH
[clearscm.git] / clearadm / processalert.cgi
1 #!/usr/local/bin/perl
2
3 =pod
4
5 =head1 NAME $RCSfile: processalert.cgi,v $
6
7 Process an alert
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.3 $
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:51:54 $
28
29 =back
30
31 =head1 SYNOPSIS
32
33  Usage processalert.cgi: [-u|sage] [-ve|rbose] [-d|ebug]
34                          action=[Add|Delete|Edit|Post] alert=<alertname>
35
36  Where:
37    -u|sage:   Displays usage
38    -ve|rbose: Be verbose
39    -d|ebug:   Output debug messages
40    
41    action:    Specifies to add, delete, edit or post an alert
42    alert:     Name of alert to delete or edit
43
44 =head2 DESCRIPTION
45
46 This script adds, deletes, edits or posts an alert
47
48 =cut
49
50 use strict;
51 use warnings;
52
53 use FindBin;
54 use Getopt::Long;
55 use CGI qw (:standard :cgi-lib *table start_Tr end_Tr);
56 use CGI::Carp 'fatalsToBrowser';
57
58 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
59
60 use Clearadm;
61 use ClearadmWeb;
62 use Display;
63 use Utils;
64
65 my $VERSION  = '$Revision: 1.3 $';
66   ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
67   
68 my $clearadm;
69
70 # Main
71 GetOptions (
72   usage      => sub { Usage },
73   verbose    => sub { set_verbose },
74   debug      => sub { set_debug },
75 ) or Usage 'Invalid parameter';
76
77 # Announce ourselves
78 verbose "$FindBin::Script v$VERSION";
79
80 $clearadm = Clearadm->new;
81
82 my %opts = Vars;
83
84 my $title = 'Alerts';
85
86 heading $title;
87
88 unless ($opts{'delete.x'} or $opts{'edit.x'} or $opts{action}) {
89   displayError 'Action not defined!';
90   exit 1;
91 } # unless
92
93 unless ($opts{action} eq 'Add') {
94   unless ($opts{name}) {
95     displayError 'Alert not defined!';
96     exit 1;
97   } # unless
98 } # unless
99
100 my ($err, $msg);
101
102 if ($opts{action} eq 'Add') {
103   display h1 {class => 'center'}, 'Add Alert';
104   editAlert; 
105 } elsif ($opts{'delete.x'}) {
106   ($err, $msg) = $clearadm->DeleteAlert ($opts{name});
107
108   if ($msg !~ /Records deleted/) {
109     displayError "Unable to delete alert $opts{name}\n$msg";
110   } else {
111     display h1 {class => 'center'}, $title;
112     display h3 {class => 'center'}, "Alert '$opts{name}' deleted";
113     
114     displayAlert;
115   } # if
116 } elsif ($opts{'edit.x'}) {
117   display h1 {class => 'center'}, 'Edit Alert: ', $opts{name};
118   editAlert ($opts{name});
119 } elsif ($opts{action} eq 'Post') {
120   delete $opts{action};
121   
122   my %system = $clearadm->GetAlert ($opts{name});
123   
124   if (%system or $opts{oldname}) {
125     my $name = delete $opts{oldname};
126     
127     $name ||= $opts{name};
128     
129     ($err, $msg) = $clearadm->UpdateAlert ($name, %opts);
130
131     if ($err) {
132       displayError "$msg (Status: $err)";
133     } else {
134       display h1 {class => 'center'}, $title;
135       display h3 {class => 'center'}, "Alert '$opts{name}' updated";
136     
137       displayAlert;
138     } # if
139   } else {
140     ($err, $msg) = $clearadm->AddAlert (%opts);
141
142     if ($err) {
143       displayError "$msg (Status: $err)";
144     } else {
145      
146       display h1 {class => 'center'}, $title;
147       display h3 {class => 'center'}, "Alert '$opts{name}' added";
148     
149       displayAlert;
150     } # if
151   } # if
152 } else {
153   displayError "Unknown action - $opts{action}";
154 } # if
155
156 footing;
157
158 =pod
159
160 =head1 CONFIGURATION AND ENVIRONMENT
161
162 DEBUG: If set then $debug is set to this level.
163
164 VERBOSE: If set then $verbose is set to this level.
165
166 TRACE: If set then $trace is set to this level.
167
168 =head1 DEPENDENCIES
169
170 =head2 Perl Modules
171
172 L<CGI>
173
174 L<CGI::Carp|CGI::Carp>
175
176 L<FindBin>
177
178 L<Getopt::Long|Getopt::Long>
179
180 =head2 ClearSCM Perl Modules
181
182 =begin man 
183
184  Clearadm
185  ClearadmWeb
186  Display
187  Utils
188
189 =end man
190
191 =begin html
192
193 <blockquote>
194 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
195 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/ClearadmWeb.pm">ClearadmWeb</a><br>
196 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
197 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
198 </blockquote>
199
200 =end html
201
202 =head1 BUGS AND LIMITATIONS
203
204 There are no known bugs in this script
205
206 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
207
208 =head1 LICENSE AND COPYRIGHT
209
210 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
211
212 =cut