[hobbit] Host Notes

Epp, Matthew Contractor PEO EIS AKO matthew.epp at us.army.mil
Tue Aug 15 00:48:19 CEST 2006


> 6) another thing regarding notes, it should be nice if the notes system
> will allow the user to put also some kind of web links on the notes
> pages of hosts so that one can put links to real documentation of that
> host or generic documentation regarding for example network
> infrastructure into the network objects monitored). It should be also
> nice if the documentation itself is saved in some kind of xml or text
> file and if a html file exist in the notes directory a link to it is
> visible on the notes pages... I don't know how clear this one is :P but
> just to explain I'm starting to deploy cfg2html on every machine because
> we need a full documentation of what's on every machine but it would be
> really nice to have

Since there seems to be a real need for some easily configured notes system,
I decided to go ahead and create a patch file for the mod that I made. I
call it "Comments" but feel free to implement it however you wish. You only
need to patch one source file and recompile. This will put your notes at the
bottom of every bb-hostsvc.sh page. Some of you may not want this, but I
wrote this for Big Brother when there wasn't any formal notes system. If
someone would like to adjust this for appearing in a different area, please
do.

Add these lines to the etc/hobbitserver.cfg file:
BBCOMMENTS="$BBHOME/comments"                   # The location of the
textfiles for service comments
BBCOMMCONF="$BBCOMMENTS/comments.conf"          # The name of the Comments
configuration file

Create the $BBHOME/comments directory, and then a comments.conf file in
there. Here's a sample starter file:

---[SNIP]---
# This is the configuration file for the Special Instructions section on
# all alert pages. To create a new alert message, put whatever
# text you want into a new file, call it anything you like, but try to
# stick to the convention of CI.service. Wildcards also work, but place
# them at the bottom of the file, so that absolute matches can override
# the wildcard entries.
 
# NOTE: Make sure there are no trailing spaces at the end of the line.
#       I'll be adding in error checking code for that asap. If someone
#       wants to fix this, please post the code.
 
# Portal Application Servers rules group
webserver*.disk webservers.disk
database*.cpu databases.cpu
#
# Place all wildcard matches below here
#

*.http ALL.http

#
# Point all conn tests to the same file
#
 
*.conn ALL.conn
---[SNIP]---

Then make sure to create the comment files themselves, like "ALL.conn" and
put them in the same directory as the conf. You can use any html code you'd
like:

---[SNIP]---
<table border=5 bordercolor=red><caption><B><font color=white>Special
Instructions:</caption><tr><td><B><font color=white>
 
Put your comments in here. Additional HTML formatting is allowed, so feel
free to insert coloring, links, whatever.
 
</td></tr></table><br>
---[SNIP]---


Now for the patch. This is the first patch file I've ever had to make, so
don't scream at me too much if I didn't do this right. :)

--- hobbit-4.2.0/lib/htmllog.c	2006-08-09 20:10:16.000000000 +0000
+++ hobbit-4.2.0.modified/lib/htmllog.c	2006-08-10 21:46:44.000004000 +0000
@@ -11,7 +11,7 @@
 /*
*/
 
/*--------------------------------------------------------------------------
--*/
 
-static char rcsid[] = "$Id: htmllog.c,v 1.51 2006/05/25 14:55:41 henrik Rel
$";
+static char rcsid[] = "$Id: htmllog.c,v 1.51 2006/05/25 14:55:41 henrik Exp
$";
 
 #include <ctype.h>
 #include <stdlib.h>
@@ -22,6 +22,7 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <fnmatch.h>
 
 #include "libbbgen.h"
 #include "version.h"
@@ -122,6 +123,105 @@
 	} while (restofmsg);
 }
 
+/*
+ * Here's our function to print out the service comment file
+ */
+void printcomment(char *hostname, char *service)
+{
+int commentstatres;
+int commentretc;
+int commentpage_size;
+char *basename;
+char *bbcomment;
+char *commentpage;
+char *func_matchfile = "";
+char *matchfile;
+char conffile[PATH_MAX];
+char func_matchfilename[PATH_MAX] = "";
+char hostpat[PATH_MAX] = "";
+char matchfilename[PATH_MAX] = "";
+static char *bbcomments;
+static char commfile[PATH_MAX] = "";
+struct stat commentstatbuf;
+const char *func_hostpat;
+const char *infile;
+FILE *in;
+FILE *bbcomm;
+
+	if ( commentpage != NULL )
+		free(commentpage);
+/* Build the pattern to search for from the hostname and service */
+        sprintf(hostpat, "%s.%s", hostname, service);
+	func_hostpat = hostpat;
+
+/* Search the comments.conf file for the comment file */
+ 
+        sprintf(conffile, "%s", xgetenv("BBCOMMCONF"));
+ 
+	/*
+	* line[0] stores the input line as read,
+	*/
+	char line[1][BUFSIZ];
+	infile = conffile;
+ 
+	if((in = fopen(infile, "r")) == NULL){
+		printf("Error opening file: %s\n", conffile);
+	} else {
+		while(fgets(line[0], BUFSIZ, in)){
+			char *line_to_use = line[0];
+			func_matchfile = strtok(line_to_use, " \t");
+ 
+			if(!fnmatch(func_matchfile, func_hostpat,
FNM_NOESCAPE)){
+				func_matchfile = strtok(NULL, " ");
+				strncpy(func_matchfilename, func_matchfile,
strlen(func_matchfile) -1);
+				break;
+			}
+		}
+		fclose(in);
+	}
+	matchfile = func_matchfilename;
+/* End of reading comments.conf */
+
+	sprintf(matchfilename, "%s/%s", xgetenv("BBCOMMENTS"), matchfile);
+
+	commentstatres=stat(matchfilename, &commentstatbuf);
+	if( commentstatres == -1 ) {
+		commentpage = NULL;
+	} else {
+		commentpage_size = commentstatbuf.st_size + 4096;
+ 
+		/* Fill the buffer  */
+		commentpage = (char *) calloc(1,commentpage_size);
+ 
+		if( commentpage != NULL ) {
+			*commentpage = '\0';
+ 
+			/* Open and read comment file in one call*/
+			if( (bbcomm = fopen(matchfilename, "r")) != NULL ) {
+				commentretc =
fread(commentpage,commentstatbuf.st_size,1,bbcomm);
+				/* Was the comment file read in completely ?
*/
+				if ( commentretc != 1 || strlen(commentpage)
!= commentstatbuf.st_size ) {
+					free(commentpage);
+					commentpage = NULL;
+				} else {
+#if DEBUG
+					printf("comment: %s\n",
commentpage);
+#endif
+				}
+				fclose(bbcomm);
+			} else {
+#if DEBUG
+				printf("Error opening file %s\n",
matchfilename);
+#endif
+			}
+		}
+	}
+	/* END OF READING IN COMMENTS FILE */
+ 
+	if (commentpage != NULL) {
+                printf("<BR><BR><CENTER>%s<BR></CENTER>", commentpage);
+	}
+}
 
 void generate_html_log(char *hostname, char *displayname, char *service,
char *ip, 
 		       int color, char *sender, char *flags, 
@@ -367,6 +467,12 @@
 	}
 
 	fprintf(output,"</CENTER>\n");
+/*
+ * Here we insert our service comments from the comments.conf setup
+ * Hope this works!
+ */
+        printcomment(hostname, service);
+
 	headfoot(output, tplfile, "", "footer", color);
 }



More information about the Xymon mailing list