Changeset 256


Ignore:
Timestamp:
Jun 25, 2018, 9:07:53 PM (2 years ago)
Author:
g7moreau
Message:
  • Rename YAML key
Location:
trunk/nagios-velvice
Files:
2 edited

Legend:

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

    r255 r256  
    33# 2014/05/15 Gabriel Moreau <Gabriel.Moreau@univ-grenoble-alpes.fr>
    44# 2017/06/22 Gabriel Moreau - big update
     5# 2018/06/25 Gabriel Moreau - make velvice generic
    56#
    67# velvice.cgi
     
    1415use strict;
    1516use warnings;
    16 use version; our $VERSION = version->declare('0.5.6');
     17use version; our $VERSION = version->declare('0.6.1');
    1718
    1819use CGI;
     
    2324use YAML::Syck;
    2425
     26my $query = CGI->new();
     27my $check = uri_decode($query->param('check'));
     28my $script_name = $query->script_name();
     29#my $uri = $query->request_uri();
     30
    2531my $config = {};
    2632$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'}                ||= {};
    3945
    4046my $log = Nagios::StatusLog->new(
    41    Filename => $config->{'status-file'},
     47   Filename => $config->{'nagios-server'}{'status-file'},
    4248   Version  => 3.0
    4349   );
    4450
    45 my $check = uri_decode($query->param('check'));
    46 my $script_name = $query->script_name();
    47 
    4851sub hostmapping {
    4952   my $host = shift;
    5053
    51    return exists $config->{'mapping'}{$host} ? $config->{'mapping'}{$host} : $host;
     54   return exists $config->{'host-mapping'}{$host} ? $config->{'host-mapping'}{$host} : $host;
    5255   }
    5356
     
    6265   my ($color, $downtime) = @_;
    6366
    64    $downtime = $downtime - $config->{'downtime'}{'min'}; # same color first days
    65    $downtime = $config->{'downtime'}{'max'} if $downtime > $config->{'downtime'}{'max'}; # max 50 days for color
     67   $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
    6669   $downtime =  0 if $downtime <  0;
    6770
    68    my $factor = ($downtime * $config->{'downtime'}{'factor'}) / $config->{'downtime'}{'max'};
     71   my $factor = ($downtime * $config->{'color-downtime'}{'factor'}) / $config->{'color-downtime'}{'max'};
    6972   return Color::Calc::color_light_html($color, $factor);
    7073   }
     
    126129<h1>
    127130 <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>
    129132   <li><small>(<a href="$script_name">UPDATE</a> - $date)</small></li>
    130133 </ul>
     
    156159
    157160   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: $!";
    159162
    160163   my %remote_sshdown = ();
     
    178181      if ($hostname ne $current_host) {
    179182         $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";
    181184         }
    182185
    183186      my $bold;
    184187      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';
    188191         }
    189192      $htmlpage .= $bold ? '  <td class="bold">' : '  <td>';
     
    212215
    213216      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';
    218221
    219222         if ($service =~ m/$act_regex/ and ($act_status eq 'ALL' or $status =~ m/$act_status/)) {
     
    247250         my $color = alertcolor('#F88888', $downtime);
    248251         $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";
    250253         my @host_service;
    251254         for my $srv ($log->list_services_on_host($host)) {
     
    267270      REMOTE_ACTION:
    268271      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';
    270273
    271274         my @action = grep !exists $remote_sshdown{$act_depend}->{$_}, @{$remote_db{$act_name}};
    272275         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";
    274277            $htmlpage .= "<h2>$srv_title</h2>\n";
    275278            $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'};
    278282            my @hosts;
    279283            for my $host (@action) {
     
    300304   sleep 2;
    301305   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: $!";
    303307   print $nagios_cmd "$_\n" for @futurecheck;
    304308   close $nagios_cmd;
  • trunk/nagios-velvice/velvice.sample.yml

    r254 r256  
    11---
    2 status-file: /var/cache/nagios3/status.dat
    3 nagios-cmd:  /var/lib/nagios3/rw/nagios.cmd
     2nagios-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
    47
    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:
     8host-mapping:
    99   localhost:  srv-nagios
    1010   toto:       titi
    1111
    12 downtime:
     12color-downtime:
    1313   min:     3
    1414   max:    50
    1515   factor:  0.7
    1616
    17 action:
     17remote-action:
    1818   oom-killer:
    1919      regex: ^OOM Killer
Note: See TracChangeset for help on using the changeset viewer.