[Xymon] Patch: filelist option for graph page

Stef Coene stef.coene at docum.org
Thu Feb 11 09:47:59 CET 2016


Hi,

This patch enhances the graph creation pages and add a filelist option.
This option can be used to limit what will be graphed. When the graph has 
FXPATTERN it will limit the matched files to what's specified in the filelist 
option.
This is handy if you want to generate custom graphs.

Example: this will create a network graph of only device eth0
showgraph.sh?host=host01service=ifstat&filelist=eth0&action=menu


Stef
-------------- next part --------------
diff -Naur xymon-4.3.25.ori/web/showgraph.c xymon-4.3.25/web/showgraph.c
--- xymon-4.3.25.ori/web/showgraph.c	2015-10-01 16:42:42.000000000 +0200
+++ xymon-4.3.25/web/showgraph.c	2016-02-11 09:04:28.952369144 +0100
@@ -49,6 +49,9 @@
 #endif
 
 
+char **filelist = NULL;
+int filelistmatch = 0;
+int filelistsize = 0;
 char *hostname = NULL;
 char **hostlist = NULL;
 int hostlistsize = 0;
@@ -220,6 +223,29 @@
 			xfree(hnames);
 			if (hostlist) hostname = hostlist[0];
 		}
+		else if (strcmp(cwalk->name, "filelist") == 0) {
+			char *filehnames = strdup(cwalk->value);
+         char *filename = NULL;
+
+			filename = strtok_r(cwalk->value, ",", &stp);
+			while (filename) {
+				if (filelist == NULL) {
+					filelistsize = 1;
+					filelist = (char **)malloc(sizeof(char *));
+					filelist[0] = strdup(filename);
+				}
+				else {
+					filelistsize++;
+					filelist = (char **)realloc(filelist, (filelistsize * sizeof(char *)));
+					filelist[filelistsize-1] = strdup(filename);
+				}
+
+				filename = strtok_r(NULL, ",", &stp);
+			}
+
+			xfree(filehnames);
+			/* if (filelist) filename = filelist[0]; */
+		}
 		else if (strcmp(cwalk->name, "service") == 0) {
 			service = strdup(cwalk->value);
 		}
@@ -713,6 +739,17 @@
 		addtobuffer(result, urlencode(hostname));
 	}
 
