xymon

Check-in [ee632ae4db]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add EXTIME= options for analysis and alert rules git-svn-id: http://svn.code.sf.net/p/xymon/code/branches/4.3.19@7588 44351d6e-118b-4698-b696-ce33095ecaa4
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | origin/4.3.19
Files: files | file ages | folders
SHA3-256: ee632ae4db2c4e6282486300b23bcd775d1cfb073dcdde747ab744e82ddf5dc6
User & Date: jccleaver@users.sf.net 2015-02-25 20:17:40
Context
2015-02-26
07:41
Backport trunk r7330/1: c-ares to 1.10.0, allowing build-specified CFLAGS to be passed down git-svn-id: http://svn.code.sf.net/p/xymon/code/branches/4.3.19@7589 44351d6e-118b-4698-b696-ce33095ecaa4 check-in: aec56f28b7 user: jccleaver@users.sf.net tags: trunk, origin/4.3.19
2015-02-25
20:17
Add EXTIME= options for analysis and alert rules git-svn-id: http://svn.code.sf.net/p/xymon/code/branches/4.3.19@7588 44351d6e-118b-4698-b696-ce33095ecaa4 check-in: ee632ae4db user: jccleaver@users.sf.net tags: trunk, origin/4.3.19
03:49
Fix OpenBSD or dietlibc building, via Mark Felder git-svn-id: http://svn.code.sf.net/p/xymon/code/branches/4.3.19@7585 44351d6e-118b-4698-b696-ce33095ecaa4 check-in: 4312bca79d user: jccleaver@users.sf.net tags: trunk, origin/4.3.19
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/loadalerts.c.

178
179
180
181
182
183
184

185
186
187
188
189
190
191
...
471
472
473
474
475
476
477










478
479
480
481
482
483
484
...
725
726
727
728
729
730
731

732
733
734
735
736
737
738
...
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
...
976
977
978
979
980
981
982
983

984
985
986
987
988
989
990
991
992
993
....
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
....
1150
1151
1152
1153
1154
1155
1156

1157
1158
1159
1160




1161
1162
1163
1164
1165
1166
1167
....
1200
1201
1202
1203
1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
	if (crit->exclassspec)   xfree(crit->exclassspec);
	if (crit->exclassspecre) pcre_free(crit->exclassspecre);
	if (crit->groupspec)     xfree(crit->groupspec);
	if (crit->groupspecre)   pcre_free(crit->groupspecre);
	if (crit->exgroupspec)   xfree(crit->exgroupspec);
	if (crit->exgroupspecre) pcre_free(crit->exgroupspecre);
	if (crit->timespec)      xfree(crit->timespec);

}

