[xymon] RE: Alerts variables

Henrik Størner henrik at hswn.dk
Mon Feb 14 13:40:14 CET 2011


In <B08F3F3D67451844A7A8A029FCC71E4C1941CC1661 at WIN01.ad.deltamanagement.se> =?iso-8859-1?Q?Johan_Sj=F6berg?= <johan.sjoberg at deltamanagement.se> writes:

>Yes, exactly. It is a script from Xymonton that is invoked using SCRIPT. So=
> I would like to know if any variable is passed to the script containing th=
>e status "disabled"

OK, this turned out to be a slightly larger change than I had
anticipated. After testing things a bit, it dawned on me that
neither the mail-messages nor the script-based alerts would
be able to tell the difference between a genuine recovery
(going "green") and a recovery due to the status being disabled.

Which doesn't seem right.

The patch below should solve this. For mail/SMS alerts the
subject and message text has been changed from "recovered"
to "disabled". For scripts this can be seen from the value
of the RECOVERED variable - it will be "1" for a genuine
recovery (unchanged from before) and "2" for a recover-
by-disable.

The BBCOLORLEVEL setting remains unchanged, i.e. it will
NOT be blue. This is because BBCOLORLEVEL holds the value
of the color that triggered the alert - not the current 
color of the status.

Note: When you apply this patch (against 4.3.0-RC1), please
run "make clean" and then "make" to build the package.
Without the "make clean", some of the library modules will
probably not get updated - causing weird results.


Regards,
Henrik

Index: lib/loadalerts.c
===================================================================
--- lib/loadalerts.c	(revision 6631)
+++ lib/loadalerts.c	(working copy)
@@ -958,7 +958,7 @@
 		return result;
 	}
 
-	if (alert->state == A_RECOVERED) {
+	if ((alert->state == A_RECOVERED) || (alert->state == A_DISABLED)) {
 		/*
 		 * Dont do the check until we are checking individual recipients (rulecrit is set).
 		 * You dont need to have RECOVERED on the top-level rule, it's enough if a recipient
Index: lib/loadalerts.h
===================================================================
--- lib/loadalerts.h	(revision 6631)
+++ lib/loadalerts.h	(working copy)
@@ -18,7 +18,7 @@
 #if defined(LOCALCLIENT) || !defined(CLIENTONLY)
 #include <pcre.h>
 
-typedef enum { A_PAGING, A_NORECIP, A_ACKED, A_RECOVERED, A_NOTIFY, A_DEAD } astate_t;
+typedef enum { A_PAGING, A_NORECIP, A_ACKED, A_RECOVERED, A_DISABLED, A_NOTIFY, A_DEAD } astate_t;
 
 typedef struct activealerts_t {
 	/* Identification of the alert */
Index: xymond/xymond_alert.c
===================================================================
--- xymond/xymond_alert.c	(revision 6631)
+++ xymond/xymond_alert.c	(working copy)
@@ -75,8 +75,8 @@
 activealerts_t *ahead = NULL;
 
 char *statename[] = {
-	/* A_PAGING, A_NORECIP, A_ACKED, A_RECOVERED, A_NOTIFY, A_DEAD */
-	"paging", "norecip", "acked", "recovered", "notify", "dead"
+	/* A_PAGING, A_NORECIP, A_ACKED, A_RECOVERED, A_DISABLED, A_NOTIFY, A_DEAD */
+	"paging", "norecip", "acked", "recovered", "disabled", "notify", "dead"
 };
 
 char *find_name(RbtHandle tree, char *name)
@@ -662,7 +662,7 @@
 				 * Dont update the color here - we want recoveries to go out 
 				 * only if the alert color triggered an alert
 				 */
-				awalk->state = A_RECOVERED;
+				awalk->state = (newcolor == COL_BLUE) ? A_DISABLED : A_RECOVERED;
 			}
 
 			if (oldalertstatus != newalertstatus) {
@@ -865,6 +865,7 @@
 				break;
 
 			  case A_RECOVERED:
+			  case A_DISABLED:
 			  case A_NOTIFY:
 				anytogo++;
 				break;
@@ -895,6 +896,7 @@
 						break;
 
 					  case A_RECOVERED:
+					  case A_DISABLED:
 					  case A_NOTIFY:
 						send_alert(awalk, notiflogfd);
 						break;
@@ -929,6 +931,7 @@
 				break;
 
 			  case A_RECOVERED:
+			  case A_DISABLED:
 			  case A_NOTIFY:
 				awalk->state = A_DEAD;
 				/* Fall through */
Index: xymond/do_alert.c
===================================================================
--- xymond/do_alert.c	(revision 6631)
+++ xymond/do_alert.c	(working copy)
@@ -225,6 +225,12 @@
 			 alert->hostname, alert->testname, recip->cfid);
 		break;
 
+	  case A_DISABLED:
+		subjfmt = (include_configid ? "Xymon %s:%s disabled [cfid:%d]" :  "Xymon %s:%s disabled");
+		snprintf(subj, sizeof(subj)-1, subjfmt, 
+			 alert->hostname, alert->testname, recip->cfid);
+		break;
+
 	  case A_NORECIP:
 	  case A_DEAD:
 		/* Cannot happen */
@@ -310,6 +316,11 @@
 				alert->hostname, alert->testname);
 			break;
 