+	if (filelist) {
+	   addtobuffer(result, "&filelist=");
+      int i;
+
+      addtobuffer(result, urlencode(filelist[0]));
+      for (i = 1; (i < filelistsize); i++) {
+         addtobuffer(result, ",");
+         addtobuffer(result, urlencode(filelist[i]));
+      }
+   }
+
 	addtobuffer(result, "&color="); addtobuffer(result, colorname(bgcolor));
 	if (service) {
 		addtobuffer(result, "&service=");
@@ -999,6 +1036,21 @@
 			/* We have a matching file! */
 			rrddbs[rrddbcount].rrdfn = strdup(d->d_name);
 			if (pcre_copy_substring(d->d_name, ovector, result, 1, param, sizeof(param)) > 0) {
+
+            /* Nakijken of we een lijst hebben van rrd's die we moeten machen */
+	         if (filelist) {
+               int i;
+			      filelistmatch = 0 ;
+               for (i = 0; (i < filelistsize); i++) {
+                  if ( strcmp(filelist[i],param) == 0 ) {
+			            filelistmatch = 1 ;
+                  }
+               }
+               if (!filelistmatch) {
+                  continue ;
+               }
+            }
+
 				/*
 				 * This is ugly, but I cannot find a pretty way of un-mangling
 				 * the disk- and http-data that has been molested by the back-end.
@@ -1034,7 +1086,8 @@
 				rrddbsize += 5;
 				rrddbs = (rrddb_t *)realloc(rrddbs, (rrddbsize+1) * sizeof(rrddb_t));
 			}
-		}
+		} /* While loop in directory */
+
 		pcre_free(pat);
 		if (expat) pcre_free(expat);
 		closedir(dir);
diff -Naur xymon-4.3.25.ori/xymond/webfiles/zoom.js xymon-4.3.25/xymond/webfiles/zoom.js
--- xymon-4.3.25.ori/xymond/webfiles/zoom.js	2015-10-17 06:09:08.000000000 +0200
+++ xymon-4.3.25/xymond/webfiles/zoom.js	2016-02-11 08:52:33.128988028 +0100
@@ -582,6 +582,7 @@
 
  var idxStr;
  var countStr;
+ var filterStr;
  var nostaleStr;
 
  gMouseObj.setEvent(e);
@@ -590,10 +591,11 @@
  graphEnd = parseInt(gUrlObj.getUrlParameterValue("graph_end"));
  graphTop = parseFloat(gUrlObj.getUrlParameterValue("upper"));
  graphBottom = parseFloat(gUrlObj.getUrlParameterValue("lower"));
- haveGraphLimits = (gUrlObj.getUrlParameterValue("upper") != undefined) && (gUrlObj.getUrlParameterValue("lower") != undefined);
+ // haveGraphLimits = (gUrlObj.getUrlParameterValue("upper") != undefined) && (gUrlObj.getUrlParameterValue("lower") != undefined);
 
  idxStr = "";
  countStr = "";
+ filterStr = "";
  nostaleStr = "";
 
  if ((gMouseObj.rightButtonPressed()) && (insideZoomBox())) {
@@ -610,6 +612,7 @@
   var dispName = gUrlObj.getUrlParameterValue("disp");
   var firstIdx = gUrlObj.getUrlParameterValue("first");
   var nostale =  gUrlObj.getUrlParameterValue("nostale");
+  var filter =  gUrlObj.getUrlParameterValue("filter");
   var idxCount =  gUrlObj.getUrlParameterValue("count");
   var graphWidth = gUrlObj.getUrlParameterValue("graph_width");
   var graphHeight = gUrlObj.getUrlParameterValue("graph_height");
@@ -621,11 +624,14 @@
   if (idxCount != "") {
      countStr = "&count=" + idxCount; 
   }
+  if (filter != "") {
+     filterStr = "&filter=" + filter; 
+  }
   if (nostale != "") {
      nostaleStr = "&nostale"; 
   }
 
-  open(urlBase + "&host=" + host + "&service=" + service + "&disp=" + dispName + idxStr + countStr + nostaleStr + "&graph_start=" + newGraphStart + "&graph_end=" + newGraphEnd + "&graph_height=" + graphHeight + "&graph_width=" + graphWidth + "&color=" + bgColor, "_self");
+  open(urlBase + "&host=" + host + "&service=" + service + "&disp=" + dispName + idxStr + countStr + filterStr + nostaleStr + "&graph_start=" + newGraphStart + "&graph_end=" + newGraphEnd + "&graph_height=" + graphHeight + "&graph_width=" + graphWidth + "&color=" + bgColor, "_self");
  }
 
  if ((gMouseObj.leftButtonPressed()) && (gMouseObj.dragging)) {
@@ -672,6 +678,7 @@
    var firstIdx = gUrlObj.getUrlParameterValue("first");
    var nostale =  gUrlObj.getUrlParameterValue("nostale");
    var idxCount =  gUrlObj.getUrlParameterValue("count");
+   var filter =  gUrlObj.getUrlParameterValue("filter");
    var graphWidth = gUrlObj.getUrlParameterValue("graph_width");
    var graphHeight = gUrlObj.getUrlParameterValue("graph_height");
    var bgColor = gUrlObj.getUrlParameterValue("color");
@@ -682,11 +689,14 @@
    if (idxCount != "") {
       countStr = "&count=" + idxCount; 
    }
+   if (filter != "") {
+      filterStr = "&filter=" + filter; 
+   }
    if (nostale != "") {
       nostaleStr = "&nostale"; 
    }
 
-   newURL = urlBase + "&host=" + host + "&service=" + service + "&disp=" + dispName + idxStr + countStr + nostaleStr + "&graph_start=" + newGraphStart + "&graph_end=" + newGraphEnd + "&graph_height=" + graphHeight + "&graph_width=" + graphWidth + "&color=" + bgColor;
+   newURL = urlBase + "&host=" + host + "&service=" + service + "&disp=" + dispName + idxStr + countStr + filterStr + nostaleStr + "&graph_start=" + newGraphStart + "&graph_end=" + newGraphEnd + "&graph_height=" + graphHeight + "&graph_width=" + graphWidth + "&color=" + bgColor;
 
    if (haveGraphLimits) {
       var OnePixelY = (graphTop - graphBottom) / gZoomGraphObj.zoomBoxHeight; // Represent # of units on Y axis for 1 pixel on the graph


More information about the Xymon mailing list