monit-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] ICMP with optional host parameter


From: Michel Marti
Subject: [PATCH] ICMP with optional host parameter
Date: Thu, 20 Jan 2005 19:38:53 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041007 Debian/1.7.3-5

Hello,

Attached is a patch (against monit-cvs) that adds an optional "host" parameter to the ICMP test and enables the use of "if failed icmp" for services of type "process".

With the patch applied, you could e.g. do something like this:

check process ipsec with pidfile /var/run/ipsec.pid
  start program = "/etc/init.d/ipsec start"
  stop program = "/etc/init.d/ipsec stop"
  if failed icmp host theotherside type echo with timeout 15 seconds then 
restart


Cheers,

Michel
diff -urN --exclude=CVS monit-cvs-start/gc.c monit-cvs/gc.c
--- monit-cvs-start/gc.c        2005-01-06 21:51:49.000000000 +0100
+++ monit-cvs/gc.c      2005-01-20 18:02:32.000000000 +0100
@@ -377,6 +377,7 @@
   if((*i)->action)
     _gc_eventaction(&(*i)->action);
 
+  FREE((*i)->host);
   FREE(*i);
 
 }
diff -urN --exclude=CVS monit-cvs-start/http/cervlet.c monit-cvs/http/cervlet.c
--- monit-cvs-start/http/cervlet.c      2005-01-06 21:51:50.000000000 +0100
+++ monit-cvs/http/cervlet.c    2005-01-20 19:22:31.000000000 +0100
@@ -1733,7 +1733,7 @@
 
 static void print_service_params_icmp(HttpResponse res, Service_T s) {
 
-  if(s->type == TYPE_HOST && s->icmplist) {
+  if((s->type == TYPE_HOST || s->type == TYPE_PROCESS) && s->icmplist) {
 
     Icmp_T i;
 
@@ -1748,11 +1748,11 @@
         if(!i->is_available) {
           out_print(res,
             "<tr><td>ICMP Response time</font></td><td><font color='#ff0000'>"
-            "connection failed [%s]</font></td></tr>", icmpnames[i->type]);
+            "connection failed for %s [%s]</font></td></tr>", i->host, 
icmpnames[i->type]);
         } else {
           out_print(res,
-            "<tr><td>ICMP Response time</td><td>%.3fs [%s]</td></tr>",
-            i->response, icmpnames[i->type]);
+            "<tr><td>ICMP Response time</td><td>%.3fs for %s [%s]</td></tr>",
+            i->response, i->host, icmpnames[i->type]);
         }
       }
     }
@@ -2199,13 +2199,13 @@
                  "cpu percent total", s->inf->total_cpu_percent/10.0);
       }
     }
