Index: trunk/nagios-velvice/velvice.cgi
===================================================================
--- trunk/nagios-velvice/velvice.cgi	(revision 255)
+++ trunk/nagios-velvice/velvice.cgi	(revision 256)
@@ -3,4 +3,5 @@
 # 2014/05/15 Gabriel Moreau <Gabriel.Moreau@univ-grenoble-alpes.fr>
 # 2017/06/22 Gabriel Moreau - big update
+# 2018/06/25 Gabriel Moreau - make velvice generic
 #
 # velvice.cgi
@@ -14,5 +15,5 @@
 use strict;
 use warnings;
-use version; our $VERSION = version->declare('0.5.6');
+use version; our $VERSION = version->declare('0.6.1');
 
 use CGI;
@@ -23,31 +24,33 @@
 use YAML::Syck;
 
+my $query = CGI->new();
+my $check = uri_decode($query->param('check'));
+my $script_name = $query->script_name();
+#my $uri = $query->request_uri();
+
 my $config = {};
 $config = YAML::Syck::LoadFile('/etc/nagios3/velvice.yml') if -e '/etc/nagios3/velvice.yml';
-$config->{'status-file'}         ||= '/var/cache/nagios3/status.dat';
-$config->{'nagios-cmd'}          ||= '/var/lib/nagios3/rw/nagios.cmd';
-$config->{'portal-url'}          ||= 'http://localhost/nagios3/';
-$config->{'status-cgi'}          ||= 'http://localhost/cgi-bin/nagios3/status.cgi';
-$config->{'mapping'}             ||= {};
-$config->{'downtime'}            ||= {};
-$config->{'downtime'}{'min'}     ||= 3;
-$config->{'downtime'}{'max'}     ||= 50;
-$config->{'downtime'}{'factor'}  ||= 0.7;
-$config->{'action'}              ||= {};
-
-my $query = CGI->new();
+$config->{'nagios-server'}                ||= {};
+$config->{'nagios-server'}{'status-file'} ||= '/var/cache/nagios3/status.dat';
+$config->{'nagios-server'}{'nagios-cmd'}  ||= '/var/lib/nagios3/rw/nagios.cmd';
+$config->{'nagios-server'}{'portal-url'}  ||= 'http://localhost/nagios3/';
+$config->{'nagios-server'}{'status-cgi'}  ||= 'http://localhost/cgi-bin/nagios3/status.cgi';
+#$config->{'nagios-server'}{'status-cgi'}  ||= "$uri/status.cgi";
+$config->{'host-mapping'}                 ||= {};
+$config->{'color-downtime'}               ||= {};
+$config->{'color-downtime'}{'min'}        ||= 3;
+$config->{'color-downtime'}{'max'}        ||= 50;
+$config->{'color-downtime'}{'factor'}     ||= 0.7;
+$config->{'remote-action'}                ||= {};
 
 my $log = Nagios::StatusLog->new(
-   Filename => $config->{'status-file'},
+   Filename => $config->{'nagios-server'}{'status-file'},
    Version  => 3.0
    );
 
-my $check = uri_decode($query->param('check'));
-my $script_name = $query->script_name();
-
 sub hostmapping {
    my $host = shift;
 
-   return exists $config->{'mapping'}{$host} ? $config->{'mapping'}{$host} : $host;
+   return exists $config->{'host-mapping'}{$host} ? $config->{'host-mapping'}{$host} : $host;
    }
 
@@ -62,9 +65,9 @@
    my ($color, $downtime) = @_;
 
-   $downtime = $downtime - $config->{'downtime'}{'min'}; # same color first days
-   $downtime = $config->{'downtime'}{'max'} if $downtime > $config->{'downtime'}{'max'}; # max 50 days for color
+   $downtime = $downtime - $config->{'color-downtime'}{'min'}; # same color first days
+   $downtime = $config->{'color-downtime'}{'max'} if $downtime > $config->{'color-downtime'}{'max'}; # max 50 days for color
    $downtime =  0 if $downtime <  0;
 
-   my $factor = ($downtime * $config->{'downtime'}{'factor'}) / $config->{'downtime'}{'max'};
+   my $factor = ($downtime * $config->{'color-downtime'}{'factor'}) / $config->{'color-downtime'}{'max'};
    return Color::Calc::color_light_html($color, $factor);
    }
@@ -126,5 +129,5 @@
 <h1>
  <ul>
-   <li>Nagios Velvice Alert Panel : <a href="$config->{'portal-url'}">Core Server</a></li>
+   <li>Nagios Velvice Alert Panel : <a href="$config->{'nagios-server'}{'portal-url'}">Core Server</a></li>
    <li><small>(<a href="$script_name">UPDATE</a> - $date)</small></li>
  </ul>
@@ -156,5 +159,5 @@
 
    my $nagios_cmd;
-   open $nagios_cmd, '>>', $config->{'nagios-cmd'} or die "Can't open file filename: $!";
+   open $nagios_cmd, '>>', $config->{'nagios-server'}{'nagios-cmd'} or die "Can't open file filename: $!";
 
    my %remote_sshdown = ();
