Changeset 245
- Timestamp:
- Jun 25, 2018, 10:30:10 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nagios-velvice/velvice.cgi
r244 r245 10 10 # Possible command http://old.nagios.org/developerinfo/externalcommands/commandlist.php 11 11 # 12 # apt-get install libnagios-object-perl libhtml-parser-perl perl-modules liburi-encode-perl libcolor-calc-perl libyaml-syck-perl libhash-merge-perl12 # apt-get install libnagios-object-perl libhtml-parser-perl perl-modules liburi-encode-perl libcolor-calc-perl libyaml-syck-perl 13 13 14 14 use strict; … … 22 22 use Color::Calc (); 23 23 use YAML::Syck; 24 #use Hash::Merge;25 24 26 25 my $config = {}; … … 35 34 $config->{'downtime'}{'max'} ||= 50; 36 35 $config->{'downtime'}{'factor'} ||= 0.7; 36 $config->{'service'} ||= {}; 37 37 38 38 my $query = CGI->new(); … … 157 157 my %sshdown = (); 158 158 my @aptuptodate = (); 159 my %cmdafter = (); 160 my $after; 161 159 162 my $current_host = ''; 160 163 $htmlpage .= "<table border=\"1\">\n"; … … 162 165 my $hostname = $srv->host_name; 163 166 my $service = $srv->service_description; 164 my $ level= $srv->status;167 my $status = $srv->status; 165 168 my $downtime = downtime($srv->last_state_change); 166 169 my $output = HTML::Entities::encode($srv->plugin_output); 167 170 $output =~ s/^[A-Z_\s]+?[:-]//; 168 171 169 my $color = $ leveleq 'CRITICAL' ? '#F88888' : '#FFFF00';172 my $color = $status eq 'CRITICAL' ? '#F88888' : '#FFFF00'; 170 173 $color = alertcolor($color, $downtime); 171 174 $htmlpage .= " <tr style='background:$color;'>\n"; … … 174 177 $htmlpage .= " <td rowspan='$hostcount{$hostname}' style='vertical-align:middle;'><a href=\"$config->{'status-cgi'}?host=$hostname\">$hostname</a></td>\n"; 175 178 } 176 if ($service eq 'APT UPTODATE') { 177 $htmlpage .= " <td><b>$service</b></td>\n"; 178 } 179 else { 180 $htmlpage .= " <td>$service</td>\n"; 181 } 182 $htmlpage .= " <td>$level</td>\n"; 179 180 my $bold; 181 for my $srv_name (keys %{$config->{'service'}}) { 182 my $srv_regex = $config->{'service'}{$srv_name}{'regex'}; 183 $bold++ if $service =~ m/$srv_regex/ and $config->{'service'}{$srv_name}{'style'} eq 'bold'; 184 } 185 $htmlpage .= " <td>"; 186 $htmlpage .= "<b>" if $bold; 187 $htmlpage .= "$service"; 188 $htmlpage .= "</b>" if $bold; 189 $htmlpage .= "</td>\n"; 190 191 $htmlpage .= " <td>$status</td>\n"; 183 192 $htmlpage .= " <td style='max-width:60%;'><small>$output"; 184 193 185 194 $sshdown{$hostname}++ if $service eq 'SSH'; 186 195 187 # or ($check =~ m/apt/i and $service eq 'APT UPTODATE')188 196 if (($check =~ m/all/i) 189 197 or ($check =~ m/^$service$/i) 190 or ($check =~ m/critical/i and $ leveleq 'CRITICAL')191 or ($check =~ m/warning/i and $ leveleq 'WARNING')192 or ($check =~ m/pending/i and $ leveleq 'PENDING')198 or ($check =~ m/critical/i and $status eq 'CRITICAL') 199 or ($check =~ m/warning/i and $status eq 'WARNING') 200 or ($check =~ m/pending/i and $status eq 'PENDING') 193 201 ) { 194 202 $now++; … … 205 213 206 214 push @aptuptodate, $hostname if $service eq 'APT UPTODATE'; 207 push @oomkiller, $hostname if $service eq 'OOM Killer' and $level ne 'PENDING'; 215 push @oomkiller, $hostname if $service eq 'OOM Killer' and $status ne 'PENDING'; 216 for my $srv_name (keys %{$config->{'service'}}) { 217 my $srv_regex = $config->{'service'}{$srv_name}{'regex'}; 218 my $srv_status = $config->{'service'}{$srv_name}{'status'}; 219 if ($service =~ m/$srv_regex/ and ($srv_status eq 'ALL' or $status =~ m/$srv_status/)) { 220 $cmdafter{$srv_name} ||= []; 221 push @{$cmdafter{$srv_name}}, $hostname; 222 $after++; 223 } 224 } 208 225 209 226 $htmlpage .= "</small></td>\n"; … … 236 253 } 237 254 238 if (@oomkiller or @aptuptodate ) {255 if (@oomkiller or @aptuptodate or $after) { 239 256 require Nagios::Object::Config; 240 257 my $parser = Nagios::Object::Config->new(); 241 258 $parser->parse("/var/cache/nagios3/objects.cache"); 259 260 for my $srv_name (keys %cmdafter) { 261 my @action = grep !exists $sshdown{$_}, @{$cmdafter{$srv_name}}; 262 if (@action) { 263 $htmlpage .= "<h2>Action: $srv_name</h2>\n"; 264 $htmlpage .= "<pre>\n"; 265 my $remote_action = $config->{'service'}{$srv_name}{'command'}; 266 $remote_action = $config->{'service'}{$srv_name}{'command-one'} if @action == 1; 267 my @hosts; 268 for my $host (@action) { 269 my $object = $parser->find_object("$host", "Nagios::Host"); 270 push @hosts, hostmapping($object->address =~ s/\..*$//r); 271 } 272 my $hosts_list = join ' ', @hosts; 273 $htmlpage .= $remote_action =~ s{\%m}{$hosts_list}r; 274 $htmlpage .= "</pre>\n"; 275 } 276 } 242 277 243 278 @oomkiller = grep !exists $sshdown{$_}, @oomkiller;
Note: See TracChangeset
for help on using the changeset viewer.