+		  case A_DISABLED:
+			sprintf(info, "%s:%s DISABLED", 
+				alert->hostname, alert->testname);
+			break;
+
 		  case A_NOTIFY:
 			sprintf(info, "%s:%s NOTICE", 
 				alert->hostname, alert->testname);
@@ -365,7 +376,7 @@
 	int first = 1;
 	int alertcount = 0;
 	time_t now = getcurrenttime(NULL);
-	char *alerttxt[A_DEAD+1] = { "Paging", "Acked", "Recovered", "Notify", "Dead" };
+	char *alerttxt[A_DEAD+1] = { "Paging", "Acked", "Recovered", "Disabled", "Notify", "Dead" };
 
 	dbgprintf("send_alert %s:%s state %d\n", alert->hostname, alert->testname, (int)alert->state);
 	traceprintf("send_alert %s:%s state %s\n", 
@@ -380,7 +391,7 @@
 			continue;
 		}
 
-		if (recip->noalerts && ((alert->state == A_PAGING) || (alert->state == A_RECOVERED))) {
+		if (recip->noalerts && ((alert->state == A_PAGING) || (alert->state == A_RECOVERED) || (alert->state == A_DISABLED))) {
 			traceprintf("Recipient '%s' dropped (NOALERT)\n", recip->recipient);
 			continue;
 		}
@@ -408,7 +419,7 @@
 			}
 			alertcount++;
 		}
-		else if (alert->state == A_RECOVERED) {
+		else if ((alert->state == A_RECOVERED) || (alert->state == A_DISABLED)) {
 			/* RECOVERED messages require that we've sent out an alert before */
 			repeat_t *rpt = NULL;
 
@@ -463,7 +474,7 @@
 							timestamp, alert->hostname, alert->testname,
 							alert->ip, mailrecip, recip->cfid,
 							(long)now, servicecode(alert->testname));
-						if (alert->state == A_RECOVERED) {
+						if ((alert->state == A_RECOVERED) || (alert->state == A_DISABLED)) {
 							fprintf(logfd, " %ld\n", (long)(now - alert->eventstart));
 						}
 						else {
@@ -561,7 +572,17 @@
 					putenv(bbcolorlevel);
 
 					recovered = (char *)malloc(strlen("RECOVERED=") + 2);
-					sprintf(recovered, "RECOVERED=%d", ((alert->state == A_RECOVERED) ? 1 : 0));
+					switch (alert->state) {
+					  case A_RECOVERED:
+						strcpy(recovered, "RECOVERED=1");
+						break;
+					  case A_DISABLED:
+						strcpy(recovered, "RECOVERED=2");
+						break;
+					  default:
+						strcpy(recovered, "RECOVERED=0");
+						break;
+					}
 					putenv(recovered);
 
 					downsecs = (char *)malloc(strlen("DOWNSECS=") + 20);
@@ -572,7 +593,7 @@
 					sprintf(eventtstamp, "EVENTSTART=%ld", (long)alert->eventstart);
 					putenv(eventtstamp);
 
-					if (alert->state == A_RECOVERED) {
+					if ((alert->state == A_RECOVERED) || (alert->state == A_DISABLED)) {
 						downsecsmsg = (char *)malloc(strlen("DOWNSECSMSG=Event duration :") + 20);
 						sprintf(downsecsmsg, "DOWNSECSMSG=Event duration : %ld", (long)(getcurrenttime(NULL) - alert->eventstart));
 					}
@@ -628,7 +649,7 @@
 							timestamp, alert->hostname, alert->testname,
 							alert->ip, scriptrecip, (long)now, 
 							servicecode(alert->testname));
-						if (alert->state == A_RECOVERED) {
+						if ((alert->state == A_RECOVERED) || (alert->state == A_DISABLED)) {
 							fprintf(logfd, " %ld\n", (long)(now - alert->eventstart));
 						}
 						else {



More information about the Xymon mailing list