Changeset 257


Ignore:
Timestamp:
Jun 25, 2018, 9:35:20 PM (2 years ago)
Author:
g7moreau
Message:
  • Better default value, better variable cgi name
File:
1 edited

Legend:

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

    r256 r257  
    1515use strict;
    1616use warnings;
    17 use version; our $VERSION = version->declare('0.6.1');
     17use version; our $VERSION = version->declare('0.6.2');
    1818
    1919use CGI;
     
    2424use YAML::Syck;
    2525
    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();
     26my $query           = CGI->new();
     27my $cgi_check      = uri_decode($query->param('check'));
     28my $cgi_script_name = $query->script_name();
     29my $cgi_uri        = $query->request_uri();
    3030
    3131my $config = {};
     
    3434$config->{'nagios-server'}{'status-file'} ||= '/var/cache/nagios3/status.dat';
    3535$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";
     36$config->{'nagios-server'}{'portal-url'}  ||= $cgi_uri =~ s{/cgi-bin/}{/}r;
     37$config->{'nagios-server'}{'status-cgi'}  ||= "$cgi_uri/status.cgi";
    3938$config->{'host-mapping'}                 ||= {};
    4039$config->{'color-downtime'}               ||= {};
     
    130129 <ul>
    131130   <li>Nagios Velvice Alert Panel : <a href="$config->{'nagios-server'}{'portal-url'}">Core Server</a></li>
    132    <li><small>(<a href="$script_name">UPDATE</a> - $date)</small></li>
     131   <li><small>(<a href="$cgi_script_name">UPDATE</a> - $date)</small></li>
    133132 </ul>
    134133</h1>
     
    149148   $htmlpage .= "<p>Alert to recheck - Level:\n";
    150149   $htmlpage .= join ",\n",
    151       " <a href='$script_name?check=all'>ALL</a><small>(" . scalar(@serviceproblems) . ')</small>',
    152       map(" <a href='$script_name?check=" . lc(uri_encode($_)) . "'>$_</a>($service_status{$_})", sort keys %service_status);
     150      " <a href='$cgi_script_name?check=all'>ALL</a><small>(" . scalar(@serviceproblems) . ')</small>',
     151      map(" <a href='$cgi_script_name?check=" . lc(uri_encode($_)) . "'>$_</a>($service_status{$_})", sort keys %service_status);
    153152   $htmlpage .= ".\n";
    154153   $htmlpage .= " <br />\n";
    155154   $htmlpage .= " Service:\n";
    156    $htmlpage .= join ",\n", map(" <a href='$script_name?check=" . lc(uri_encode($_)) . "'>$_</a><small>($service_name{$_})</small>", sort keys %service_name);
     155   $htmlpage .= join ",\n", map(" <a href='$cgi_script_name?check=" . lc(uri_encode($_)) . "'>$_</a><small>($service_name{$_})</small>", sort keys %service_name);
    157156   $htmlpage .= ".\n";
    158157   $htmlpage .= "</p>\n";
     
    173172      my $status   = $srv->status;
    174173      my $downtime = downtime($srv->last_state_change);
    175       my $output   = HTML::Entities::encode($srv->plugin_output);
    176       $output =~ s/^[A-Z_\s]+?[:-]//;
     174      my $output   = HTML::Entities::encode($srv->plugin_output) =~ s/^[A-Z_\s]+?[:-]//r;
    177175
    178176      my $color = $status eq 'CRITICAL' ? '#F88888' : '#FFFF00';
     
    196194      $htmlpage .= "  <td style='max-width:60%;'><small>$output";
    197195
    198       if (($check =~ m/all/i)
    199             or ($check =~ m/^$service$/i)
    200             or ($check =~ m/critical/i and $status eq 'CRITICAL')
    201             or ($check =~ m/warning/i  and $status eq 'WARNING')
    202             or ($check =~ m/pending/i  and $status eq 'PENDING')
     196      if (($cgi_check =~ m/all/i)
     197            or ($cgi_check =~ m/^$service$/i)
     198            or ($cgi_check =~ m/critical/i and $status eq 'CRITICAL')
     199            or ($cgi_check =~ m/warning/i  and $status eq 'WARNING')
     200            or ($cgi_check =~ m/pending/i  and $status eq 'PENDING')
    203201            ) {
    204202         $now++;
Note: See TracChangeset for help on using the changeset viewer.