1 /*----------------------------------------------------------------------------*/
2 /* Xymon RRD handler module.                                                  */
3 /*                                                                            */
4 /* This module handles various "counts" messages.                             */
5 /*                                                                            */
6 /* Copyright (C) 2005-2011 Henrik Storner <henrik@hswn.dk>                    */
7 /*                                                                            */
8 /* This program is released under the GNU General Public License (GPL),       */
9 /* version 2. See the file "COPYING" for details.                             */
10 /*                                                                            */
11 /*----------------------------------------------------------------------------*/
12 
13 static char counts_rcsid[] = "$Id: do_counts.c 7026 2012-07-13 14:05:20Z storner $";
14 
do_one_counts_rrd(char * counttype,char * hostname,char * testname,char * classname,char * pagepaths,char * msg,time_t tstamp,char * params[],char * tpl)15 static int do_one_counts_rrd(char *counttype, char *hostname, char *testname, char *classname, char *pagepaths, char *msg, time_t tstamp, char *params[], char *tpl)
16 {
17 	char *boln, *eoln;
18 
19 	boln = strchr(msg, '\n'); if (boln) boln++;
20 	while (boln && *boln) {
21 		char *fn, *countstr = NULL;
22 
23 		eoln = strchr(boln, '\n'); if (eoln) *eoln = '\0';
24 
25 		fn = strtok(boln, ":"); if (fn) countstr = strtok(NULL, ":");
26 		if (fn && countstr) {
27 			char *p;
28 
29 			for (p=strchr(fn, '/'); (p); p = strchr(p, '/')) *p = ',';
30 			setupfn2("%s.%s.rrd", counttype, fn);
31 
32 			snprintf(rrdvalues, sizeof(rrdvalues), "%d:%s", (int)tstamp, countstr);
33 			create_and_update_rrd(hostname, testname, classname, pagepaths, params, tpl);
34 		}
35 
36 		boln = (eoln ? eoln+1 : NULL);
37 	}
38 
39 	return 0;
40 }
41 
42 static char *counts_params[] = { "DS:count:GAUGE:600:0:U", NULL };
43 static void *counts_tpl      = NULL;
44 static char *derive_params[] = { "DS:count:DERIVE:600:0:U", NULL };
45 static void *derive_tpl      = NULL;
46 
do_counts_rrd(char * counttype,char * hostname,char * testname,char * classname,char * pagepaths,char * msg,time_t tstamp)47 int do_counts_rrd(char *counttype, char *hostname, char *testname, char *classname, char *pagepaths, char *msg, time_t tstamp)
48 {
49 	if (counts_tpl == NULL) counts_tpl = setup_template(counts_params);
50 
51 	return do_one_counts_rrd(counttype, hostname, testname, classname, pagepaths, msg, tstamp, counts_params, counts_tpl);
52 }
53 
do_derives_rrd(char * counttype,char * hostname,char * testname,char * classname,char * pagepaths,char * msg,time_t tstamp)54 int do_derives_rrd(char *counttype, char *hostname, char *testname, char *classname, char *pagepaths, char *msg, time_t tstamp)
55 {
56 	if (derive_tpl == NULL) derive_tpl = setup_template(derive_params);
57 
58 	return do_one_counts_rrd(counttype, hostname, testname, classname, pagepaths, msg, tstamp, derive_params, derive_tpl);
59 }
60 
61