1 /*----------------------------------------------------------------------------*/
2 /* Xymon RRD handler module.                                                  */
3 /*                                                                            */
4 /* Copyright (C) 2004-2011 Henrik Storner <henrik@hswn.dk>                    */
5 /*                                                                            */
6 /* This program is released under the GNU General Public License (GPL),       */
7 /* version 2. See the file "COPYING" for details.                             */
8 /*                                                                            */
9 /*----------------------------------------------------------------------------*/
10 
11 static char xymond_rcsid[] = "$Id: do_xymond.c 7026 2012-07-13 14:05:20Z storner $";
12 
do_xymond_rrd(char * hostname,char * testname,char * classname,char * pagepaths,char * msg,time_t tstamp)13 int do_xymond_rrd(char *hostname, char *testname, char *classname, char *pagepaths, char *msg, time_t tstamp)
14 {
15 	static char *xymond_params[] = { "DS:inmessages:DERIVE:600:0:U",
16 					 "DS:statusmessages:DERIVE:600:0:U",
17 					 "DS:combomessages:DERIVE:600:0:U",
18 					 "DS:pagemessages:DERIVE:600:0:U",
19 					 "DS:summarymessages:DERIVE:600:0:U",
20 					 "DS:datamessages:DERIVE:600:0:U",
21 					 "DS:notesmessages:DERIVE:600:0:U",
22 					 "DS:enablemessages:DERIVE:600:0:U",
23 					 "DS:disablemessages:DERIVE:600:0:U",
24 					 "DS:ackmessages:DERIVE:600:0:U",
25 					 "DS:configmessages:DERIVE:600:0:U",
26 					 "DS:querymessages:DERIVE:600:0:U",
27 					 "DS:boardmessages:DERIVE:600:0:U",
28 					 "DS:listmessages:DERIVE:600:0:U",
29 					 "DS:logmessages:DERIVE:600:0:U",
30 					 "DS:dropmessages:DERIVE:600:0:U",
31 					 "DS:renamemessages:DERIVE:600:0:U",
32 					 "DS:statuschmsgs:DERIVE:600:0:U",
33 					 "DS:stachgchmsgs:DERIVE:600:0:U",
34 					 "DS:pagechmsgs:DERIVE:600:0:U",
35 					 "DS:datachmsgs:DERIVE:600:0:U",
36 					 "DS:noteschmsgs:DERIVE:600:0:U",
37 					 "DS:enadischmsgs:DERIVE:600:0:U",
38 					 NULL };
39 	static void *xymond_tpl        = NULL;
40 
41 	struct {
42 		char *marker;
43 		unsigned long val;
44 	} xymond_data[] = {
45 		{ "\nIncoming messages", 0 },
46 		{ "\n- status", 0 },
47 		{ "\n- combo", 0 },
48 		{ "\n- page", 0 },
49 		{ "\n- summary", 0 },
50 		{ "\n- data", 0 },
51 		{ "\n- notes", 0 },
52 		{ "\n- enable", 0 },
53 		{ "\n- disable", 0 },
54 		{ "\n- ack", 0 },
55 		{ "\n- config", 0 },
56 		{ "\n- query", 0 },
57 		{ "\n- xymondboard", 0 },
58 		{ "\n- xymondlist", 0 },
59 		{ "\n- xymondlog", 0 },
60 		{ "\n- drop", 0 },
61 		{ "\n- rename", 0 },
62 		{ "\nstatus channel messages", 0 },
63 		{ "\nstachg channel messages", 0 },
64 		{ "\npage   channel messages", 0 },
65 		{ "\ndata   channel messages", 0 },
66 		{ "\nnotes  channel messages", 0 },
67 		{ "\nenadis channel messages", 0 },
68 		{ NULL, 0 }
69 	};
70 
71 	int	i, gotany = 0;
72 	char	*p;
73 	char	valstr[50];
74 
75 	MEMDEFINE(valstr);
76 
77 	if (xymond_tpl == NULL) xymond_tpl = setup_template(xymond_params);
78 
79 	snprintf(rrdvalues, sizeof(rrdvalues), "%d", (int)tstamp);
80 	i = 0;
81 	while (xymond_data[i].marker) {
82 		p = strstr(msg, xymond_data[i].marker);
83 		if (p) {
84 			if (*p == '\n') p++;
85 			p += strcspn(p, ":\r\n");
86 			if (*p == ':') {
87 				xymond_data[i].val = strtoul(p+1, NULL, 10);
88 				gotany++;
89 				snprintf(valstr, sizeof(valstr), ":%lu", xymond_data[i].val);
90 				strncat(rrdvalues, valstr, sizeof(rrdvalues)-strlen(rrdvalues)-1);
91 			}
92 			else strcat(rrdvalues, ":U");
93 		}
94 		else strcat(rrdvalues, ":U");
95 
96 		i++;
97 	}
98 
99 	if (gotany) {
100 		if (strcmp("xymond", testname) != 0) {
101 			setupfn2("%s.%s.rrd", "xymond", testname);
102 		}
103 		else {
104 			setupfn("%s.rrd", "xymond");
105 		}
106 
107 		MEMUNDEFINE(valstr);
108 		return create_and_update_rrd(hostname, testname, classname, pagepaths, xymond_params, xymond_tpl);
109 	}
110 
111 	MEMUNDEFINE(valstr);
112 	return 0;
113 }
114 
115