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 mailq_rcsid[] = "$Id: do_mailq.c 7026 2012-07-13 14:05:20Z storner $";
12
do_mailq_rrd(char * hostname,char * testname,char * classname,char * pagepaths,char * msg,time_t tstamp)13 int do_mailq_rrd(char *hostname, char *testname, char *classname, char *pagepaths, char *msg, time_t tstamp)
14 {
15 static char *mailq_params[] = { "DS:mailq:GAUGE:600:0:U", NULL };
16 static void *mailq_tpl = NULL;
17
18 char *p;
19 char *inqueue, *outqueue;
20 int mailq, inq, outq;
21
22 if (mailq_tpl == NULL) mailq_tpl = setup_template(mailq_params);
23
24 /*
25 * The normail "mailq" report only has a "... N requests" line and a single graph.
26 * Erik's enhanced script has both an incoming and an outgoing mail queue, with
27 * two different RRD's. We'll try to handle both setups.
28 */
29
30 outqueue = strstr(msg, "\nMail queue out:");
31 inqueue = strstr(msg, "\nMail queue in:");
32 if (inqueue && outqueue) {
33 /* Dual queue message */
34
35 /* Skip the "Mail queue X" line */
36 outqueue = strchr(outqueue+1, '\n');
37 inqueue = strchr(inqueue+1, '\n');
38 if ((outqueue == NULL) || (inqueue == NULL)) return 0;
39 outqueue++; inqueue++;
40
41 /* Next line has "&green Mail Queue (26 requests)". Cut string at end-of-line */
42 p = strchr(outqueue, '\n'); if (p) *p = '\0';
43 p = strchr(inqueue, '\n'); if (p) *p = '\0';
44
45 /* Skip until we find a number, and get the digit. */
46 p = outqueue + strcspn(outqueue, "0123456789"); outq = atoi(p);
47 p = inqueue + strcspn(inqueue, "0123456789"); inq = atoi(p);
48
49 /* Update RRD's */
50 setupfn("%s.rrd", "mailqin");
51 snprintf(rrdvalues, sizeof(rrdvalues), "%d:%d", (int)tstamp, inq);
52 create_and_update_rrd(hostname, testname, classname, pagepaths, mailq_params, mailq_tpl);
53
54 setupfn("%s.rrd", "mailqout");
55 snprintf(rrdvalues, sizeof(rrdvalues), "%d:%d", (int)tstamp, outq);
56 create_and_update_rrd(hostname, testname, classname, pagepaths, mailq_params, mailq_tpl);
57 return 0;
58
59 }
60 else {
61 char *valptr;
62
63 /* Looking for "... N requests ... " */
64 valptr = strstr(msg, "requests");
65 if (valptr) {
66 /* Go back past any whitespace before "requests" */
67 do { valptr--; } while ((valptr > msg) && (*valptr != '\n') && isspace((int)*valptr));
68
69 /* Go back to the beginning of the number */
70 while ((valptr > msg) && isdigit((int) *(valptr-1))) valptr--;
71
72 mailq = atoi(valptr);
73
74 setupfn("%s.rrd", "mailq");
75 snprintf(rrdvalues, sizeof(rrdvalues), "%d:%d", (int)tstamp, mailq);
76 return create_and_update_rrd(hostname, testname, classname, pagepaths, mailq_params, mailq_tpl);
77 }
78 }
79
80 return 0;
81 }
82
83