int load_alertconfig(char *configfn, int defcolors, int defaultinterval)
{
	/* (Re)load the configuration file without leaking memory */
	static void *configfiles = NULL;
	char fn[PATH_MAX];
................................................................................
				criteria_t *crit;

				if (firsttoken) { flush_rule(currule); currule = NULL; currcp = NULL; pstate = P_NONE; }
				val = strchr(p, '=')+1;
				crit = setup_criteria(&currule, &currcp);
				crit->timespec = strdup(val);
				firsttoken = 0;










			}
			else if (strncasecmp(p, "DURATION", 8) == 0) {
				criteria_t *crit;

				if (firsttoken) { flush_rule(currule); currule = NULL; currcp = NULL; pstate = P_NONE; }
				crit = setup_criteria(&currule, &currcp);
				if (*(p+8) == '>') {
................................................................................
				first = 0;
			}
		}
		printf(" ");
	}

	if (crit->timespec) printf("TIME=%s ", crit->timespec);

	if (crit->minduration) printf("DURATION>%d ", (crit->minduration / 60));
	if (crit->maxduration) printf("DURATION<%d ", (crit->maxduration / 60));
	if (isrecip) {
		switch (crit->sendrecovered) {
		  case SR_UNKNOWN: break;
		  case SR_WANTED: printf("RECOVERED "); break;
		  case SR_NOTWANTED: printf("NORECOVERED "); break;
................................................................................

int stoprulefound = 0;

static int criteriamatch(activealerts_t *alert, criteria_t *crit, criteria_t *rulecrit, int *anymatch, time_t *nexttime)
{
	/*
	 * See if the "crit" matches the "alert".
	 * Match on pagespec, dgspec, hostspec, svcspec, classspec, groupspec, colors, timespec, minduration, maxduration, sendrecovered
	 */

	static char *pgnames = NULL;
	int pgmatchres, pgexclres;
	time_t duration = (getcurrenttime(NULL) - alert->eventstart);
	int result, cfid = 0;
	char *pgtok, *cfline = NULL;
................................................................................
	 * Time restrictions apply to ALL messages.
	 * Before 4.2, these were only applied to ALERT messages,
	 * not RECOVERED and NOTIFY messages. This caused some
	 * unfortunate alerts in the middle of the night because
	 * some random system recovered ... not good. So apply
	 * this check to all messages.
	 */
	if (crit && crit->timespec && !timematch(xmh_item(hinfo, XMH_HOLIDAYS), crit->timespec)) {

		/* Try again in a minute */
		if (nexttime) *nexttime = getcurrenttime(NULL) + 60;
		traceprintf("Failed '%s' (time criteria)\n", cfline);
		if (!printmode) return 0; 
	}

	/* Check color. For RECOVERED messages, this holds the color of the alert, not the recovery state */
	if (crit && crit->colors) {
		result = (((1 << alert->color) & crit->colors) != 0);
		if (printmode) return 1;
................................................................................
		stopfont = "COLOR=\"#FF0000\" FACE=\"Tahoma, Arial, Helvetica\"";
	}

	fontspec = normalfont;
	stoprulefound = 0;
	while ((recip = next_recipient(alert, &first, NULL, NULL)) != NULL) {
		int mindur = 0, maxdur = INT_MAX;
		char *timespec = NULL;
		int colors = defaultcolors;
		int i, firstcolor = 1;
		int recovered = 0, notice = 0;

		count++;

		addtobuffer(buf, "<tr>");
................................................................................
		 * settings determine everything.
		 */
		if (printrule->criteria && printrule->criteria->minduration) mindur = printrule->criteria->minduration;
		if (recip->criteria && recip->criteria->minduration && (recip->criteria->minduration > mindur)) mindur = recip->criteria->minduration;
		if (printrule->criteria && printrule->criteria->maxduration) maxdur = printrule->criteria->maxduration;
		if (recip->criteria && recip->criteria->maxduration && (recip->criteria->maxduration < maxdur)) maxdur = recip->criteria->maxduration;
		if (printrule->criteria && printrule->criteria->timespec) timespec = printrule->criteria->timespec;

		if (recip->criteria && recip->criteria->timespec) {
			if (timespec == NULL) timespec = recip->criteria->timespec;
			else errprintf("Cannot handle nested timespecs yet\n");
		}





		if (printrule->criteria && printrule->criteria->colors) colors = (colors & printrule->criteria->colors);
		if (recip->criteria && recip->criteria->colors) colors = (colors & recip->criteria->colors);

		/*
		 * Recoveries are sent if
		 * - there are no recipient criteria, and the rule says yes;
................................................................................
		sprintf(l, "<td align=center>%s</td>", durationstring(maxdur));
		addtobuffer(buf, l);

		sprintf(l, "<td align=center>%s</td>", durationstring(recip->interval)); 
		addtobuffer(buf, l);

		if (timespec) sprintf(l, "<td align=center>%s</td>", timespec); else strcpy(l, "<td align=center>-</td>");

		addtobuffer(buf, l);

		addtobuffer(buf, "<td>");
		for (i = 0; (i < COL_COUNT); i++) {
			if ((1 << i) & colors) {
				sprintf(l, "%s%s", (firstcolor ? "" : ","), colorname(i));
				addtobuffer(buf, l);







>







 







>
>
>
>
>
>
>
>
>
>







 







>







 







|







 







|
>


|







 







|







 







>




>
>
>
>







 







>







178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
...
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
...
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
...
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
...
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
....
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
....
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
....
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
	if (crit->exclassspec)   xfree(crit->exclassspec);
	if (crit->exclassspecre) pcre_free(crit->exclassspecre);
	if (crit->groupspec)     xfree(crit->groupspec);
	if (crit->groupspecre)   pcre_free(crit->groupspecre);
	if (crit->exgroupspec)   xfree(crit->exgroupspec);
	if (crit->exgroupspecre) pcre_free(crit->exgroupspecre);
	if (crit->timespec)      xfree(crit->timespec);
	if (crit->extimespec)    xfree(crit->extimespec);
}

int load_alertconfig(char *configfn, int defcolors, int defaultinterval)
{
	/* (Re)load the configuration file without leaking memory */
	static void *configfiles = NULL;
	char fn[PATH_MAX];
................................................................................
				criteria_t *crit;

				if (firsttoken) { flush_rule(currule); currule = NULL; currcp = NULL; pstate = P_NONE; }
				val = strchr(p, '=')+1;
				crit = setup_criteria(&currule, &currcp);
				crit->timespec = strdup(val);
				firsttoken = 0;
			}
			else if ((strncasecmp(p, "EXTIME=", 7) == 0) || (strncasecmp(p, "EXTIMES=", 8) == 0)) {
				char *val;
				criteria_t *crit;

				if (firsttoken) { flush_rule(currule); currule = NULL; currcp = NULL; pstate = P_NONE; }
				val = strchr(p, '=')+1;
				crit = setup_criteria(&currule, &currcp);
				crit->extimespec = strdup(val);
				firsttoken = 0;
			}
			else if (strncasecmp(p, "DURATION", 8) == 0) {
				criteria_t *crit;

				if (firsttoken) { flush_rule(currule); currule = NULL; currcp = NULL; pstate = P_NONE; }
				crit = setup_criteria(&currule, &currcp);
				if (*(p+8) == '>') {
................................................................................
				first = 0;
			}
		}
		printf(" ");
	}

	if (crit->timespec) printf("TIME=%s ", crit->timespec);
	if (crit->extimespec) printf("EXTIME=%s ", crit->extimespec);
	if (crit->minduration) printf("DURATION>%d ", (crit->minduration / 60));
	if (crit->maxduration) printf("DURATION<%d ", (crit->maxduration / 60));
	if (isrecip) {
		switch (crit->sendrecovered) {
		  case SR_UNKNOWN: break;
		  case SR_WANTED: printf("RECOVERED "); break;
		  case SR_NOTWANTED: printf("NORECOVERED "); break;
................................................................................

int stoprulefound = 0;

static int criteriamatch(activealerts_t *alert, criteria_t *crit, criteria_t *rulecrit, int *anymatch, time_t *nexttime)
{
	/*
	 * See if the "crit" matches the "alert".
	 * Match on pagespec, dgspec, hostspec, svcspec, classspec, groupspec, colors, timespec, extimespec, minduration, maxduration, sendrecovered
	 */

	static char *pgnames = NULL;
	int pgmatchres, pgexclres;
	time_t duration = (getcurrenttime(NULL) - alert->eventstart);
	int result, cfid = 0;
	char *pgtok, *cfline = NULL;
................................................................................
	 * Time restrictions apply to ALL messages.
	 * Before 4.2, these were only applied to ALERT messages,
	 * not RECOVERED and NOTIFY messages. This caused some
	 * unfortunate alerts in the middle of the night because
	 * some random system recovered ... not good. So apply
	 * this check to all messages.
	 */
	if (crit && ( (crit->timespec && !timematch(xmh_item(hinfo, XMH_HOLIDAYS), crit->timespec)) || 
		      (crit->extimespec && timematch(xmh_item(hinfo, XMH_HOLIDAYS), crit->extimespec)) ) ) {
		/* Try again in a minute */
		if (nexttime) *nexttime = getcurrenttime(NULL) + 60;
		traceprintf("Failed '%s' (time/extime criteria)\n", cfline);
		if (!printmode) return 0; 
	}

	/* Check color. For RECOVERED messages, this holds the color of the alert, not the recovery state */
	if (crit && crit->colors) {
		result = (((1 << alert->color) & crit->colors) != 0);
		if (printmode) return 1;
................................................................................
		stopfont = "COLOR=\"#FF0000\" FACE=\"Tahoma, Arial, Helvetica\"";
	}

	fontspec = normalfont;
	stoprulefound = 0;
	while ((recip = next_recipient(alert, &first, NULL, NULL)) != NULL) {
		int mindur = 0, maxdur = INT_MAX;
		char *timespec = NULL; char *extimespec = NULL;
		int colors = defaultcolors;
		int i, firstcolor = 1;
		int recovered = 0, notice = 0;

		count++;

		addtobuffer(buf, "<tr>");
................................................................................
		 * settings determine everything.
		 */
		if (printrule->criteria && printrule->criteria->minduration) mindur = printrule->criteria->minduration;
		if (recip->criteria && recip->criteria->minduration && (recip->criteria->minduration > mindur)) mindur = recip->criteria->minduration;
		if (printrule->criteria && printrule->criteria->maxduration) maxdur = printrule->criteria->maxduration;
		if (recip->criteria && recip->criteria->maxduration && (recip->criteria->maxduration < maxdur)) maxdur = recip->criteria->maxduration;
		if (printrule->criteria && printrule->criteria->timespec) timespec = printrule->criteria->timespec;
		if (printrule->criteria && printrule->criteria->extimespec) extimespec = printrule->criteria->extimespec;
		if (recip->criteria && recip->criteria->timespec) {
			if (timespec == NULL) timespec = recip->criteria->timespec;
			else errprintf("Cannot handle nested timespecs yet\n");
		}
		if (recip->criteria && recip->criteria->extimespec) {
			if (extimespec == NULL) extimespec = recip->criteria->extimespec;
			else errprintf("Cannot handle nested extimespecs yet\n");
		}

		if (printrule->criteria && printrule->criteria->colors) colors = (colors & printrule->criteria->colors);
		if (recip->criteria && recip->criteria->colors) colors = (colors & recip->criteria->colors);

		/*
		 * Recoveries are sent if
		 * - there are no recipient criteria, and the rule says yes;
................................................................................
		sprintf(l, "<td align=center>%s</td>", durationstring(maxdur));
		addtobuffer(buf, l);

		sprintf(l, "<td align=center>%s</td>", durationstring(recip->interval)); 
		addtobuffer(buf, l);

		if (timespec) sprintf(l, "<td align=center>%s</td>", timespec); else strcpy(l, "<td align=center>-</td>");
		if (extimespec) sprintf(l, "<td align=center>%s</td>", extimespec); else strcpy(l, "<td align=center>-</td>");
		addtobuffer(buf, l);

		addtobuffer(buf, "<td>");
		for (i = 0; (i < COL_COUNT); i++) {
			if ((1 << i) & colors) {
				sprintf(l, "%s%s", (firstcolor ? "" : ","), colorname(i));
				addtobuffer(buf, l);

Changes to lib/loadalerts.h.

71
72
73
74
75
76
77

78
79
80
81
82
83
84
	pcre *exclassspecre;
	char *groupspec;
	pcre *groupspecre;
	char *exgroupspec;
	pcre *exgroupspecre;
	int colors;
	char *timespec;

	int minduration, maxduration;	/* In seconds */
	enum recovermsg_t sendrecovered, sendnotice;
} criteria_t;

/* This defines a recipient. There may be some criteria, and then how we send alerts to him */
typedef struct recip_t {
	int cfid;







>







71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	pcre *exclassspecre;
	char *groupspec;
	pcre *groupspecre;
	char *exgroupspec;
	pcre *exgroupspecre;
	int colors;
	char *timespec;
	char *extimespec;
	int minduration, maxduration;	/* In seconds */
	enum recovermsg_t sendrecovered, sendnotice;
} criteria_t;

/* This defines a recipient. There may be some criteria, and then how we send alerts to him */
typedef struct recip_t {
	int cfid;

Changes to xymond/alerts.cfg.5.

101
102
103
104
105
106
107



108
109
110
111
112
113
114
.sp
.BR "COLOR=color[,color]"
Rule matching an alert by color. Can be "red", "yellow", or "purple". The forms "!red", "!yellow" and "!purple" can also be used to NOT send an alert if the color is the specified one.
.sp
.BR "TIME=timespecification"
Rule matching an alert by the time-of-day. This is specified as the DOWNTIME timespecification in the hosts.cfg file.
.sp



.BR "DURATION>time, DURATION<time"
Rule matcing an alert if the event has lasted longer/shorter than the given duration. E.g. DURATION>1h (lasted longer than 1 hour) or DURATION<30 (only sends alerts the first 30 minutes). The duration is specified as a number, optionally followed by 'm' (minutes, default), 'h' (hours) or 'd' (days).
.sp
.BR RECOVERED
Rule matches if the alert has recovered from an alert state.
.sp
.BR NOTICE







>
>
>







101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
.sp
.BR "COLOR=color[,color]"
Rule matching an alert by color. Can be "red", "yellow", or "purple". The forms "!red", "!yellow" and "!purple" can also be used to NOT send an alert if the color is the specified one.
.sp
.BR "TIME=timespecification"
Rule matching an alert by the time-of-day. This is specified as the DOWNTIME timespecification in the hosts.cfg file.
.sp
.BR "EXTIME=timespecification"
Rule excluding an alert by the time-of-day. This is specified as the DOWNTIME timespecification in the hosts.cfg file.
.sp
.BR "DURATION>time, DURATION<time"
Rule matcing an alert if the event has lasted longer/shorter than the given duration. E.g. DURATION>1h (lasted longer than 1 hour) or DURATION<30 (only sends alerts the first 30 minutes). The duration is specified as a number, optionally followed by 'm' (minutes, default), 'h' (hours) or 'd' (days).
.sp
.BR RECOVERED
Rule matches if the alert has recovered from an alert state.
.sp
.BR NOTICE

Changes to xymond/analysis.cfg.5.

571
572
573
574
575
576
577







578
579
580
581
582
583
584
Rule excluding a group by matching the display-group string.

.BR "TIME=timespecification"
Rule matching by the time-of-day. This is specified as the DOWNTIME 
time specification in the hosts.cfg file.  E.g. "TIME=W:0800:2200"
applied to a rule will make this rule active only on week-days between
8AM and 10PM.








.SH DIRECTING ALERTS TO GROUPS
For some tests - e.g. "procs" or "msgs" - the right group of people
to alert in case of a failure may be different, depending on which 
of the client rules actually detected a problem. E.g. if you have
PROCS rules for a host checking both "httpd" and "sshd" processes,
then the Web admins should handle httpd-failures, whereas "sshd"







>
>
>
>
>
>
>







571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
Rule excluding a group by matching the display-group string.

.BR "TIME=timespecification"
Rule matching by the time-of-day. This is specified as the DOWNTIME 
time specification in the hosts.cfg file.  E.g. "TIME=W:0800:2200"
applied to a rule will make this rule active only on week-days between
8AM and 10PM.

.BR "EXTIME=timespecification"
Rule excluding by the time-of-day. This is also specified as the DOWNTIME 
time specification in the hosts.cfg file.  E.g. "TIME=W:0400:0600"
applied to a rule will make this rule exclude on week-days between
4AM and 6AM. This applies on top of any TIME= specification, so both
must match.

.SH DIRECTING ALERTS TO GROUPS
For some tests - e.g. "procs" or "msgs" - the right group of people
to alert in case of a failure may be different, depending on which 
of the client rules actually detected a problem. E.g. if you have
PROCS rules for a host checking both "httpd" and "sshd" processes,
then the Web admins should handle httpd-failures, whereas "sshd"

Changes to xymond/client_config.c.

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
...
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
...
434
435
436
437
438
439
440

441
442
443
444
445
446
447
...
456
457
458
459
460
461
462
463

464
465
466
467
468
469
470
...
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
...
556
557
558
559
560
561
562

563
564
565
566
567
568
569
...
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
...
675
676
677
678
679
680
681






682
683
684
685
686
687
688
....
1568
1569
1570
1571
1572
1573
1574

1575
1576
1577
1578
1579
1580
1581
1582

1583
1584
1585
1586
1587
1588
1589
....
1870
1871
1872
1873
1874
1875
1876

1877
1878
1879
1880
1881
1882
1883
....
1900
1901
1902
1903
1904
1905
1906

1907
1908
1909
1910
1911
1912
1913
	exprlist_t *exhostexp;
	exprlist_t *pageexp;
	exprlist_t *expageexp;
	exprlist_t *dgexp;
	exprlist_t *exdgexp;
	exprlist_t *classexp;
	exprlist_t *exclassexp;
	char *timespec, *statustext, *rrdidstr, *groups;
	ruletype_t ruletype;
	int cfid;
	unsigned int flags;
	struct c_rule_t *next;
	union {
		c_load_t load;
		c_uptime_t uptime;
................................................................................
}

static c_rule_t *setup_rule(ruletype_t ruletype, 
			    exprlist_t *curhost, exprlist_t *curexhost, 
			    exprlist_t *curpage, exprlist_t *curexpage, 
			    exprlist_t *curdg, exprlist_t *curexdg, 
			    exprlist_t *curclass, exprlist_t *curexclass, 
			    char *curtime, char *curtext, char *curgroup,
			    int cfid)
{
	c_rule_t *newitem = (c_rule_t *)calloc(1, sizeof(c_rule_t));
	if (ruletail) { ruletail->next = newitem; ruletail = newitem; }
	else rulehead = ruletail = newitem;

	newitem->ruletype = ruletype;
................................................................................
	newitem->pageexp = curpage;
	newitem->expageexp = curexpage;
	newitem->dgexp = curdg;
	newitem->exdgexp = curexdg;
	newitem->classexp = curclass;
	newitem->exclassexp = curexclass;
	if (curtime) newitem->timespec = strdup(curtime);

	if (curtext) newitem->statustext = strdup(curtext);
	if (curgroup) newitem->groups = strdup(curgroup);
	newitem->cfid = cfid;

	return newitem;
}

................................................................................
	     (strncasecmp(token, "EXPAGE=", 7) == 0)		||
	     (strncasecmp(token, "DISPLAYGROUP=", 13) == 0)	||
	     (strncasecmp(token, "EXDISPLAYGROUP=", 15) == 0)	||
	     (strncasecmp(token, "CLASS=", 6) == 0)		||
	     (strncasecmp(token, "EXCLASS=", 8) == 0)		||
	     (strncasecmp(token, "TEXT=", 5) == 0)		||
	     (strncasecmp(token, "GROUP=", 6) == 0)		||
	     (strncasecmp(token, "TIME=", 5) == 0)		) return 1;


	return 0;
}

static char *ftypestr(unsigned int ftype)
{
	if      (ftype == S_IFSOCK) return "socket";
................................................................................
	/* (Re)load the configuration file without leaking memory */
	static void *configfiles = NULL;
	char fn[PATH_MAX];
	FILE *fd;
	strbuffer_t *inbuf;
	char *tok;
	exprlist_t *curhost, *curpage, *curclass, *curexhost, *curexpage, *curexclass, *curdg, *curexdg;
	char *curtime, *curtext, *curgroup;
	c_rule_t *currule = NULL;
	int cfid = 0;

	MEMDEFINE(fn);

	if (configfn) strcpy(fn, configfn); else sprintf(fn, "%s/etc/analysis.cfg", xgetenv("XYMONHOME"));

................................................................................

	/* First free the old list, if any */
	while (rulehead) {
		c_rule_t *tmp = rulehead;
		rulehead = rulehead->next;
		if (tmp->groups) xfree(tmp->groups);
		if (tmp->timespec) xfree(tmp->timespec);

		if (tmp->statustext) xfree(tmp->statustext);
		if (tmp->rrdidstr) xfree(tmp->rrdidstr);

		switch (tmp->ruletype) {
		  case C_MIBVAL:
			if (tmp->rule.mibval.havetree) xtreeDestroy(tmp->rule.mibval.valdeftree);
			break;
................................................................................
			}
			handle = xtreeNext(ruletree, handle);
		}
		xtreeDestroy(ruletree);
		havetree = 0;
	}

#define NEWRULE(X) (setup_rule(X, curhost, curexhost, curpage, curexpage, curdg, curexdg, curclass, curexclass, curtime, curtext, curgroup, cfid));

	curhost = curpage = curclass = curexhost = curexpage = curexclass = curdg = curexdg = NULL;
	curtime = curtext = curgroup = NULL;
	inbuf = newstrbuffer(0);
	while (stackfgets(inbuf, NULL)) {
		exprlist_t *newhost, *newpage, *newexhost, *newexpage, *newclass, *newexclass, *newdg, *newexdg;
		char *newtime, *newtext, *newgroup;
		int unknowntok = 0;

		cfid++;
		sanitize_input(inbuf, 1, 0); if (STRBUFLEN(inbuf) == 0) continue;

		newhost = newpage = newexhost = newexpage = newclass = newexclass = newdg = newexdg = NULL;
		newtime = newtext = newgroup = NULL;
		currule = NULL;

		tok = wstok(STRBUF(inbuf));
		while (tok) {
			if (strncasecmp(tok, "HOST=", 5) == 0) {
				char *p = strchr(tok, '=');
				newhost = setup_expr(p+1, 0);
................................................................................
				tok = wstok(NULL); continue;
			}
			else if (strncasecmp(tok, "TIME=", 5) == 0) {
				char *p = strchr(tok, '=');
				if (currule) currule->timespec = strdup(p+1);
				else newtime = strdup(p+1);
				tok = wstok(NULL); continue;






			}
			else if (strncasecmp(tok, "TEXT=", 5) == 0) {
				char *p = strchr(tok, '=');
				if (currule) currule->statustext = strdup(p+1);
				else newtext = strdup(p+1);
				tok = wstok(NULL); continue;
			}
................................................................................
			curhost = newhost;
			curpage = newpage;
			curclass = newclass;
			curexhost = newexhost;
			curexpage = newexpage;
			curexclass = newexclass;
			if (curtime) xfree(curtime); curtime = newtime;

			if (curtext) xfree(curtext); curtext = newtext;
			if (curgroup) xfree(curgroup); curgroup = newgroup;
		}
	}

	stackfclose(fd);
	freestrbuffer(inbuf);
	if (curtime) xfree(curtime);

	if (curtext) xfree(curtext);

	/* Create the ruletree, but leave it empty - it will be filled as clients report */
	ruletree = xtreeNew(strcasecmp);
	havetree = 1;

	MEMUNDEFINE(fn);
................................................................................
			printf(" TRACK");
			if (rwalk->rrdidstr) printf("=%s", rwalk->rrdidstr);
		}

		if (rwalk->flags & CHK_OPTIONAL) printf(" OPTIONAL");

		if (rwalk->timespec) printf(" TIME=%s", rwalk->timespec);

		if (rwalk->hostexp) printf(" HOST=%s", rwalk->hostexp->pattern);
		if (rwalk->exhostexp) printf(" EXHOST=%s", rwalk->exhostexp->pattern);
		if (rwalk->dgexp) printf(" DISPLAYGROUP=%s", rwalk->dgexp->pattern);
		if (rwalk->exdgexp) printf(" EXDISPLAYGROUP=%s", rwalk->exdgexp->pattern);
		if (rwalk->pageexp) printf(" PAGE=%s", rwalk->pageexp->pattern);
		if (rwalk->expageexp) printf(" EXPAGE=%s", rwalk->expageexp->pattern);
		if (rwalk->classexp) printf(" CLASS=%s", rwalk->classexp->pattern);
................................................................................
	}

	holidayset = (hinfo ? xmh_item(hinfo, XMH_HOLIDAYS) : NULL);

	for (; (rwalk); rwalk = rwalk->next) {
		if (rwalk->rule->ruletype != ruletype) continue;
		if (rwalk->rule->timespec && !timematch(holidayset, rwalk->rule->timespec)) continue;


		/* If we get here, then we have something that matches */
		return rwalk->rule;
	}

	return NULL;
}







|







 







|







 







>







 







|
>







 







|







 







>







 







|


|



|






|







 







>
>
>
>
>
>







 







>








>







 







>







 







>







241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
...
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
...
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
...
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
...
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
...
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
...
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
...
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
....
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
....
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
....
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
	exprlist_t *exhostexp;
	exprlist_t *pageexp;
	exprlist_t *expageexp;
	exprlist_t *dgexp;
	exprlist_t *exdgexp;
	exprlist_t *classexp;
	exprlist_t *exclassexp;
	char *timespec, *extimespec, *statustext, *rrdidstr, *groups;
	ruletype_t ruletype;
	int cfid;
	unsigned int flags;
	struct c_rule_t *next;
	union {
		c_load_t load;
		c_uptime_t uptime;
................................................................................
}

static c_rule_t *setup_rule(ruletype_t ruletype, 
			    exprlist_t *curhost, exprlist_t *curexhost, 
			    exprlist_t *curpage, exprlist_t *curexpage, 
			    exprlist_t *curdg, exprlist_t *curexdg, 
			    exprlist_t *curclass, exprlist_t *curexclass, 
			    char *curtime, char *curextime, char *curtext, char *curgroup,
			    int cfid)
{
	c_rule_t *newitem = (c_rule_t *)calloc(1, sizeof(c_rule_t));
	if (ruletail) { ruletail->next = newitem; ruletail = newitem; }
	else rulehead = ruletail = newitem;

	newitem->ruletype = ruletype;
................................................................................
	newitem->pageexp = curpage;
	newitem->expageexp = curexpage;
	newitem->dgexp = curdg;
	newitem->exdgexp = curexdg;
	newitem->classexp = curclass;
	newitem->exclassexp = curexclass;
	if (curtime) newitem->timespec = strdup(curtime);
	if (curextime) newitem->extimespec = strdup(curextime);
	if (curtext) newitem->statustext = strdup(curtext);
	if (curgroup) newitem->groups = strdup(curgroup);
	newitem->cfid = cfid;

	return newitem;
}

................................................................................
	     (strncasecmp(token, "EXPAGE=", 7) == 0)		||
	     (strncasecmp(token, "DISPLAYGROUP=", 13) == 0)	||
	     (strncasecmp(token, "EXDISPLAYGROUP=", 15) == 0)	||
	     (strncasecmp(token, "CLASS=", 6) == 0)		||
	     (strncasecmp(token, "EXCLASS=", 8) == 0)		||
	     (strncasecmp(token, "TEXT=", 5) == 0)		||
	     (strncasecmp(token, "GROUP=", 6) == 0)		||
	     (strncasecmp(token, "TIME=", 5) == 0)		||
	     (strncasecmp(token, "EXTIME=", 7) == 0)		) return 1;

	return 0;
}

