Changeset 322


Ignore:
Timestamp:
Jul 20, 2018, 9:26:28 PM (6 years ago)
Author:
g7moreau
Message:
  • Add refreshments config for the web page
Location:
trunk/nagios-velvice
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/nagios-velvice/make-package-debian

    r263 r322  
    4343Tag: implemented-in::perl, interface::commandline, role::program
    4444Priority: optional
    45 Depends: perl, perl-base, perl-modules, libnagios-object-perl, libhtml-parser-perl, liburi-encode-perl, libcolor-calc-perl, libyaml-syck-perl
     45Depends: perl, perl-base, perl-modules, libnagios-object-perl, libhtml-parser-perl, liburi-encode-perl, libcolor-calc-perl, libyaml-syck-perl, libdatetime-event-recurrence-perl, libdatetime-set-perl
    4646Suggests: libyaml-shell-perl | yamllint, nagios3, nagios3-cgi
    4747Architecture: all
  • 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">
  • trunk/nagios-velvice/velvice.sample.yml

    r263 r322  
    3434      status: ALL
    3535      style: bold
     36
     37refreshments:
     38   -
     39      refresh: 300
     40      days:  [ 1 .. 5 ]
     41      start: [  9, 13 ]
     42      end:   [ 12, 18 ]
     43
     44   -
     45      refresh: 600
     46      days:  [ 1 .. 5 ]
     47      start: [ 12, 18 ]
     48      end:   [ 13, 20 ]
     49
     50   -
     51      refresh: 900
     52      days:  [ 1 .. 5 ]
     53      start: [ 7, 20 ]
     54      end:   [ 9, 24 ]
     55
     56   -
     57      refresh: 900
     58      days:  [ 6, 7 ]
     59      start: [  7 ]
     60      end:   [ 24 ]
     61
     62   -
     63      refresh: 1200
     64      days:  [  1 .. 7 ]
     65      start: [  0 ]
     66      end:   [ 24 ]
Note: See TracChangeset for help on using the changeset viewer.