[hobbit] custom client script and disable

Henrik Stoerner henrik at hswn.dk
Mon Nov 14 17:46:11 CET 2005


On Mon, Nov 14, 2005 at 05:18:41PM +0100, Frédéric Mangeant wrote:
> >same here (with Hobbit 4.1.2), it returns the "true" color of the 
> >test, and not blue :
> >
> >$ ./bb localhost "query dashboard.conn"
> >red <!-- [flags:ordAstILe] --> Thu Nov 10 16:53:30 2005 conn NOT ok
> >
> >It works fine on my bbgen 3.6 server :
> >
> >$ ./bb localhost "query dashboard.conn"
> >blue   Wed Oct 26 18:24:17 2005    OFFLINE UNTIL Mon Jul 21 18:24:17 2008
> 
> using "hobbitdlog" (from 4.1.2p1) it works fine, the blue color shows up 
> on the first line :

Eureka - I should have thought of that right away.

When hobbitd responds to a "query" command, it just spits back the 
first line of the last status message it received. But that will be
the "raw" status message - i.e. it will show red, because a disable
is handled through some internal status flags in Hobbit that aren't
reflected in the status message text hobbitd stores.

That is why when you look at the detailed status view for something
that is disabled, you'll see the "true" status below the "Disabled 
until .... " message.

This patch should fix it - against 4.1.2p1.


Regards,
Henrik

-------------- next part --------------
--- hobbitd/hobbitd.c.orig	2005-11-10 16:57:35.000000000 +0100
+++ hobbitd/hobbitd.c	2005-11-14 17:44:32.874945066 +0100
@@ -1978,11 +1978,23 @@
 			xfree(msg->buf);
 			msg->doingwhat = RESPONDING;
 			if (log->message) {
-				unsigned char *eoln;
-
-				eoln = strchr(log->message, '\n'); if (eoln) *eoln = '\0';
-				msg->buf = msg->bufp = strdup(msg_data(log->message));
+				unsigned char *bol, *eoln;
+				int msgcol;
+				char response[500];
+
+				bol = msg_data(log->message);
+				msgcol = parse_color(bol);
+				if (msgcol != -1) {
+					/* Skip the color - it may be different in real life */
+					bol += strlen(colorname(msgcol));
+					bol += strspn(bol, " \t");
+				}
+				eoln = strchr(bol, '\n'); if (eoln) *eoln = '\0';
+				snprintf(response, sizeof(response), "%s %s\n", colorname(log->color), bol);
+				response[sizeof(response)-1] = '\0';
 				if (eoln) *eoln = '\n';
+
+				msg->buf = msg->bufp = strdup(response);
 				msg->buflen = strlen(msg->buf);
 			}
 			else {


More information about the Xymon mailing list