prevent sending notifications of alarms in status CLEAR
Costa Tsaousis (ktsaou) committed
Nov 13, 2016 at 21:00 UTC
8d59fd78834a368e2a4178c65190c14e488574f7
1 file changed
+32
-25
src/health.c
+32
-25
@@ -2575,11 +2575,13 @@ void health_reload(void) {
2575
// health main thread and friends
2576
2577
static inline int rrdcalc_value2status(calculated_number n) {
2578
- if(isnan(n)) return RRDCALC_STATUS_UNDEFINED;
2578
+ if(isnan(n) || isinf(n)) return RRDCALC_STATUS_UNDEFINED;
2579
if(n) return RRDCALC_STATUS_RAISED;
2580
return RRDCALC_STATUS_CLEAR;
2581
}
2582
2583
+#define ALARM_EXEC_COMMAND_LENGTH 8192
2584
+
2585
static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
2586
ae->flags |= HEALTH_ENTRY_FLAG_PROCESSED;
2587
@@ -2590,30 +2592,35 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
2592
2593
// find the previous notification for the same alarm
2594
// which we have run the exec script
2593
- ALARM_ENTRY *t;
2594
- for(t = ae->next; t ;t = t->next) {
2595
- if(t->alarm_id == ae->alarm_id && t->flags & HEALTH_ENTRY_FLAG_EXEC_RUN)
2596
- break;
2597
- }
2595
+ {
2596
+ uint32_t id = ae->alarm_id;
2597
+ ALARM_ENTRY *t;
2598
+ for(t = ae->next; t ; t = t->next) {
2599
+ if(t->alarm_id == id && t->flags & HEALTH_ENTRY_FLAG_EXEC_RUN)
2600
+ break;
2601
+ }
2602
2599
- if(likely(t)) {
2600
- // we have executed this alarm notification in the past
2601
- if (t && t->new_status == ae->new_status) {
2602
- // don't send the same notification again
2603
- debug(D_HEALTH, "Health not sending again notification for alarm '%s.%s' status %s", ae->chart, ae->name,
2604
- rrdcalc_status2string(ae->new_status));
2605
- goto done;
2603
+ if(likely(t)) {
2604
+ // we have executed this alarm notification in the past
2605
+ if(t && t->new_status == ae->new_status) {
2606
+ // don't send the notification for the same status again
2607
+ debug(D_HEALTH, "Health not sending again notification for alarm '%s.%s' status %s", ae->chart, ae->name
2608
+ , rrdcalc_status2string(ae->new_status));
2609
+ goto done;
2610
+ }
2611
}
2607
- }
2608
- else {
2609
- // we have not executed this alarm notification in the past
2610
- if(unlikely(ae->old_status == RRDCALC_STATUS_UNINITIALIZED && ae->new_status == RRDCALC_STATUS_CLEAR)) {
2611
- debug(D_HEALTH, "Health not sending notification for first initialization of alarm '%s.%s' status %s", ae->chart, ae->name, rrdcalc_status2string(ae->new_status));
2612
- goto done;
2612
+ else {
2613
+ // we have not executed this alarm notification in the past
2614
+ // so, don't send CLEAR notifications
2615
+ if(unlikely(ae->new_status == RRDCALC_STATUS_CLEAR)) {
2616
+ debug(D_HEALTH, "Health not sending notification for first initialization of alarm '%s.%s' status %s"
2617
+ , ae->chart, ae->name, rrdcalc_status2string(ae->new_status));
2618
+ goto done;
2619
+ }
2620
}
2621
}
2622
2616
- char buffer[FILENAME_MAX + 1];
2623
+ static char command_to_run[ALARM_EXEC_COMMAND_LENGTH + 1];
2624
pid_t command_pid;
2625
2626
const char *exec = ae->exec;
@@ -2622,7 +2629,7 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
2629
const char *recipient = ae->recipient;
2630
if(!recipient) recipient = health.health_default_recipient;
2631
2625
- snprintfz(buffer, FILENAME_MAX, "exec %s '%s' '%s' '%u' '%u' '%u' '%lu' '%s' '%s' '%s' '%s' '%s' '%0.0Lf' '%0.0Lf' '%s' '%u' '%u' '%s' '%s'",
2632
+ snprintfz(command_to_run, ALARM_EXEC_COMMAND_LENGTH, "exec %s '%s' '%s' '%u' '%u' '%u' '%lu' '%s' '%s' '%s' '%s' '%s' '%0.0Lf' '%0.0Lf' '%s' '%u' '%u' '%s' '%s'",
2633
exec,
2634
recipient,
2635
host->hostname,
@@ -2647,14 +2654,14 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
2654
ae->flags |= HEALTH_ENTRY_FLAG_EXEC_RUN;
2655
ae->exec_run_timestamp = time(NULL);
2656
2650
- debug(D_HEALTH, "executing command '%s'", buffer);
2651
- FILE *fp = mypopen(buffer, &command_pid);
2657
+ debug(D_HEALTH, "executing command '%s'", command_to_run);
2658
+ FILE *fp = mypopen(command_to_run, &command_pid);
2659
if(!fp) {
2653
- error("HEALTH: Cannot popen(\"%s\", \"r\").", buffer);
2660
+ error("HEALTH: Cannot popen(\"%s\", \"r\").", command_to_run);
2661
goto done;
2662
}
2663
debug(D_HEALTH, "HEALTH reading from command");
2657
- char *s = fgets(buffer, FILENAME_MAX, fp);
2664
+ char *s = fgets(command_to_run, FILENAME_MAX, fp);
2665
(void)s;
2666
ae->exec_code = mypclose(fp, command_pid);
2667
debug(D_HEALTH, "done executing command - returned with code %d", ae->exec_code);