Ignore:
Timestamp:
Jul 20, 2018, 9:26:28 PM (7 years ago)
Author:
g7moreau
Message:
  • Add refreshments config for the web page
File:
1 edited

Legend:

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

    r321 r322  
    1212#
    1313# apt-get install perl-modules libnagios-object-perl libhtml-parser-perl liburi-encode-perl libcolor-calc-perl libyaml-syck-perl
     14# apt-get install libdatetime-event-recurrence-perl libdatetime-set-perl
    1415
    1516use strict;
    1617use warnings;
    17 use version; our $VERSION = version->declare('0.8.10');
     18use version; our $VERSION = version->declare('0.9.0');
    1819
    1920use CGI;
     
    5152$config->{'color-downtime'}{'factor'}     ||=  0.7;
    5253$config->{'remote-action'}                ||= {};
     54$config->{'refresh'}                      ||=  0;
     55
     56sub hostmapping {
     57   my $host = shift;
     58
     59   return exists $config->{'host-mapping'}{$host} ? $config->{'host-mapping'}{$host} : $host;
     60   }
     61
     62sub downtime {
     63   my ($time_change) = @_;
     64
     65   my $now = time;
     66   return sprintf '%.1f', ($now - $time_change) / (60 * 3600);
     67   }
     68
     69sub alertcolor {
     70   my ($status, $downtime) = @_;
     71
     72   my $color = '#0000FF';
     73   $color = $STATUS_DB{$status}->{'color'} if exists $STATUS_DB{$status};
     74
     75   $downtime = $downtime - $config->{'color-downtime'}{'day-min'}; # same color first days
     76   $downtime = $config->{'color-downtime'}{'day-max'} if $downtime > $config->{'color-downtime'}{'day-max'}; # max 50 days for color
     77   $downtime =  0 if $downtime <  0;
     78
     79   my $factor = ($downtime * $config->{'color-downtime'}{'factor'}) / $config->{'color-downtime'}{'day-max'};
     80   return Color::Calc::color_light_html($color, $factor);
     81   }
     82
     83sub nosbreak {
     84   my ($str) = @_;
     85   
     86   return $str =~ s/\s/\&nbsp;/gr;
     87   }
    5388
    5489my $log = Nagios::StatusLog->new(
     
    5792   );
    5893
    59 sub hostmapping {
    60    my $host = shift;
    61 
    62    return exists $config->{'host-mapping'}{$host} ? $config->{'host-mapping'}{$host} : $host;
    63    }
    64 
    65 sub downtime {
    66    my ($time_change) = @_;
    67 
    68    my $now = time;
    69    return sprintf '%.1f', ($now - $time_change) / (60 * 3600);
    70    }
    71 
    72 sub alertcolor {
    73    my ($status, $downtime) = @_;
    74 
    75    my $color = '#0000FF';
    76    $color = $STATUS_DB{$status}->{'color'} if exists $STATUS_DB{$status};
    77 
    78    $downtime = $downtime - $config->{'color-downtime'}{'day-min'}; # same color first days
    79    $downtime = $config->{'color-downtime'}{'day-max'} if $downtime > $config->{'color-downtime'}{'day-max'}; # max 50 days for color
    80    $downtime =  0 if $downtime <  0;
    81 
    82    my $factor = ($downtime * $config->{'color-downtime'}{'factor'}) / $config->{'color-downtime'}{'day-max'};
    83    return Color::Calc::color_light_html($color, $factor);
    84    }
    85 
    86 sub nosbreak {
    87    my ($str) = @_;
    88    
    89    return $str =~ s/\s/\&nbsp;/gr;
     94# refresh configuration
     95if (exists $config->{'refreshments'}) {
     96   require DateTime::Event::Recurrence;
     97   require DateTime::SpanSet;
     98
     99   my @refreshments;
     100   SET:
     101   for my $set (@{$config->{'refreshments'}}) {
     102      my $start   = DateTime::Event::Recurrence->weekly(days => $set->{'days'}, hours => $set->{'start'});
     103      my $end     = DateTime::Event::Recurrence->weekly(days => $set->{'days'}, hours => $set->{'end'});
     104      my $spanset = DateTime::SpanSet->from_sets(start_set => $start, end_set => $end);
     105      push @refreshments, {refresh => $set->{'refresh'}, spanset => $spanset};
     106      }
     107
     108   my $now = DateTime->now();
     109   SET:
     110   for my $set (@refreshments) {
     111      next SET if not $set->{'spanset'}->contains($now);
     112 
     113      $config->{'refresh'} = $set->{'refresh'};
     114      last SET;
     115      }
    90116   }
    91117
     
    145171<head>
    146172 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     173 <meta http-equiv="Refresh"      content="$config->{'refresh'}">
    147174 <title>Nagios  Velvice</title>
    148175 <link rel="stylesheet"    type="text/css"  href="$config->{'nagios-server'}{'stylesheets'}/velvice.css">
Note: See TracChangeset for help on using the changeset viewer.