static char *ftypestr(unsigned int ftype)
{
	if      (ftype == S_IFSOCK) return "socket";
................................................................................
	/* (Re)load the configuration file without leaking memory */
	static void *configfiles = NULL;
	char fn[PATH_MAX];
	FILE *fd;
	strbuffer_t *inbuf;
	char *tok;
	exprlist_t *curhost, *curpage, *curclass, *curexhost, *curexpage, *curexclass, *curdg, *curexdg;
	char *curtime, *curextime, *curtext, *curgroup;
	c_rule_t *currule = NULL;
	int cfid = 0;

	MEMDEFINE(fn);

	if (configfn) strcpy(fn, configfn); else sprintf(fn, "%s/etc/analysis.cfg", xgetenv("XYMONHOME"));

................................................................................

	/* First free the old list, if any */
	while (rulehead) {
		c_rule_t *tmp = rulehead;
		rulehead = rulehead->next;
		if (tmp->groups) xfree(tmp->groups);
		if (tmp->timespec) xfree(tmp->timespec);
		if (tmp->extimespec) xfree(tmp->extimespec);
		if (tmp->statustext) xfree(tmp->statustext);
		if (tmp->rrdidstr) xfree(tmp->rrdidstr);

		switch (tmp->ruletype) {
		  case C_MIBVAL:
			if (tmp->rule.mibval.havetree) xtreeDestroy(tmp->rule.mibval.valdeftree);
			break;
................................................................................
			}
			handle = xtreeNext(ruletree, handle);
		}
		xtreeDestroy(ruletree);
		havetree = 0;
	}