-    if(s->type == TYPE_HOST && s->icmplist) {
+    if( (s->type == TYPE_HOST || s->type == TYPE_PROCESS) && s->icmplist) {
       Icmp_T i;
       for(i= s->icmplist; i; i= i->next) {
        out_print(res,
-                 "  %-33s %.3fs [%s]\n",
+                 "  %-33s %.3fs to %s [%s]\n",
                  "icmp response time", i->is_available?i->response:-1.,
-                 icmpnames[i->type]);
+                 i->host, icmpnames[i->type]);
       }
     }
     if((s->type == TYPE_HOST || s->type == TYPE_PROCESS) && s-> portlist) {
diff -urN --exclude=CVS monit-cvs-start/monitor.h monit-cvs/monitor.h
--- monit-cvs-start/monitor.h   2005-01-06 21:51:49.000000000 +0100
+++ monit-cvs/monitor.h 2005-01-20 18:01:59.000000000 +0100
@@ -471,6 +471,7 @@
 
 /** Defines a ICMP object */
 typedef struct myicmp {
+  char *host;                                 /**< host to "ping" (optional) */
   int type;                                              /**< ICMP type used */
   int timeout;              /**< The timeout in seconds to wait for response */
   int is_available;                     /**< TRUE if the server is available */
diff -urN --exclude=CVS monit-cvs-start/p.y monit-cvs/p.y
--- monit-cvs-start/p.y 2005-01-20 19:25:44.000000000 +0100
+++ monit-cvs/p.y       2005-01-20 18:45:47.000000000 +0100
@@ -301,6 +301,7 @@
                 | ppid
                 | connection
                 | connectionunix
+                | icmp
                 | timeout
                 | alert
                 | every
@@ -374,7 +375,7 @@
 opthost         : start
                 | stop
                 | connection
-               | icmp
+                | icmp
                 | timeout
                 | alert
                 | every
@@ -692,10 +693,10 @@
                 ;
 
 
-icmp            : IF FAILED ICMP icmptype nettimeout THEN action1 recovery {
-                   icmpset.type= $<number>4;
-                   icmpset.timeout= $<number>5;
-                   addeventaction(&(icmpset).action, $<number>7, $<number>8);
+icmp            : IF FAILED ICMP icmphost icmptype nettimeout THEN action1 
recovery {
+                   icmpset.type= $<number>5;
+                   icmpset.timeout= $<number>6;
+                   addeventaction(&(icmpset).action, $<number>8, $<number>9);
                    addicmp(&icmpset);
                   }
                 ;
@@ -709,6 +710,19 @@
                 | HOST STRING { check_hostname($2); portset.hostname= $2; }
                ;
 
+icmphost            : /* EMPTY */ {
+                    if(current->type == TYPE_HOST) {
+                      icmpset.host= xstrdup(current->path);
+                    } else {
+                      icmpset.host= xstrdup(LOCALHOST);
+                    }
+                  }
+                | HOST STRING { 
+                    check_hostname($2); 
+                    icmpset.host= $2; 
+                  }
+               ;
+
 port            : PORT NUMBER { portset.port= $2; portset.family= AF_INET; }
                 ;
 
@@ -1899,6 +1913,7 @@
     ASSERT(is);
 
     NEW(icmp);
+    icmp->host= is->host;
     icmp->type= is->type;
     icmp->timeout= is->timeout;
     icmp->action= is->action;
@@ -2702,6 +2717,7 @@
  * Reset the ICMP set to default values
  */
 static void reset_icmpset() {
+  icmpset.host = NULL;
   icmpset.type= ICMP_ECHO;
   icmpset.timeout= NET_TIMEOUT;
   icmpset.action= NULL;
diff -urN --exclude=CVS monit-cvs-start/util.c monit-cvs/util.c
--- monit-cvs-start/util.c      2005-01-20 19:25:44.000000000 +0100
+++ monit-cvs/util.c    2005-01-20 18:03:14.000000000 +0100
@@ -684,9 +684,9 @@
     for(i= s->icmplist; i; i= i->next) {
       EventAction_T a= i->action;
 
-      printf(" %-20s = if failed %s with timeout %d seconds then %s "
+      printf(" %-20s = if failed %s to %s with timeout %d seconds then %s "
         "else if recovered then %s\n",
-        "ICMP", icmpnames[i->type], i->timeout, actionnames[a->failed->id],
+        "ICMP", icmpnames[i->type], i->host, i->timeout, 
actionnames[a->failed->id],
         actionnames[a->passed->id]);
     }
 
diff -urN --exclude=CVS monit-cvs-start/validate.c monit-cvs/validate.c
--- monit-cvs-start/validate.c  2005-01-20 19:25:44.000000000 +0100
+++ monit-cvs/validate.c        2005-01-20 18:39:15.000000000 +0100
@@ -171,7 +171,6 @@
 int check_process(Service_T s) {
 
   pid_t  pid= -1;
-  Port_T pp= NULL;
   Resource_T pr= NULL;
 
   ASSERT(s);
@@ -204,10 +203,8 @@
 
   }
 
-  /* Test each host:port and protocol in the service's portlist */
-  if(s->portlist)
-    for(pp= s->portlist; pp; pp= pp->next)
-      check_connection(s, pp);
+  /* Test each host:port and protocol and ICMP */
+  check_remote_host(s);
 
   return TRUE;
   
@@ -395,8 +392,9 @@
 
       switch(icmp->type) {
       case ICMP_ECHO:
-
-        icmp->response= icmp_echo(s->path, icmp->timeout);
+        DEBUG("'%s' sending ICMP echo request to host '%s' with timeout %d\n",
+            s->name, icmp->host, icmp->timeout);
+        icmp->response=icmp_echo(icmp->host, icmp->timeout);
 
         if(icmp->response < 0) {
           icmp->is_available= FALSE;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]