Changeset 256 for trunk/nagios-velvice
- Timestamp:
- Jun 25, 2018, 9:07:53 PM (7 years ago)
- Location:
- trunk/nagios-velvice
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nagios-velvice/velvice.cgi
r255 r256 3 3 # 2014/05/15 Gabriel Moreau <Gabriel.Moreau@univ-grenoble-alpes.fr> 4 4 # 2017/06/22 Gabriel Moreau - big update 5 # 2018/06/25 Gabriel Moreau - make velvice generic 5 6 # 6 7 # velvice.cgi … … 14 15 use strict; 15 16 use warnings; 16 use version; our $VERSION = version->declare('0. 5.6');17 use version; our $VERSION = version->declare('0.6.1'); 17 18 18 19 use CGI; … … 23 24 use YAML::Syck; 24 25 26 my $query = CGI->new(); 27 my $check = uri_decode($query->param('check')); 28 my $script_name = $query->script_name(); 29 #my $uri = $query->request_uri(); 30 25 31 my $config = {}; 26 32 $config = YAML::Syck::LoadFile('/etc/nagios3/velvice.yml') if -e '/etc/nagios3/velvice.yml'; 27 $config->{' status-file'} ||= '/var/cache/nagios3/status.dat';28 $config->{'nagios- cmd'} ||= '/var/lib/nagios3/rw/nagios.cmd';29 $config->{' portal-url'} ||= 'http://localhost/nagios3/';30 $config->{' status-cgi'} ||= 'http://localhost/cgi-bin/nagios3/status.cgi';31 $config->{' mapping'} ||= {};32 $config->{'downtime'} ||= {};33 $config->{' downtime'}{'min'} ||= 3;34 $config->{' downtime'}{'max'} ||= 50;35 $config->{' downtime'}{'factor'} ||= 0.7;36 $config->{' action'} ||= {};37 38 my $query = CGI->new();33 $config->{'nagios-server'} ||= {}; 34 $config->{'nagios-server'}{'status-file'} ||= '/var/cache/nagios3/status.dat'; 35 $config->{'nagios-server'}{'nagios-cmd'} ||= '/var/lib/nagios3/rw/nagios.cmd'; 36 $config->{'nagios-server'}{'portal-url'} ||= 'http://localhost/nagios3/'; 37 $config->{'nagios-server'}{'status-cgi'} ||= 'http://localhost/cgi-bin/nagios3/status.cgi'; 38 #$config->{'nagios-server'}{'status-cgi'} ||= "$uri/status.cgi"; 39 $config->{'host-mapping'} ||= {}; 40 $config->{'color-downtime'} ||= {}; 41 $config->{'color-downtime'}{'min'} ||= 3; 42 $config->{'color-downtime'}{'max'} ||= 50; 43 $config->{'color-downtime'}{'factor'} ||= 0.7; 44 $config->{'remote-action'} ||= {}; 39 45 40 46 my $log = Nagios::StatusLog->new( 41 Filename => $config->{' status-file'},47 Filename => $config->{'nagios-server'}{'status-file'}, 42 48 Version => 3.0 43 49 ); 44 50 45 my $check = uri_decode($query->param('check'));46 my $script_name = $query->script_name();47 48 51 sub hostmapping { 49 52 my $host = shift; 50 53 51 return exists $config->{' mapping'}{$host} ? $config->{'mapping'}{$host} : $host;54 return exists $config->{'host-mapping'}{$host} ? $config->{'host-mapping'}{$host} : $host; 52 55 } 53 56 … … 62 65 my ($color, $downtime) = @_; 63 66 64 $downtime = $downtime - $config->{' downtime'}{'min'}; # same color first days65 $downtime = $config->{' downtime'}{'max'} if $downtime > $config->{'downtime'}{'max'}; # max 50 days for color67 $downtime = $downtime - $config->{'color-downtime'}{'min'}; # same color first days 68 $downtime = $config->{'color-downtime'}{'max'} if $downtime > $config->{'color-downtime'}{'max'}; # max 50 days for color 66 69 $downtime = 0 if $downtime < 0; 67 70 68 my $factor = ($downtime * $config->{' downtime'}{'factor'}) / $config->{'downtime'}{'max'};71 my $factor = ($downtime * $config->{'color-downtime'}{'factor'}) / $config->{'color-downtime'}{'max'}; 69 72 return Color::Calc::color_light_html($color, $factor); 70 73 } … … 126 129 <h1> 127 130 <ul> 128 <li>Nagios Velvice Alert Panel : <a href="$config->{' portal-url'}">Core Server</a></li>131 <li>Nagios Velvice Alert Panel : <a href="$config->{'nagios-server'}{'portal-url'}">Core Server</a></li> 129 132 <li><small>(<a href="$script_name">UPDATE</a> - $date)</small></li> 130 133 </ul> … … 156 159 157 160 my $nagios_cmd; 158 open $nagios_cmd, '>>', $config->{'nagios- cmd'} or die "Can't open file filename: $!";161 open $nagios_cmd, '>>', $config->{'nagios-server'}{'nagios-cmd'} or die "Can't open file filename: $!"; 159 162 160 163 my %remote_sshdown = (); … … 178 181 if ($hostname ne $current_host) { 179 182 $current_host = $hostname; 180 $htmlpage .= " <td rowspan='$hostcount{$hostname}' style='vertical-align:middle;'><a href=\"$config->{' status-cgi'}?host=$hostname\">$hostname</a></td>\n";183 $htmlpage .= " <td rowspan='$hostcount{$hostname}' style='vertical-align:middle;'><a href=\"$config->{'nagios-server'}{'status-cgi'}?host=$hostname\">$hostname</a></td>\n"; 181 184 } 182 185 183 186 my $bold; 184 187 ACTION_STYLE: 185 for my $act_name (keys %{$config->{' action'}}) {186 my $act_regex = $config->{' action'}{$act_name}{'regex'};187 $bold++ if $service =~ m/$act_regex/ and $config->{' action'}{$act_name}{'style'} eq 'bold';188 for my $act_name (keys %{$config->{'remote-action'}}) { 189 my $act_regex = $config->{'remote-action'}{$act_name}{'regex'}; 190 $bold++ if $service =~ m/$act_regex/ and $config->{'remote-action'}{$act_name}{'style'} eq 'bold'; 188 191 } 189 192 $htmlpage .= $bold ? ' <td class="bold">' : ' <td>'; … … 212 215 213 216 ACTION_PUSH_AND_DEPEND: 214 for my $act_name (keys %{$config->{' action'}}) {215 my $act_regex = $config->{' action'}{$act_name}{'regex'};216 my $act_status = $config->{' action'}{$act_name}{'status'} || 'ALL';217 my $act_depend = $config->{' action'}{$act_name}{'depend'} || 'SSH';217 for my $act_name (keys %{$config->{'remote-action'}}) { 218 my $act_regex = $config->{'remote-action'}{$act_name}{'regex'}; 219 my $act_status = $config->{'remote-action'}{$act_name}{'status'} || 'ALL'; 220 my $act_depend = $config->{'remote-action'}{$act_name}{'depend'} || 'SSH'; 218 221 219 222 if ($service =~ m/$act_regex/ and ($act_status eq 'ALL' or $status =~ m/$act_status/)) { … … 247 250 my $color = alertcolor('#F88888', $downtime); 248 251 $htmlpage .= " <tr style='background:$color'>\n"; 249 $htmlpage .= " <td><a href=\"$config->{' status-cgi'}?host=$hostname\">$hostname</a></td>\n";252 $htmlpage .= " <td><a href=\"$config->{'nagios-server'}{'status-cgi'}?host=$hostname\">$hostname</a></td>\n"; 250 253 my @host_service; 251 254 for my $srv ($log->list_services_on_host($host)) { … … 267 270 REMOTE_ACTION: 268 271 for my $act_name (keys %remote_db) { 269 my $act_depend = $config->{' action'}{$act_name}{'depend'} || 'SSH';272 my $act_depend = $config->{'remote-action'}{$act_name}{'depend'} || 'SSH'; 270 273 271 274 my @action = grep !exists $remote_sshdown{$act_depend}->{$_}, @{$remote_db{$act_name}}; 272 275 if (@action) { 273 my $srv_title = $config->{' action'}{$act_name}{'title'} || "Action: $act_name";276 my $srv_title = $config->{'remote-action'}{$act_name}{'title'} || "Action: $act_name"; 274 277 $htmlpage .= "<h2>$srv_title</h2>\n"; 275 278 $htmlpage .= "<pre>\n"; 276 my $remote_action = $config->{'action'}{$act_name}{'command'}; 277 $remote_action = $config->{'action'}{$act_name}{'command-one'} if @action == 1 and exists $config->{'action'}{$act_name}{'command-one'}; 279 my $remote_action = $config->{'remote-action'}{$act_name}{'command'}; 280 $remote_action = $config->{'remote-action'}{$act_name}{'command-one'} 281 if @action == 1 and exists $config->{'remote-action'}{$act_name}{'command-one'}; 278 282 my @hosts; 279 283 for my $host (@action) { … … 300 304 sleep 2; 301 305 my $nagios_cmd; 302 open $nagios_cmd, '>>', $config->{'nagios- cmd'} or die "Can't open file filename: $!";306 open $nagios_cmd, '>>', $config->{'nagios-server'}{'nagios-cmd'} or die "Can't open file filename: $!"; 303 307 print $nagios_cmd "$_\n" for @futurecheck; 304 308 close $nagios_cmd; -
trunk/nagios-velvice/velvice.sample.yml
r254 r256 1 1 --- 2 status-file: /var/cache/nagios3/status.dat 3 nagios-cmd: /var/lib/nagios3/rw/nagios.cmd 2 nagios-server: 3 status-file: /var/cache/nagios3/status.dat 4 nagios-cmd: /var/lib/nagios3/rw/nagios.cmd 5 portal-url: https://srv-nagios.example.com/nagios3/ 6 status-cgi: https://srv-nagios.example.com/cgi-bin/nagios3/status.cgi 4 7 5 portal-url: https://srv-nagios.example.com/nagios3/ 6 status-cgi: https://srv-nagios.example.com/cgi-bin/nagios3/status.cgi 7 8 mapping: 8 host-mapping: 9 9 localhost: srv-nagios 10 10 toto: titi 11 11 12 downtime:12 color-downtime: 13 13 min: 3 14 14 max: 50 15 15 factor: 0.7 16 16 17 action:17 remote-action: 18 18 oom-killer: 19 19 regex: ^OOM Killer
Note: See TracChangeset
for help on using the changeset viewer.