Xymon Mailing List Archive search

adding extra channel

8 messages in this thread

list Stef Coene · Tue, 6 Feb 2007 16:47:55 +0100 ·
Hi,

We want to (mis)use the hobbit client-server communication to send oracle information to a hobbit server.  Thx to Henrik for the perl demo, I know how to write a perl script that I can use on the hobbit server to receive the information by hooking it in the a channel.

I can use the client channel for this, but I think it's better if I create an extra channel for this.
I took a quick look at the code, but I can barely and understand the code :(

So, has anyone changed the hobbit server code and added an extra channel and want to share his changes ?


Stef
list Charles Goyard · Wed, 7 Feb 2007 10:28:58 +0100 ·
Hi,
quoted from Stef Coene

Stef Coene wrote :
I can use the client channel for this, but I think it's better if I create an 
extra channel for this.
I took a quick look at the code, but I can barely and understand the code :(
I will do that, because I currently misuse the "notes" channel for
inventory purposes and using hobbit as a gateway (because monitoring is
the only thing guaranteed to be open on the firewalls). If you can wait
a month or so (I have a few more-than-urgent task to finish), I'll
submit the patch to the list. The new channels could be "user1" and
"user2".


-- 
Charles Goyard - user-98f9625a7a59@xymon.invalid - (+33) 1 45 38 01 31
list Stef Coene · Wed, 7 Feb 2007 11:50:24 +0100 ·
quoted from Charles Goyard
On Wednesday 07 February 2007 10:28, Charles Goyard wrote:
Hi,

Stef Coene wrote :
I can use the client channel for this, but I think it's better if I
create an extra channel for this.
I took a quick look at the code, but I can barely and understand the code

:(
quoted from Charles Goyard
I will do that, because I currently misuse the "notes" channel for
inventory purposes and using hobbit as a gateway (because monitoring is
the only thing guaranteed to be open on the firewalls). If you can wait
a month or so (I have a few more-than-urgent task to finish), I'll
submit the patch to the list. The new channels could be "user1" and
"user2".
Mhh, I can not wait a month.  If I'm first with a patch, I will post it 
here ;)


Stef
list Henrik Størner · Wed, 7 Feb 2007 12:50:53 +0100 ·
quoted from Stef Coene
On Tue, Feb 06, 2007 at 04:47:55PM +0100, Stef Coene wrote:
We want to (mis)use the hobbit client-server communication to send oracle 
information to a hobbit server.  Thx to Henrik for the perl demo, I know how 
to write a perl script that I can use on the hobbit server to receive the 
information by hooking it in the a channel.

I can use the client channel for this, but I think it's better if I create an 
extra channel for this.
I took a quick look at the code, but I can barely and understand the code :(

So, has anyone changed the hobbit server code and added an extra channel and 
want to share his changes ?
The attached patch should do it. It creates a "user" channel that is fed
the messages you send with 
   $BB $BBDISP "usermsg HOSTNAME ... your custom message here ..."

On the server side, run 
   hobbitd_channel --channel=user YOURCUSTOMCOMMAND
to pick up the messages.

I've set the max size of such messages at 128 KB (random number), but
you can tune it by setting MAXMSG_USER to something else and restarting 
Hobbit. Note that as always, OS limits may need to be tweaked since this
adds an extra shared memory segment and a couple of semaphore items. If
you suddenly cannot start Hobbit and it complains about "cannot setup
user channel", then that's your problem.


Henrik

-------------- next part --------------
--- hobbitd/hobbitd.c	2007/02/02 11:30:48	1.260
+++ hobbitd/hobbitd.c	2007/02/07 11:39:39
@@ -188,6 +188,7 @@
 hobbitd_channel_t *enadischn = NULL;	/* Receives "enable" and "disable" messages */
 hobbitd_channel_t *clientchn = NULL;	/* Receives "client" messages */
 hobbitd_channel_t *clichgchn = NULL;	/* Receives "clichg" messages */
+hobbitd_channel_t *userchn   = NULL;	/* Receives "usermsg" messages */
 
 #define NO_COLOR (COL_COUNT)
 static char *colnames[COL_COUNT+1];
@@ -637,13 +638,14 @@
 			break;
 
 		  case C_NOTES:
+		  case C_USER:
 			n = snprintf(channel->channelbuf,  (bufsz-5),
 				"@@%s#%u/%s|%d.%06d|%s|%s\n%s", 
 				channelmarker, channel->seq, hostname, (int) tstamp.tv_sec, (int) tstamp.tv_usec,
 				sender, hostname, msg);
 			if (n > (bufsz-5)) {
-				errprintf("Oversize notes msg from %s for %s:%s truncated (n=%d, limit=%d)\n", 
-					sender, hostname, log->test->name, n, bufsz);
+				errprintf("Oversize notes msg from %s for %s truncated (n=%d, limit=%d)\n", 
+					sender, hostname, n, bufsz);
 			}
 			*(channel->channelbuf + bufsz - 5) = '\0';
 			break;
@@ -1294,6 +1296,13 @@
 	dbgprintf("<-handle_notes\n");
 }
 
+void handle_usermsg(char *msg, char *sender, char *hostname)
+{
+	dbgprintf("->handle_usermsg\n");
+	posttochannel(userchn, channelnames[C_USER], msg, sender, hostname, NULL, NULL);
+	dbgprintf("<-handle_usermsg\n");
+}
• void handle_enadis(int enabled, conn_t *msg, char *sender)
 {
 	char *firstline = NULL, *hosttest = NULL, *durstr = NULL, *txtstart = NULL;
@@ -2515,18 +2524,18 @@
 			handle_status(msg->buf, sender, h->hostname, t->name, NULL, log, color, NULL);
 		}
 	}
-	else if (strncmp(msg->buf, "notes", 5) == 0) {
+	else if ((strncmp(msg->buf, "notes", 5) == 0) || (strncmp(msg->buf, "usermsg", 7) == 0)) {
 		char *hostname, *bhost, *ehost, *p;
 		char savechar;
 
-		bhost = msg->buf + strlen("notes"); bhost += strspn(bhost, " \t");
+		bhost = msg->buf + strcspn(msg->buf, " \t\r\n"); bhost += strspn(bhost, " \t");
 		ehost = bhost + strcspn(bhost, " \t\r\n");
 		savechar = *ehost; *ehost = '\0';
 		hostname = strdup(bhost);
 		*ehost = savechar;
 
 		p = hostname; while ((p = strchr(p, ',')) != NULL) *p = '.';
-		if (*hostname == '\0') { errprintf("Invalid notes message from %s - blank hostname\n", sender); xfree(hostname); hostname = NULL; }
+		if (*hostname == '\0') { errprintf("Invalid notes/user message from %s - blank hostname\n", sender); xfree(hostname); hostname = NULL; }
 
 		if (hostname) {
 			char *hname, hostip[IP_ADDR_STRLEN];
@@ -2537,12 +2546,27 @@
 			if (hname == NULL) {
 				log_ghost(hostname, sender, msg->buf);
 			}
-			else if (!oksender(maintsenders, NULL, msg->addr.sin_addr, msg->buf)) {
-				/* Invalid sender */
-				errprintf("Invalid notes message - sender %s not allowed for host %s\n", sender, hostname);
-			}
 			else {
-				handle_notes(msg->buf, sender, hostname);
+				if (*msg->buf == 'n') {
+					/* "notes" message */
+					if (!oksender(maintsenders, NULL, msg->addr.sin_addr, msg->buf)) {
+						/* Invalid sender */
+						errprintf("Invalid notes message - sender %s not allowed for host %s\n", sender, hostname);
+					}
+					else {
+						handle_notes(msg->buf, sender, hostname);
+					}
+				}
+				else if (*msg->buf == 'u') {
+					/* "usermsg" message */
+					if (!oksender(statussenders, NULL, msg->addr.sin_addr, msg->buf)) {
+						/* Invalid sender */
+						errprintf("Invalid user message - sender %s not allowed for host %s\n", sender, hostname);
+					}
+					else {
+						handle_usermsg(msg->buf, sender, hostname);
+					}
+				}
 			}
 
 			xfree(hostname);
@@ -4199,6 +4223,8 @@
 	if (clientchn == NULL) { errprintf("Cannot setup client channel\n"); return 1; }
 	clichgchn  = setup_channel(C_CLICHG, CHAN_MASTER);
 	if (clichgchn == NULL) { errprintf("Cannot setup clichg channel\n"); return 1; }
+	userchn  = setup_channel(C_USER, CHAN_MASTER);
+	if (userchn == NULL) { errprintf("Cannot setup user channel\n"); return 1; }
 
 	errprintf("Setting up logfiles\n");
 	setvbuf(stdout, NULL, _IONBF, 0);
--- hobbitd/hobbitd_buffer.c	2006/05/25 20:53:34	1.8
+++ hobbitd/hobbitd_buffer.c	2007/02/07 11:22:44
@@ -34,6 +34,7 @@
 		  case C_STACHG: v = getenv("MAXMSG_STACHG"); defvalue = shbufsz(C_STATUS); break;
 		  case C_PAGE:   v = getenv("MAXMSG_PAGE");   defvalue = shbufsz(C_STATUS); break;
 		  case C_ENADIS: v = getenv("MAXMSG_ENADIS"); defvalue =  32; break;
+		  case C_USER:   v = getenv("MAXMSG_USER");   defvalue = 128; break;
 		  default: break;
 		}
 
--- hobbitd/hobbitd_buffer.h	2006/05/25 20:53:34	1.3
+++ hobbitd/hobbitd_buffer.h	2007/02/07 11:22:06
@@ -11,7 +11,7 @@
 #ifndef __HOBBITD_BUFFER_H__
 #define __HOBBITD_BUFFER_H__
 
-enum msgchannels_t { C_STATUS=1, C_STACHG, C_PAGE, C_DATA, C_NOTES, C_ENADIS, C_CLIENT, C_CLICHG, C_LAST };
+enum msgchannels_t { C_STATUS=1, C_STACHG, C_PAGE, C_DATA, C_NOTES, C_ENADIS, C_CLIENT, C_CLICHG, C_USER, C_LAST };
 
 extern unsigned int shbufsz(enum msgchannels_t chnid);
 #endif
--- hobbitd/hobbitd_ipc.c	2006/07/20 16:06:41	1.30
+++ hobbitd/hobbitd_ipc.c	2007/02/07 11:23:33
@@ -49,6 +49,7 @@
 	"enadis",
 	"client",
 	"clichg",
+	"user",
 	NULL
 };
list Stef Coene · Wed, 7 Feb 2007 13:11:29 +0100 ·
quoted from Henrik Størner
On Wednesday 07 February 2007 12:50, Henrik Stoerner wrote:
The attached patch should do it. It creates a "user" channel that is fed
the messages you send with
   $BB $BBDISP "usermsg HOSTNAME ... your custom message here ..."

On the server side, run
   hobbitd_channel --channel=user YOURCUSTOMCOMMAND
to pick up the messages.

I've set the max size of such messages at 128 KB (random number), but
you can tune it by setting MAXMSG_USER to something else and restarting
Hobbit. Note that as always, OS limits may need to be tweaked since this
adds an extra shared memory segment and a couple of semaphore items. If
you suddenly cannot start Hobbit and it complains about "cannot setup
user channel", then that's your problem.


Henrik
Henrik, if you are ever in Belgium of the Netherlands, let me know, and I will 
be you a drink.
Nice job.


Stef
list Charles Goyard · Wed, 7 Feb 2007 13:48:00 +0100 ·
quoted from Stef Coene
Henrik Stoerner wrote :
The attached patch should do it. It creates a "user" channel
Well, same thing, if you come to France, be my guest :)

Will this patch be integrated in the mainstream hobbit ?

Regards,

-- 
Charles Goyard - user-98f9625a7a59@xymon.invalid - (+33) 1 45 38 01 31
list Henrik Størner · Wed, 7 Feb 2007 14:41:52 +0100 ·
quoted from Charles Goyard
On Wed, Feb 07, 2007 at 01:48:00PM +0100, Charles Goyard wrote:
Henrik Stoerner wrote :
The attached patch should do it. It creates a "user" channel
Well, same thing, if you come to France, be my guest :)
Thanks - I'll let everyone know in advance if I plan to go abroad :-)
Will this patch be integrated in the mainstream hobbit ?
In some form, yes. I may change it slighly so you can choose how many
such channels you want - with the default being zero. But that won't
affect how it works from your point of view, so feel free to apply this 
patch and use it.


Regards,
Henrik
list Stef Coene · Wed, 7 Feb 2007 15:28:52 +0100 ·
quoted from Henrik Størner
On Wednesday 07 February 2007 14:41, Henrik Stoerner wrote:
In some form, yes. I may change it slighly so you can choose how many
such channels you want - with the default being zero. But that won't
affect how it works from your point of view, so feel free to apply this
patch and use it.
Since you are acting fast in writing nice patches, I also need ssl support ;)


Stef