Index: trunk/nagios-velvice/velvice.cgi
===================================================================
--- trunk/nagios-velvice/velvice.cgi	(revision 250)
+++ trunk/nagios-velvice/velvice.cgi	(revision 254)
@@ -34,5 +34,5 @@
 $config->{'downtime'}{'max'}     ||= 50;
 $config->{'downtime'}{'factor'}  ||= 0.7;
-$config->{'service'}             ||= {};
+$config->{'action'}              ||= {};
 
 my $query = CGI->new();
@@ -132,9 +132,9 @@
 ENDH
 
-my %service_name  = ();
-my %service_level = ();
+my %service_name   = ();
+my %service_status = ();
 for my $srv (@serviceproblems) {
    $service_name{$srv->service_description}++;
-   $service_level{$srv->status}++;
+   $service_status{$srv->status}++;
    }
 
@@ -147,5 +147,5 @@
    $htmlpage .= join ",\n",
       " <a href='$script_name?check=all'>ALL</a><small>(" . scalar(@serviceproblems) . ')</small>',
-      map(" <a href='$script_name?check=" . lc(uri_encode($_)) . "'>$_</a>($service_level{$_})", sort keys %service_level);
+      map(" <a href='$script_name?check=" . lc(uri_encode($_)) . "'>$_</a>($service_status{$_})", sort keys %service_status);
    $htmlpage .= ".\n";
    $htmlpage .= " <br />\n";
@@ -158,10 +158,11 @@
    open $nagios_cmd, '>>', $config->{'nagios-cmd'} or die "Can't open file filename: $!";
 
-   my %sshdown    = ();
-   my %cmdafter   = ();
-   my $after;
+   my %remote_sshdown = ();
+   my %remote_db      = ();
+   my $remote_flag;
 
    my $current_host  = '';
    $htmlpage .= "<table border=\"1\">\n";
+   SERVICE_PROBLEMS:
    for my $srv (@serviceproblems) {
       my $hostname = $srv->host_name;
@@ -181,7 +182,8 @@
 
       my $bold;
-      for my $srv_name (keys %{$config->{'service'}}) {
-         my $srv_regex = $config->{'service'}{$srv_name}{'regex'};
-         $bold++ if $service =~ m/$srv_regex/ and $config->{'service'}{$srv_name}{'style'} eq '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';
          }
       $htmlpage .= $bold ? '  <td class="bold">' : '  <td>';
@@ -190,6 +192,4 @@
       $htmlpage .= "  <td>$status</td>\n";
       $htmlpage .= "  <td style='max-width:60%;'><small>$output";
-
-      $sshdown{$hostname}++ if $service eq 'SSH';
 
       if (($check =~ m/all/i)
@@ -211,12 +211,19 @@
          }
 
-      for my $srv_name (keys %{$config->{'service'}}) {
-         my $srv_regex  = $config->{'service'}{$srv_name}{'regex'};
-         my $srv_status = $config->{'service'}{$srv_name}{'status'};
-         if ($service =~ m/$srv_regex/ and ($srv_status eq 'ALL' or $status =~ m/$srv_status/)) {
-            $cmdafter{$srv_name} ||= [];
-            push @{$cmdafter{$srv_name}}, $hostname;
-            $after++;
+      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';
+
+         if ($service =~ m/$act_regex/ and ($act_status eq 'ALL' or $status =~ m/$act_status/)) {
+            $remote_db{$act_name} ||= [];
+            push @{$remote_db{$act_name}}, $hostname;
+            $remote_flag++;
             }
+
+         # check depend service otherwise
+         $remote_sshdown{$act_depend} ||= {};
+         $remote_sshdown{$act_depend}->{$hostname}++ if $service =~ m/$act_depend/;
          }
 
@@ -229,7 +236,9 @@
    close $nagios_cmd;
 
+   # host down
    if (%hostdown) {
       $htmlpage .= "<br />\n";
       $htmlpage .= "<table border='1'>\n";
+      HOST_DOWN:
       for my $host (sort keys %hostdown) {
          my $host_stat = $hostdown{$host};
@@ -250,17 +259,21 @@
       }
 
-   if ($after) {
+   # remote action
+   if ($remote_flag) {
       require Nagios::Object::Config;
       my $parser = Nagios::Object::Config->new();
       $parser->parse("/var/cache/nagios3/objects.cache");
 
-      for my $srv_name (keys %cmdafter) {
-         my @action = grep !exists $sshdown{$_}, @{$cmdafter{$srv_name}};
+      REMOTE_ACTION:
+      for my $act_name (keys %remote_db) {
+         my $act_depend = $config->{'action'}{$act_name}{'depend'} || 'SSH';
+
+         my @action = grep !exists $remote_sshdown{$act_depend}->{$_}, @{$remote_db{$act_name}};
          if (@action) {
-            my $srv_title = $config->{'service'}{$srv_name}{'title'} || "Action: $srv_name";
+            my $srv_title = $config->{'action'}{$act_name}{'title'} || "Action: $act_name";
             $htmlpage .= "<h2>$srv_title</h2>\n";
             $htmlpage .= "<pre>\n";
-            my $remote_action = $config->{'service'}{$srv_name}{'command'};
-            $remote_action = $config->{'service'}{$srv_name}{'command-one'} if @action == 1;
+            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 @hosts;
             for my $host (@action) {
@@ -283,5 +296,5 @@
 print $htmlpage;
 
-# delay future check
+# delayed future check
 if (@futurecheck) {
    sleep 2;
