Changeset 254


Ignore:
Timestamp:
Jun 25, 2018, 5:07:25 PM (2 years ago)
Author:
g7moreau
Message:
  • Change to action and make ssh depend generic
Location:
trunk/nagios-velvice
Files:
2 edited

Legend:

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

    r250 r254  
    3434$config->{'downtime'}{'max'}     ||= 50;
    3535$config->{'downtime'}{'factor'}  ||= 0.7;
    36 $config->{'service'}             ||= {};
     36$config->{'action'}              ||= {};
    3737
    3838my $query = CGI->new();
     
    132132ENDH
    133133
    134 my %service_name  = ();
    135 my %service_level = ();
     134my %service_name   = ();
     135my %service_status = ();
    136136for my $srv (@serviceproblems) {
    137137   $service_name{$srv->service_description}++;
    138    $service_level{$srv->status}++;
     138   $service_status{$srv->status}++;
    139139   }
    140140
     
    147147   $htmlpage .= join ",\n",
    148148      " <a href='$script_name?check=all'>ALL</a><small>(" . scalar(@serviceproblems) . ')</small>',
    149       map(" <a href='$script_name?check=" . lc(uri_encode($_)) . "'>$_</a>($service_level{$_})", sort keys %service_level);
     149      map(" <a href='$script_name?check=" . lc(uri_encode($_)) . "'>$_</a>($service_status{$_})", sort keys %service_status);
    150150   $htmlpage .= ".\n";
    151151   $htmlpage .= " <br />\n";
     
    158158   open $nagios_cmd, '>>', $config->{'nagios-cmd'} or die "Can't open file filename: $!";
    159159
    160    my %sshdown    = ();
    161    my %cmdafter   = ();
    162    my $after;
     160   my %remote_sshdown = ();
     161   my %remote_db      = ();
     162   my $remote_flag;
    163163
    164164   my $current_host  = '';
    165165   $htmlpage .= "<table border=\"1\">\n";
     166   SERVICE_PROBLEMS:
    166167   for my $srv (@serviceproblems) {
    167168      my $hostname = $srv->host_name;
     
    181182
    182183      my $bold;
    183       for my $srv_name (keys %{$config->{'service'}}) {
    184          my $srv_regex = $config->{'service'}{$srv_name}{'regex'};
    185          $bold++ if $service =~ m/$srv_regex/ and $config->{'service'}{$srv_name}{'style'} eq 'bold';
     184      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';
    186188         }
    187189      $htmlpage .= $bold ? '  <td class="bold">' : '  <td>';
     
    190192      $htmlpage .= "  <td>$status</td>\n";
    191193      $htmlpage .= "  <td style='max-width:60%;'><small>$output";
    192 
    193       $sshdown{$hostname}++ if $service eq 'SSH';
    194194
    195195      if (($check =~ m/all/i)
     
    211211         }
    212212
    213       for my $srv_name (keys %{$config->{'service'}}) {
    214          my $srv_regex  = $config->{'service'}{$srv_name}{'regex'};
    215          my $srv_status = $config->{'service'}{$srv_name}{'status'};
    216          if ($service =~ m/$srv_regex/ and ($srv_status eq 'ALL' or $status =~ m/$srv_status/)) {
    217             $cmdafter{$srv_name} ||= [];
    218             push @{$cmdafter{$srv_name}}, $hostname;
    219             $after++;
     213      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';
     218
     219         if ($service =~ m/$act_regex/ and ($act_status eq 'ALL' or $status =~ m/$act_status/)) {
     220            $remote_db{$act_name} ||= [];
     221            push @{$remote_db{$act_name}}, $hostname;
     222            $remote_flag++;
    220223            }
     224
     225         # check depend service otherwise
     226         $remote_sshdown{$act_depend} ||= {};
     227         $remote_sshdown{$act_depend}->{$hostname}++ if $service =~ m/$act_depend/;
    221228         }
    222229
     
    229236   close $nagios_cmd;
    230237
     238   # host down
    231239   if (%hostdown) {
    232240      $htmlpage .= "<br />\n";
    233241      $htmlpage .= "<table border='1'>\n";
     242      HOST_DOWN:
    234243      for my $host (sort keys %hostdown) {
    235244         my $host_stat = $hostdown{$host};
     
    250259      }
    251260
    252    if ($after) {
     261   # remote action
     262   if ($remote_flag) {
    253263      require Nagios::Object::Config;
    254264      my $parser = Nagios::Object::Config->new();
    255265      $parser->parse("/var/cache/nagios3/objects.cache");
    256266
    257       for my $srv_name (keys %cmdafter) {
    258          my @action = grep !exists $sshdown{$_}, @{$cmdafter{$srv_name}};
     267      REMOTE_ACTION:
     268      for my $act_name (keys %remote_db) {
     269         my $act_depend = $config->{'action'}{$act_name}{'depend'} || 'SSH';
     270
     271         my @action = grep !exists $remote_sshdown{$act_depend}->{$_}, @{$remote_db{$act_name}};
    259272         if (@action) {
    260             my $srv_title = $config->{'service'}{$srv_name}{'title'} || "Action: $srv_name";
     273            my $srv_title = $config->{'action'}{$act_name}{'title'} || "Action: $act_name";
    261274            $htmlpage .= "<h2>$srv_title</h2>\n";
    262275            $htmlpage .= "<pre>\n";
    263             my $remote_action = $config->{'service'}{$srv_name}{'command'};
    264             $remote_action = $config->{'service'}{$srv_name}{'command-one'} if @action == 1;
     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'};
    265278            my @hosts;
    266279            for my $host (@action) {
     
    283296print $htmlpage;
    284297
    285 # delay future check
     298# delayed future check
    286299if (@futurecheck) {
    287300   sleep 2;
  • trunk/nagios-velvice/velvice.sample.yml

    r248 r254  
    1515   factor:  0.7
    1616
    17 service:
     17action:
    1818   oom-killer:
    1919      regex: ^OOM Killer
Note: See TracChangeset for help on using the changeset viewer.