Xymon Mailing List Archive search

MRTG-based Graphs in Trends Section

3 messages in this thread

list Alan F. *hs Oktay · Thu, 12 May 2005 12:28:31 -0400 ·
Hey everyone.

 
Love Hobbit!  It's fast and configurable.

 
We are having trouble with the above.  The problem deals with the Title
Tag in the MRTG configuration file of the host.  I have several routers
which contain many interfaces being monitored.  Unless we create a
separate rrd configuration section for each interface, the title of the
graph is the same.

 
Any way to have Hobbit read the Title Tag in the MRTG Configuration File
and thus label the graphs accordingly?

 
Thanks everyone...

Alan
list Henrik Størner · Sun, 15 May 2005 09:53:50 +0200 ·
quoted from Alan F. *hs Oktay
On Thu, May 12, 2005 at 12:28:31PM -0400, Oktay, Alan F. *HS wrote:
Any way to have Hobbit read the Title Tag in the MRTG Configuration File
and thus label the graphs accordingly?
Not directly, but the attached patch lets you have an external
script decide what the title is.

I've tried it on my own MRTG setup and it appears to work fine.
I used this script to generate the title from mrtg.cfg (note that
you may have to change the permissions on mrtg.cfg to let the 
CGI user read it):

#!/bin/sh

HOSTNAME="$1"; shift
GTYPE="$1"; shift
LEGEND="$1"; shift

RRD="$1"; shift
#echo "RRD=$RRD, rest is $*" >>/tmp/title.log

MRTGSET="`echo $RRD | sed -e's/\.rrd$//'`"
#echo "MRTGSET=$MRTGSET" >>/tmp/title.log

MRTGTITLE=`grep -i "Title\[$MRTGSET\]:" /etc/mrtg.cfg | cut -d: -f2-`
#echo "TITLE=$MRTGTITLE" >>/tmp/title.log

echo "$MRTGTITLE $LEGEND"
exit 0


Regards,
Henrik

-------------- next part --------------
--- hobbitd/hobbitgraph.c	2005/05/07 09:24:20	1.28
+++ hobbitd/hobbitgraph.c	2005/05/15 07:40:44
@@ -11,7 +11,7 @@
 /*                                                                            */
 /*----------------------------------------------------------------------------*/
 
-static char rcsid[] = "$Id: hobbitgraph.c,v 1.28 2005/05/07 09:24:20 henrik Exp $";
+static char rcsid[] = "$Id: hobbitgraph.c,v 1.30 2005/05/15 07:40:32 henrik Exp $";
 
 #include <limits.h>
 #include <stdio.h>
@@ -734,7 +734,35 @@
 	qsort(&rrddbs[0], rrddbcount, sizeof(rrddb_t), rrd_name_compare);
 
 	/* Setup the title */
-	sprintf(graphtitle, "%s %s %s", displayname, gdef->title, glegend);
+	if (!gdef->title) gdef->title = strdup("");
+	if (strncmp(gdef->title, "exec:", 5) == 0) {
+		char *pcmd;
+		int i, pcmdlen = 0;
+		FILE *pfd;
+		char *p;
• +		pcmdlen = strlen(gdef->title+5) + strlen(displayname) + strlen(service) + strlen(glegend) + 5;
+		for (i=0; (i<rrddbcount); i++) pcmdlen += (strlen(rrddbs[i].rrdfn) + 3);
• +		p = pcmd = (char *)malloc(pcmdlen+1);
+		p += sprintf(p, "%s %s %s \"%s\"", gdef->title+5, displayname, service, glegend);
+		for (i=0; (i<rrddbcount); i++) {
+			if ((firstidx == -1) || ((i >= firstidx) && (i <= lastidx))) {
+				p += sprintf(p, " \"%s\"", rrddbs[i].rrdfn);
+			}
+		}
+		pfd = popen(pcmd, "r");
+		if (pfd) {
+			fgets(graphtitle, sizeof(graphtitle), pfd);
+			pclose(pfd);
+		}
• +		/* Drop any newline at end of the title */
+		p = strchr(graphtitle, '\n'); if (p) *p = '\0';
+	}
+	else {
+		sprintf(graphtitle, "%s %s %s", displayname, gdef->title, glegend);
+	}
 
 	/*
 	 * Setup the arguments for calling rrd_graph.
list Eric E *hs Schwimmer · Tue, 17 May 2005 14:53:19 -0400 ·
Henrik,

Works great! Thanks so much!

For those that dont want to read the c code, you need to replace the title
in your [mrtg] stanza in the hobbitgraph.cgi file with something like the following:

TITLE exec:/usr/local/hobbit/server/bin/mrtg-title.sh

... or wherever you saved the shell script below to.

One small change I made to the shell script was to change the MRTGTITLE capture line to:

MRTGTITLE=`grep -i "Title\[$MRTGSET\]:" /usr/local/mrtg/cfg/$HOSTNAME.cfg | cut -d: -f2-`

...since our hosts our configured on a per-file basis and included from the main mrtg.conf

Thanks again!
-Eric


-----Original Message-----
From:	Henrik Stoerner [mailto:user-ce4a2c883f75@xymon.invalid]
Sent:	Sun 5/15/2005 3:53 AM
To:	user-ae9b8668bcde@xymon.invalid
Cc:	
Subject:	Re: [hobbit] MRTG-based Graphs in Trends Section
quoted from Henrik Størner
On Thu, May 12, 2005 at 12:28:31PM -0400, Oktay, Alan F. *HS wrote:
Any way to have Hobbit read the Title Tag in the MRTG Configuration File
and thus label the graphs accordingly?
Not directly, but the attached patch lets you have an external
script decide what the title is.

I've tried it on my own MRTG setup and it appears to work fine.
I used this script to generate the title from mrtg.cfg (note that
you may have to change the permissions on mrtg.cfg to let the 
CGI user read it):

#!/bin/sh

HOSTNAME="$1"; shift
GTYPE="$1"; shift
LEGEND="$1"; shift

RRD="$1"; shift
#echo "RRD=$RRD, rest is $*" >>/tmp/title.log

MRTGSET="`echo $RRD | sed -e's/\.rrd$//'`"
#echo "MRTGSET=$MRTGSET" >>/tmp/title.log

MRTGTITLE=`grep -i "Title\[$MRTGSET\]:" /etc/mrtg.cfg | cut -d: -f2-`
#echo "TITLE=$MRTGTITLE" >>/tmp/title.log

echo "$MRTGTITLE $LEGEND"
exit 0


Regards,
Henrik