[hobbit] adding extra channel
Henrik Stoerner
henrik at hswn.dk
Wed Feb 7 12:50:53 CET 2007
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
};
More information about the Xymon
mailing list