@@ -178,12 +181,12 @@
       if ($hostname ne $current_host) {
          $current_host = $hostname;
-         $htmlpage .= "  <td rowspan='$hostcount{$hostname}' style='vertical-align:middle;'><a href=\"$config->{'status-cgi'}?host=$hostname\">$hostname</a></td>\n";
+         $htmlpage .= "  <td rowspan='$hostcount{$hostname}' style='vertical-align:middle;'><a href=\"$config->{'nagios-server'}{'status-cgi'}?host=$hostname\">$hostname</a></td>\n";
          }
 
       my $bold;
       ACTION_STYLE:
-      for my $act_name (keys %{$config->{'action'}}) {
-         my $act_regex = $config->{'action'}{$act_name}{'regex'};
-         $bold++ if $service =~ m/$act_regex/ and $config->{'action'}{$act_name}{'style'} eq 'bold';
+      for my $act_name (keys %{$config->{'remote-action'}}) {
+         my $act_regex = $config->{'remote-action'}{$act_name}{'regex'};
+         $bold++ if $service =~ m/$act_regex/ and $config->{'remote-action'}{$act_name}{'style'} eq 'bold';
          }
       $htmlpage .= $bold ? '  <td class="bold">' : '  <td>';
@@ -212,8 +215,8 @@
 
       ACTION_PUSH_AND_DEPEND:
-      for my $act_name (keys %{$config->{'action'}}) {
-         my $act_regex  = $config->{'action'}{$act_name}{'regex'};
-         my $act_status = $config->{'action'}{$act_name}{'status'} || 'ALL';
-         my $act_depend = $config->{'action'}{$act_name}{'depend'} || 'SSH';
+      for my $act_name (keys %{$config->{'remote-action'}}) {
+         my $act_regex  = $config->{'remote-action'}{$act_name}{'regex'};
+         my $act_status = $config->{'remote-action'}{$act_name}{'status'} || 'ALL';
+         my $act_depend = $config->{'remote-action'}{$act_name}{'depend'} || 'SSH';
 
          if ($service =~ m/$act_regex/ and ($act_status eq 'ALL' or $status =~ m/$act_status/)) {
@@ -247,5 +250,5 @@
          my $color = alertcolor('#F88888', $downtime);
          $htmlpage .= " <tr style='background:$color'>\n";
-         $htmlpage .= "  <td><a href=\"$config->{'status-cgi'}?host=$hostname\">$hostname</a></td>\n";
+         $htmlpage .= "  <td><a href=\"$config->{'nagios-server'}{'status-cgi'}?host=$hostname\">$hostname</a></td>\n";
          my @host_service;
          for my $srv ($log->list_services_on_host($host)) {
@@ -267,13 +270,14 @@
       REMOTE_ACTION:
       for my $act_name (keys %remote_db) {
-         my $act_depend = $config->{'action'}{$act_name}{'depend'} || 'SSH';
+         my $act_depend = $config->{'remote-action'}{$act_name}{'depend'} || 'SSH';
 
          my @action = grep !exists $remote_sshdown{$act_depend}->{$_}, @{$remote_db{$act_name}};
          if (@action) {
-            my $srv_title = $config->{'action'}{$act_name}{'title'} || "Action: $act_name";
+            my $srv_title = $config->{'remote-action'}{$act_name}{'title'} || "Action: $act_name";
             $htmlpage .= "<h2>$srv_title</h2>\n";
             $htmlpage .= "<pre>\n";
-            my $remote_action = $config->{'action'}{$act_name}{'command'};
-            $remote_action = $config->{'action'}{$act_name}{'command-one'} if @action == 1 and exists $config->{'action'}{$act_name}{'command-one'};
+            my $remote_action = $config->{'remote-action'}{$act_name}{'command'};
+            $remote_action = $config->{'remote-action'}{$act_name}{'command-one'}
+               if @action == 1 and exists $config->{'remote-action'}{$act_name}{'command-one'};
             my @hosts;
             for my $host (@action) {
@@ -300,5 +304,5 @@
    sleep 2;
    my $nagios_cmd;
-   open $nagios_cmd, '>>', $config->{'nagios-cmd'} or die "Can't open file filename: $!";
+   open $nagios_cmd, '>>', $config->{'nagios-server'}{'nagios-cmd'} or die "Can't open file filename: $!";
    print $nagios_cmd "$_\n" for @futurecheck;
    close $nagios_cmd;
Index: trunk/nagios-velvice/velvice.sample.yml
===================================================================
--- trunk/nagios-velvice/velvice.sample.yml	(revision 255)
+++ trunk/nagios-velvice/velvice.sample.yml	(revision 256)
@@ -1,19 +1,19 @@
 ---
-status-file: /var/cache/nagios3/status.dat
-nagios-cmd:  /var/lib/nagios3/rw/nagios.cmd
+nagios-server:
+   status-file: /var/cache/nagios3/status.dat
+   nagios-cmd:  /var/lib/nagios3/rw/nagios.cmd
+   portal-url:  https://srv-nagios.example.com/nagios3/
+   status-cgi:  https://srv-nagios.example.com/cgi-bin/nagios3/status.cgi
 
-portal-url: https://srv-nagios.example.com/nagios3/
-status-cgi: https://srv-nagios.example.com/cgi-bin/nagios3/status.cgi
-
-mapping:
+host-mapping:
    localhost:  srv-nagios
    toto:       titi
 
-downtime:
+color-downtime:
    min:     3
    max:    50
    factor:  0.7
 
-action:
+remote-action:
    oom-killer:
       regex: ^OOM Killer
