Changeset 319


Ignore:
Timestamp:
Jul 20, 2018, 12:24:13 PM (6 years ago)
Author:
g7moreau
Message:
  • Master color if multiple alert on one host
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/nagios-velvice/velvice.cgi

    r293 r319  
    1515use strict;
    1616use warnings;
    17 use version; our $VERSION = version->declare('0.8.9');
     17use version; our $VERSION = version->declare('0.8.10');
    1818
    1919use CGI;
     
    9898      }}
    9999
     100   SRV:
    100101   for my $srv ($log->list_services_on_host($host)) {
    101       if ($log->service($host, $srv)->status ne 'OK') {
    102          push @serviceproblems, $log->service($host, $srv);
    103          $hostcount{$host}++;
     102      my $status = $log->service($host, $srv)->status;
     103
     104      next SRV if $status eq 'OK';
     105
     106      push @serviceproblems, $log->service($host, $srv);
     107   
     108      my $downtime = downtime($log->service($host, $srv)->last_state_change);
     109      my $color    = $status eq 'CRITICAL' ? '#F88888' : '#FFFF00';
     110      $color = alertcolor($color, $downtime);
     111
     112      my %status_db = (
     113         CRITICAL => 3,
     114         WARNING  => 2,
     115         PENDING  => 1,
     116         );
     117
     118      my $status_id = 0;
     119      $status_id = $status_db{$status} if exists $status_db{$status};
     120
     121      #$hostcount{$host}++;
     122      $hostcount{$host} ||= {count => 0, color => $color, status_id => $status_id, downtime => $downtime};
     123      $hostcount{$host}->{'count'}++;
     124      if (($status_id >= $hostcount{$host}->{'status_id'}) and ($downtime < $hostcount{$host}->{'downtime'})) {
     125         $hostcount{$host}->{'downtime'}  = $downtime;
     126         $hostcount{$host}->{'status_id'} = $status_id;
     127         $hostcount{$host}->{'color'}     = $color;
    104128         }
    105129      }
     
    182206      $htmlpage .= " <tr>\n";
    183207      if ($hostname ne $current_host) {
    184          $current_host = $hostname;
    185          $htmlpage .= "  <td $stylecolor rowspan='$hostcount{$hostname}'>"
     208         $current_host  = $hostname;
     209         my $rowspan    = $hostcount{$hostname}->{'count'};
     210         my $rowcolor   = "style='background:" . $hostcount{$hostname}->{'color'} . ";'";
     211         $htmlpage .= "  <td $rowcolor rowspan='$rowspan'>"
    186212            . "<a href=\"$cgi_script_name?check=" . uri_encode($hostname) . '">&#8623;</a></td>' . "\n";
    187          $htmlpage .= "  <td $stylecolor class='hoop' rowspan='$hostcount{$hostname}'>"
     213         $htmlpage .= "  <td $rowcolor class='hoop' rowspan='$rowspan'>"
    188214            . "<a href=\"$config->{'nagios-server'}{'status-cgi'}?host=" . uri_encode($hostname) . "\">$hostname</a></td>\n";
    189215         }
Note: See TracChangeset for help on using the changeset viewer.