#define NEWRULE(X) (setup_rule(X, curhost, curexhost, curpage, curexpage, curdg, curexdg, curclass, curexclass, curtime, curextime, curtext, curgroup, cfid));

	curhost = curpage = curclass = curexhost = curexpage = curexclass = curdg = curexdg = NULL;
	curtime = curextime = curtext = curgroup = NULL;
	inbuf = newstrbuffer(0);
	while (stackfgets(inbuf, NULL)) {
		exprlist_t *newhost, *newpage, *newexhost, *newexpage, *newclass, *newexclass, *newdg, *newexdg;
		char *newtime, *newextime, *newtext, *newgroup;
		int unknowntok = 0;

		cfid++;
		sanitize_input(inbuf, 1, 0); if (STRBUFLEN(inbuf) == 0) continue;

		newhost = newpage = newexhost = newexpage = newclass = newexclass = newdg = newexdg = NULL;
		newtime = newextime = newtext = newgroup = NULL;
		currule = NULL;

		tok = wstok(STRBUF(inbuf));
		while (tok) {
			if (strncasecmp(tok, "HOST=", 5) == 0) {
				char *p = strchr(tok, '=');
				newhost = setup_expr(p+1, 0);
................................................................................
				tok = wstok(NULL); continue;
			}
			else if (strncasecmp(tok, "TIME=", 5) == 0) {
				char *p = strchr(tok, '=');
				if (currule) currule->timespec = strdup(p+1);
				else newtime = strdup(p+1);
				tok = wstok(NULL); continue;
			}
			else if (strncasecmp(tok, "EXTIME=", 7) == 0) {
				char *p = strchr(tok, '=');
				if (currule) currule->extimespec = strdup(p+1);
				else newextime = strdup(p+1);
				tok = wstok(NULL); continue;
			}
			else if (strncasecmp(tok, "TEXT=", 5) == 0) {
				char *p = strchr(tok, '=');
				if (currule) currule->statustext = strdup(p+1);
				else newtext = strdup(p+1);
				tok = wstok(NULL); continue;
			}
................................................................................
			curhost = newhost;
			curpage = newpage;
			curclass = newclass;
			curexhost = newexhost;
			curexpage = newexpage;
			curexclass = newexclass;
			if (curtime) xfree(curtime); curtime = newtime;
			if (curextime) xfree(curextime); curextime = newextime;
			if (curtext) xfree(curtext); curtext = newtext;
			if (curgroup) xfree(curgroup); curgroup = newgroup;
		}
	}

	stackfclose(fd);
	freestrbuffer(inbuf);
	if (curtime) xfree(curtime);
	if (curextime) xfree(curextime);
	if (curtext) xfree(curtext);

	/* Create the ruletree, but leave it empty - it will be filled as clients report */
	ruletree = xtreeNew(strcasecmp);
	havetree = 1;

	MEMUNDEFINE(fn);
