Changeset 322 for trunk/nagios-velvice/velvice.cgi
- Timestamp:
- Jul 20, 2018, 9:26:28 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nagios-velvice/velvice.cgi
r321 r322 12 12 # 13 13 # 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 14 15 15 16 use strict; 16 17 use warnings; 17 use version; our $VERSION = version->declare('0. 8.10');18 use version; our $VERSION = version->declare('0.9.0'); 18 19 19 20 use CGI; … … 51 52 $config->{'color-downtime'}{'factor'} ||= 0.7; 52 53 $config->{'remote-action'} ||= {}; 54 $config->{'refresh'} ||= 0; 55 56 sub hostmapping { 57 my $host = shift; 58 59 return exists $config->{'host-mapping'}{$host} ? $config->{'host-mapping'}{$host} : $host; 60 } 61 62 sub downtime { 63 my ($time_change) = @_; 64 65 my $now = time; 66 return sprintf '%.1f', ($now - $time_change) / (60 * 3600); 67 } 68 69 sub 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 83 sub nosbreak { 84 my ($str) = @_; 85 86 return $str =~ s/\s/\ /gr; 87 } 53 88 54 89 my $log = Nagios::StatusLog->new( … … 57 92 ); 58 93 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/\ /gr; 94 # refresh configuration 95 if (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 } 90 116 } 91 117 … … 145 171 <head> 146 172 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 173 <meta http-equiv="Refresh" content="$config->{'refresh'}"> 147 174 <title>Nagios Velvice</title> 148 175 <link rel="stylesheet" type="text/css" href="$config->{'nagios-server'}{'stylesheets'}/velvice.css">
Note: See TracChangeset
for help on using the changeset viewer.