................................................................................
			printf(" TRACK");
			if (rwalk->rrdidstr) printf("=%s", rwalk->rrdidstr);
		}

		if (rwalk->flags & CHK_OPTIONAL) printf(" OPTIONAL");

		if (rwalk->timespec) printf(" TIME=%s", rwalk->timespec);
		if (rwalk->extimespec) printf(" EXTIME=%s", rwalk->extimespec);
		if (rwalk->hostexp) printf(" HOST=%s", rwalk->hostexp->pattern);
		if (rwalk->exhostexp) printf(" EXHOST=%s", rwalk->exhostexp->pattern);
		if (rwalk->dgexp) printf(" DISPLAYGROUP=%s", rwalk->dgexp->pattern);
		if (rwalk->exdgexp) printf(" EXDISPLAYGROUP=%s", rwalk->exdgexp->pattern);
		if (rwalk->pageexp) printf(" PAGE=%s", rwalk->pageexp->pattern);
		if (rwalk->expageexp) printf(" EXPAGE=%s", rwalk->expageexp->pattern);
		if (rwalk->classexp) printf(" CLASS=%s", rwalk->classexp->pattern);
................................................................................
	}

	holidayset = (hinfo ? xmh_item(hinfo, XMH_HOLIDAYS) : NULL);

	for (; (rwalk); rwalk = rwalk->next) {
		if (rwalk->rule->ruletype != ruletype) continue;
		if (rwalk->rule->timespec && !timematch(holidayset, rwalk->rule->timespec)) continue;
		if (rwalk->rule->extimespec && timematch(holidayset, rwalk->rule->extimespec)) continue;

		/* If we get here, then we have something that matches */
		return rwalk->rule;
	}

	return NULL;
}