@cryptotaxi247 / netdata-1 / commits / 7355ae083

Tabulatin on health/health.c (#6691)

* health_tabulation: Fix tabulation on file The health.c has two type of tabulation, this commit fix this * health_tabulation: Returing the return I am bringing back the return as it was to keep the PR code according the PR name * health_tabulation: Removing comments Removing comments from this PR, I will bring back with a new PR * health_tabulation: back space I am returning an unecessary space here. * health_tabulation: space 2 I am returning an unecessary space here. * health_tabulation: function adjust the functions closing * health_tabulation: remove again After to do a download of the health.c, I removed the tabulation again to have the file without additional space

thiagoftsm committed Aug 21, 2019 at 18:48 UTC 7355ae0834fdc16165f90bedeb910c4dba004054
1 file changed +335 -335
health/health.c
+335 -335
@@ -235,15 +235,15 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
235 const char *exec = (ae->exec) ? ae->exec : host->health_default_exec;
236 const char *recipient = (ae->recipient) ? ae->recipient : host->health_default_recipient;
237
238 - int n_warn=0, n_crit=0;
239 - RRDCALC *rc;
238 + int n_warn=0, n_crit=0;
239 + RRDCALC *rc;
240 EVAL_EXPRESSION *expr=NULL;
241
242 - for(rc = host->alarms; rc ; rc = rc->next) {
243 - if(unlikely(!rc->rrdset || !rc->rrdset->last_collected_time.tv_sec))
244 - continue;
242 + for(rc = host->alarms; rc ; rc = rc->next) {
243 + if(unlikely(!rc->rrdset || !rc->rrdset->last_collected_time.tv_sec))
244 + continue;
245
246 - if(unlikely(rc->status == RRDCALC_STATUS_WARNING)) {
246 + if(unlikely(rc->status == RRDCALC_STATUS_WARNING)) {
247 n_warn++;
248 if (ae->alarm_id == rc->id)
249 expr=rc->warning;
@@ -254,8 +254,8 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
254 } else if (unlikely(rc->status == RRDCALC_STATUS_CLEAR)) {
255 if (ae->alarm_id == rc->id)
256 expr=rc->warning;
257 - }
258 - }
257 + }
258 + }
259
260 snprintfz(command_to_run, ALARM_EXEC_COMMAND_LENGTH, "exec %s '%s' '%s' '%u' '%u' '%u' '%lu' '%s' '%s' '%s' '%s' '%s' '" CALCULATED_NUMBER_FORMAT_ZERO "' '" CALCULATED_NUMBER_FORMAT_ZERO "' '%s' '%u' '%u' '%s' '%s' '%s' '%s' '%s' '%s' '%d' '%d'",
261 exec,
@@ -467,7 +467,7 @@ static void health_main_cleanup(void *ptr) {
467 }
468
469 SILENCE_TYPE check_silenced(RRDCALC *rc, char* host, SILENCERS *silencers) {
470 - SILENCER *s;
470 + SILENCER *s;
471 debug(D_HEALTH, "Checking if alarm was silenced via the command API. Alarm info name:%s context:%s chart:%s host:%s family:%s",
472 rc->name, (rc->rrdset)?rc->rrdset->context:"", rc->chart, host, (rc->rrdset)?rc->rrdset->family:"");
473
@@ -509,32 +509,32 @@ SILENCE_TYPE check_silenced(RRDCALC *rc, char* host, SILENCERS *silencers) {
509 * @return It returns 1 case rrdcalc_flags is DISABLED or 0 otherwise
510 */
511 int update_disabled_silenced(RRDHOST *host, RRDCALC *rc) {
512 - uint32_t rrdcalc_flags_old = rc->rrdcalc_flags;
513 - // Clear the flags
514 - rc->rrdcalc_flags &= ~(RRDCALC_FLAG_DISABLED | RRDCALC_FLAG_SILENCED);
515 - if (unlikely(silencers->all_alarms)) {
516 - if (silencers->stype == STYPE_DISABLE_ALARMS) rc->rrdcalc_flags |= RRDCALC_FLAG_DISABLED;
517 - else if (silencers->stype == STYPE_SILENCE_NOTIFICATIONS) rc->rrdcalc_flags |= RRDCALC_FLAG_SILENCED;
518 - } else {
519 - SILENCE_TYPE st = check_silenced(rc, host->hostname, silencers);
520 - if (st == STYPE_DISABLE_ALARMS) rc->rrdcalc_flags |= RRDCALC_FLAG_DISABLED;
521 - else if (st == STYPE_SILENCE_NOTIFICATIONS) rc->rrdcalc_flags |= RRDCALC_FLAG_SILENCED;
522 - }
523 -
524 - if (rrdcalc_flags_old != rc->rrdcalc_flags) {
525 - info("Alarm silencing changed for host '%s' alarm '%s': Disabled %s->%s Silenced %s->%s",
526 - host->hostname,
527 - rc->name,
528 - (rrdcalc_flags_old & RRDCALC_FLAG_DISABLED)?"true":"false",
529 - (rc->rrdcalc_flags & RRDCALC_FLAG_DISABLED)?"true":"false",
530 - (rrdcalc_flags_old & RRDCALC_FLAG_SILENCED)?"true":"false",
531 - (rc->rrdcalc_flags & RRDCALC_FLAG_SILENCED)?"true":"false"
532 - );
533 - }
534 - if (rc->rrdcalc_flags & RRDCALC_FLAG_DISABLED)
535 - return 1;
536 - else
537 - return 0;
512 + uint32_t rrdcalc_flags_old = rc->rrdcalc_flags;
513 + // Clear the flags
514 + rc->rrdcalc_flags &= ~(RRDCALC_FLAG_DISABLED | RRDCALC_FLAG_SILENCED);
515 + if (unlikely(silencers->all_alarms)) {
516 + if (silencers->stype == STYPE_DISABLE_ALARMS) rc->rrdcalc_flags |= RRDCALC_FLAG_DISABLED;
517 + else if (silencers->stype == STYPE_SILENCE_NOTIFICATIONS) rc->rrdcalc_flags |= RRDCALC_FLAG_SILENCED;
518 + } else {
519 + SILENCE_TYPE st = check_silenced(rc, host->hostname, silencers);
520 + if (st == STYPE_DISABLE_ALARMS) rc->rrdcalc_flags |= RRDCALC_FLAG_DISABLED;
521 + else if (st == STYPE_SILENCE_NOTIFICATIONS) rc->rrdcalc_flags |= RRDCALC_FLAG_SILENCED;
522 + }
523 +
524 + if (rrdcalc_flags_old != rc->rrdcalc_flags) {
525 + info("Alarm silencing changed for host '%s' alarm '%s': Disabled %s->%s Silenced %s->%s",
526 + host->hostname,
527 + rc->name,
528 + (rrdcalc_flags_old & RRDCALC_FLAG_DISABLED)?"true":"false",
529 + (rc->rrdcalc_flags & RRDCALC_FLAG_DISABLED)?"true":"false",
530 + (rrdcalc_flags_old & RRDCALC_FLAG_SILENCED)?"true":"false",
531 + (rc->rrdcalc_flags & RRDCALC_FLAG_SILENCED)?"true":"false"
532 + );
533 + }
534 + if (rc->rrdcalc_flags & RRDCALC_FLAG_DISABLED)
535 + return 1;
536 + else
537 + return 0;
538 }
539
540 /**
@@ -557,290 +557,290 @@ void *health_main(void *ptr) {
557
558 unsigned int loop = 0;
559 while(!netdata_exit) {
560 - loop++;
561 - debug(D_HEALTH, "Health monitoring iteration no %u started", loop);
560 + loop++;
561 + debug(D_HEALTH, "Health monitoring iteration no %u started", loop);
562 +
563 + int runnable = 0, apply_hibernation_delay = 0;
564 + time_t next_run = now + min_run_every;
565 + RRDCALC *rc;
566 +
567 + if (unlikely(check_if_resumed_from_suspention())) {
568 + apply_hibernation_delay = 1;
569 +
570 + info("Postponing alarm checks for %ld seconds, because it seems that the system was just resumed from suspension.",
571 + hibernation_delay
572 + );
573 + }
574 +
575 + if (unlikely(silencers->all_alarms && silencers->stype == STYPE_DISABLE_ALARMS)) {
576 + static int logged=0;
577 + if (!logged) {
578 + info("Skipping health checks, because all alarms are disabled via a %s command.",
579 + HEALTH_CMDAPI_CMD_DISABLEALL);
580 + logged = 1;
581 + }
582 + }
583 +
584 + rrd_rdlock();
585 +
586 + RRDHOST *host;
587 + rrdhost_foreach_read(host) {
588 + if (unlikely(!host->health_enabled))
589 + continue;
590 +
591 + if (unlikely(apply_hibernation_delay)) {
592 +
593 + info("Postponing health checks for %ld seconds, on host '%s'.", hibernation_delay, host->hostname
594 + );
595 +
596 + host->health_delay_up_to = now + hibernation_delay;
597 + }
598 +
599 + if (unlikely(host->health_delay_up_to)) {
600 + if (unlikely(now < host->health_delay_up_to))
601 + continue;
602 +
603 + info("Resuming health checks on host '%s'.", host->hostname);
604 + host->health_delay_up_to = 0;
605 + }
606 +
607 + rrdhost_rdlock(host);
608 +
609 + // the first loop is to lookup values from the db
610 + for (rc = host->alarms; rc; rc = rc->next) {
611 +
612 + if (update_disabled_silenced(host, rc))
613 + continue;
614 +
615 + if (unlikely(!rrdcalc_isrunnable(rc, now, &next_run))) {
616 + if (unlikely(rc->rrdcalc_flags & RRDCALC_FLAG_RUNNABLE))
617 + rc->rrdcalc_flags &= ~RRDCALC_FLAG_RUNNABLE;
618 + continue;
619 + }
620 +
621 + runnable++;
622 + rc->old_value = rc->value;
623 + rc->rrdcalc_flags |= RRDCALC_FLAG_RUNNABLE;
624 +
625 + // ------------------------------------------------------------
626 + // if there is database lookup, do it
627 +
628 + if (unlikely(RRDCALC_HAS_DB_LOOKUP(rc))) {
629 + /* time_t old_db_timestamp = rc->db_before; */
630 + int value_is_null = 0;
631 +
632 + int ret = rrdset2value_api_v1(rc->rrdset, NULL, &rc->value, rc->dimensions, 1, rc->after,
633 + rc->before, rc->group, 0, rc->options, &rc->db_after,
634 + &rc->db_before, &value_is_null
635 + );
636 +
637 + if (unlikely(ret != 200)) {
638 + // database lookup failed
639 + rc->value = NAN;
640 + rc->rrdcalc_flags |= RRDCALC_FLAG_DB_ERROR;
641 +
642 + debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': database lookup returned error %d",
643 + host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name, ret
644 + );
645 + } else
646 + rc->rrdcalc_flags &= ~RRDCALC_FLAG_DB_ERROR;
647 +
648 + /* - RRDCALC_FLAG_DB_STALE not currently used
649 + if (unlikely(old_db_timestamp == rc->db_before)) {
650 + // database is stale
651 +
652 + debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': database is stale", host->hostname, rc->chart?rc->chart:"NOCHART", rc->name);
653 +
654 + if (unlikely(!(rc->rrdcalc_flags & RRDCALC_FLAG_DB_STALE))) {
655 + rc->rrdcalc_flags |= RRDCALC_FLAG_DB_STALE;
656 + error("Health on host '%s', alarm '%s.%s': database is stale", host->hostname, rc->chart?rc->chart:"NOCHART", rc->name);
657 + }
658 + }
659 + else if (unlikely(rc->rrdcalc_flags & RRDCALC_FLAG_DB_STALE))
660 + rc->rrdcalc_flags &= ~RRDCALC_FLAG_DB_STALE;
661 + */
662 +
663 + if (unlikely(value_is_null)) {
664 + // collected value is null
665 + rc->value = NAN;
666 + rc->rrdcalc_flags |= RRDCALC_FLAG_DB_NAN;
667 +
668 + debug(D_HEALTH,
669 + "Health on host '%s', alarm '%s.%s': database lookup returned empty value (possibly value is not collected yet)",
670 + host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name
671 + );
672 + } else
673 + rc->rrdcalc_flags &= ~RRDCALC_FLAG_DB_NAN;
674 +
675 + debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': database lookup gave value "
676 + CALCULATED_NUMBER_FORMAT, host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name,
677 + rc->value
678 + );
679 + }
680 +
681 + // ------------------------------------------------------------
682 + // if there is calculation expression, run it
683 +
684 + if (unlikely(rc->calculation)) {
685 + if (unlikely(!expression_evaluate(rc->calculation))) {
686 + // calculation failed
687 + rc->value = NAN;
688 + rc->rrdcalc_flags |= RRDCALC_FLAG_CALC_ERROR;
689 +
690 + debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': expression '%s' failed: %s",
691 + host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name,
692 + rc->calculation->parsed_as, buffer_tostring(rc->calculation->error_msg)
693 + );
694 + } else {
695 + rc->rrdcalc_flags &= ~RRDCALC_FLAG_CALC_ERROR;
696
563 - int runnable = 0, apply_hibernation_delay = 0;
564 - time_t next_run = now + min_run_every;
565 - RRDCALC *rc;
566 -
567 - if (unlikely(check_if_resumed_from_suspention())) {
568 - apply_hibernation_delay = 1;
569 -
570 - info("Postponing alarm checks for %ld seconds, because it seems that the system was just resumed from suspension.",
571 - hibernation_delay
572 - );
573 - }
574 -
575 - if (unlikely(silencers->all_alarms && silencers->stype == STYPE_DISABLE_ALARMS)) {
576 - static int logged=0;
577 - if (!logged) {
578 - info("Skipping health checks, because all alarms are disabled via a %s command.",
579 - HEALTH_CMDAPI_CMD_DISABLEALL);
580 - logged = 1;
581 - }
582 - }
583 -
584 - rrd_rdlock();
585 -
586 - RRDHOST *host;
587 - rrdhost_foreach_read(host) {
588 - if (unlikely(!host->health_enabled))
589 - continue;
590 -
591 - if (unlikely(apply_hibernation_delay)) {
592 -
593 - info("Postponing health checks for %ld seconds, on host '%s'.", hibernation_delay, host->hostname
594 - );
595 -
596 - host->health_delay_up_to = now + hibernation_delay;
597 - }
598 -
599 - if (unlikely(host->health_delay_up_to)) {
600 - if (unlikely(now < host->health_delay_up_to))
601 - continue;
602 -
603 - info("Resuming health checks on host '%s'.", host->hostname);
604 - host->health_delay_up_to = 0;
605 - }
606 -
607 - rrdhost_rdlock(host);
608 -
609 - // the first loop is to lookup values from the db
610 - for (rc = host->alarms; rc; rc = rc->next) {
611 -
612 - if (update_disabled_silenced(host, rc))
613 - continue;
614 -
615 - if (unlikely(!rrdcalc_isrunnable(rc, now, &next_run))) {
616 - if (unlikely(rc->rrdcalc_flags & RRDCALC_FLAG_RUNNABLE))
617 - rc->rrdcalc_flags &= ~RRDCALC_FLAG_RUNNABLE;
618 - continue;
619 - }
620 -
621 - runnable++;
622 - rc->old_value = rc->value;
623 - rc->rrdcalc_flags |= RRDCALC_FLAG_RUNNABLE;
624 -
625 - // ------------------------------------------------------------
626 - // if there is database lookup, do it
627 -
628 - if (unlikely(RRDCALC_HAS_DB_LOOKUP(rc))) {
629 - /* time_t old_db_timestamp = rc->db_before; */
630 - int value_is_null = 0;
631 -
632 - int ret = rrdset2value_api_v1(rc->rrdset, NULL, &rc->value, rc->dimensions, 1, rc->after,
633 - rc->before, rc->group, 0, rc->options, &rc->db_after,
634 - &rc->db_before, &value_is_null
635 - );
636 -
637 - if (unlikely(ret != 200)) {
638 - // database lookup failed
639 - rc->value = NAN;
640 - rc->rrdcalc_flags |= RRDCALC_FLAG_DB_ERROR;
641 -
642 - debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': database lookup returned error %d",
643 - host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name, ret
644 - );
645 - } else
646 - rc->rrdcalc_flags &= ~RRDCALC_FLAG_DB_ERROR;
647 -
648 - /* - RRDCALC_FLAG_DB_STALE not currently used
649 - if (unlikely(old_db_timestamp == rc->db_before)) {
650 - // database is stale
651 -
652 - debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': database is stale", host->hostname, rc->chart?rc->chart:"NOCHART", rc->name);
653 -
654 - if (unlikely(!(rc->rrdcalc_flags & RRDCALC_FLAG_DB_STALE))) {
655 - rc->rrdcalc_flags |= RRDCALC_FLAG_DB_STALE;
656 - error("Health on host '%s', alarm '%s.%s': database is stale", host->hostname, rc->chart?rc->chart:"NOCHART", rc->name);
657 - }
658 - }
659 - else if (unlikely(rc->rrdcalc_flags & RRDCALC_FLAG_DB_STALE))
660 - rc->rrdcalc_flags &= ~RRDCALC_FLAG_DB_STALE;
661 - */
662 -
663 - if (unlikely(value_is_null)) {
664 - // collected value is null
665 - rc->value = NAN;
666 - rc->rrdcalc_flags |= RRDCALC_FLAG_DB_NAN;
667 -
668 - debug(D_HEALTH,
669 - "Health on host '%s', alarm '%s.%s': database lookup returned empty value (possibly value is not collected yet)",
670 - host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name
671 - );
672 - } else
673 - rc->rrdcalc_flags &= ~RRDCALC_FLAG_DB_NAN;
674 -
675 - debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': database lookup gave value "
676 - CALCULATED_NUMBER_FORMAT, host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name,
677 - rc->value
678 - );
679 - }
680 -
681 - // ------------------------------------------------------------
682 - // if there is calculation expression, run it
683 -
684 - if (unlikely(rc->calculation)) {
685 - if (unlikely(!expression_evaluate(rc->calculation))) {
686 - // calculation failed
687 - rc->value = NAN;
688 - rc->rrdcalc_flags |= RRDCALC_FLAG_CALC_ERROR;
689 -
690 - debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': expression '%s' failed: %s",
691 - host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name,
692 - rc->calculation->parsed_as, buffer_tostring(rc->calculation->error_msg)
693 - );
694 - } else {
695 - rc->rrdcalc_flags &= ~RRDCALC_FLAG_CALC_ERROR;
696 -
697 - debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': expression '%s' gave value "
698 - CALCULATED_NUMBER_FORMAT
699 - ": %s (source: %s)", host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name,
700 - rc->calculation->parsed_as, rc->calculation->result,
701 - buffer_tostring(rc->calculation->error_msg), rc->source
702 - );
703 -
704 - rc->value = rc->calculation->result;
705 -
706 - if (rc->local) rc->local->last_updated = now;
707 - if (rc->family) rc->family->last_updated = now;
708 - if (rc->hostid) rc->hostid->last_updated = now;
709 - if (rc->hostname) rc->hostname->last_updated = now;
710 - }
711 - }
712 - }
713 -
714 - rrdhost_unlock(host);
715 -
716 - if (unlikely(runnable && !netdata_exit)) {
717 - rrdhost_rdlock(host);
718 -
719 - for (rc = host->alarms; rc; rc = rc->next) {
720 - if (unlikely(!(rc->rrdcalc_flags & RRDCALC_FLAG_RUNNABLE)))
721 - continue;
722 -
723 - if (rc->rrdcalc_flags & RRDCALC_FLAG_DISABLED) {
724 - continue;
725 - }
726 - RRDCALC_STATUS warning_status = RRDCALC_STATUS_UNDEFINED;
727 - RRDCALC_STATUS critical_status = RRDCALC_STATUS_UNDEFINED;
728 -
729 - // --------------------------------------------------------
730 - // check the warning expression
731 -
732 - if (likely(rc->warning)) {
733 - if (unlikely(!expression_evaluate(rc->warning))) {
734 - // calculation failed
735 - rc->rrdcalc_flags |= RRDCALC_FLAG_WARN_ERROR;
736 -
737 - debug(D_HEALTH,
738 - "Health on host '%s', alarm '%s.%s': warning expression failed with error: %s",
739 - host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name,
740 - buffer_tostring(rc->warning->error_msg)
741 - );
742 - } else {
743 - rc->rrdcalc_flags &= ~RRDCALC_FLAG_WARN_ERROR;
744 - debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': warning expression gave value "
745 - CALCULATED_NUMBER_FORMAT
746 - ": %s (source: %s)", host->hostname, rc->chart ? rc->chart : "NOCHART",
747 - rc->name, rc->warning->result, buffer_tostring(rc->warning->error_msg), rc->source
748 - );
749 - warning_status = rrdcalc_value2status(rc->warning->result);
750 - }
751 - }
752 -
753 - // --------------------------------------------------------
754 - // check the critical expression
755 -
756 - if (likely(rc->critical)) {
757 - if (unlikely(!expression_evaluate(rc->critical))) {
758 - // calculation failed
759 - rc->rrdcalc_flags |= RRDCALC_FLAG_CRIT_ERROR;
760 -
761 - debug(D_HEALTH,
762 - "Health on host '%s', alarm '%s.%s': critical expression failed with error: %s",
763 - host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name,
764 - buffer_tostring(rc->critical->error_msg)
765 - );
766 - } else {
767 - rc->rrdcalc_flags &= ~RRDCALC_FLAG_CRIT_ERROR;
768 - debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': critical expression gave value "
769 - CALCULATED_NUMBER_FORMAT
770 - ": %s (source: %s)", host->hostname, rc->chart ? rc->chart : "NOCHART",
771 - rc->name, rc->critical->result, buffer_tostring(rc->critical->error_msg),
772 - rc->source
773 - );
774 - critical_status = rrdcalc_value2status(rc->critical->result);
775 - }
776 - }
777 -
778 - // --------------------------------------------------------
779 - // decide the final alarm status
780 -
781 - RRDCALC_STATUS status = RRDCALC_STATUS_UNDEFINED;
782 -
783 - switch (warning_status) {
784 - case RRDCALC_STATUS_CLEAR:
785 - status = RRDCALC_STATUS_CLEAR;
786 - break;
787 -
788 - case RRDCALC_STATUS_RAISED:
789 - status = RRDCALC_STATUS_WARNING;
790 - break;
791 -
792 - default:
793 - break;
794 - }
795 -
796 - switch (critical_status) {
797 - case RRDCALC_STATUS_CLEAR:
798 - if (status == RRDCALC_STATUS_UNDEFINED)
799 - status = RRDCALC_STATUS_CLEAR;
800 - break;
801 -
802 - case RRDCALC_STATUS_RAISED:
803 - status = RRDCALC_STATUS_CRITICAL;
804 - break;
805 -
806 - default:
807 - break;
808 - }
809 -
810 - // --------------------------------------------------------
811 - // check if the new status and the old differ
812 -
813 - if (status != rc->status) {
814 - int delay = 0;
815 -
816 - // apply trigger hysteresis
817 -
818 - if (now > rc->delay_up_to_timestamp) {
819 - rc->delay_up_current = rc->delay_up_duration;
820 - rc->delay_down_current = rc->delay_down_duration;
821 - rc->delay_last = 0;
822 - rc->delay_up_to_timestamp = 0;
823 - } else {
824 - rc->delay_up_current = (int) (rc->delay_up_current * rc->delay_multiplier);
825 - if (rc->delay_up_current > rc->delay_max_duration)
826 - rc->delay_up_current = rc->delay_max_duration;
827 -
828 - rc->delay_down_current = (int) (rc->delay_down_current * rc->delay_multiplier);
829 - if (rc->delay_down_current > rc->delay_max_duration)
830 - rc->delay_down_current = rc->delay_max_duration;
831 - }
832 -
833 - if (status > rc->status)
834 - delay = rc->delay_up_current;
835 - else
836 - delay = rc->delay_down_current;
837 -
838 - // COMMENTED: because we do need to send raising alarms
839 - // if(now + delay < rc->delay_up_to_timestamp)
840 - // delay = (int)(rc->delay_up_to_timestamp - now);
841 -
842 - rc->delay_last = delay;
843 - rc->delay_up_to_timestamp = now + delay;
697 + debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': expression '%s' gave value "
698 + CALCULATED_NUMBER_FORMAT
699 + ": %s (source: %s)", host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name,
700 + rc->calculation->parsed_as, rc->calculation->result,
701 + buffer_tostring(rc->calculation->error_msg), rc->source
702 + );
703 +
704 + rc->value = rc->calculation->result;
705 +
706 + if (rc->local) rc->local->last_updated = now;
707 + if (rc->family) rc->family->last_updated = now;
708 + if (rc->hostid) rc->hostid->last_updated = now;
709 + if (rc->hostname) rc->hostname->last_updated = now;
710 + }
711 + }
712 + }
713 +
714 + rrdhost_unlock(host);
715 +
716 + if (unlikely(runnable && !netdata_exit)) {
717 + rrdhost_rdlock(host);
718 +
719 + for (rc = host->alarms; rc; rc = rc->next) {
720 + if (unlikely(!(rc->rrdcalc_flags & RRDCALC_FLAG_RUNNABLE)))
721 + continue;
722 +
723 + if (rc->rrdcalc_flags & RRDCALC_FLAG_DISABLED) {
724 + continue;
725 + }
726 + RRDCALC_STATUS warning_status = RRDCALC_STATUS_UNDEFINED;
727 + RRDCALC_STATUS critical_status = RRDCALC_STATUS_UNDEFINED;
728 +
729 + // --------------------------------------------------------
730 + // check the warning expression
731 +
732 + if (likely(rc->warning)) {
733 + if (unlikely(!expression_evaluate(rc->warning))) {
734 + // calculation failed
735 + rc->rrdcalc_flags |= RRDCALC_FLAG_WARN_ERROR;
736 +
737 + debug(D_HEALTH,
738 + "Health on host '%s', alarm '%s.%s': warning expression failed with error: %s",
739 + host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name,
740 + buffer_tostring(rc->warning->error_msg)
741 + );
742 + } else {
743 + rc->rrdcalc_flags &= ~RRDCALC_FLAG_WARN_ERROR;
744 + debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': warning expression gave value "
745 + CALCULATED_NUMBER_FORMAT
746 + ": %s (source: %s)", host->hostname, rc->chart ? rc->chart : "NOCHART",
747 + rc->name, rc->warning->result, buffer_tostring(rc->warning->error_msg), rc->source
748 + );
749 + warning_status = rrdcalc_value2status(rc->warning->result);
750 + }
751 + }
752 +
753 + // --------------------------------------------------------
754 + // check the critical expression
755 +
756 + if (likely(rc->critical)) {
757 + if (unlikely(!expression_evaluate(rc->critical))) {
758 + // calculation failed
759 + rc->rrdcalc_flags |= RRDCALC_FLAG_CRIT_ERROR;
760 +
761 + debug(D_HEALTH,
762 + "Health on host '%s', alarm '%s.%s': critical expression failed with error: %s",
763 + host->hostname, rc->chart ? rc->chart : "NOCHART", rc->name,
764 + buffer_tostring(rc->critical->error_msg)
765 + );
766 + } else {
767 + rc->rrdcalc_flags &= ~RRDCALC_FLAG_CRIT_ERROR;
768 + debug(D_HEALTH, "Health on host '%s', alarm '%s.%s': critical expression gave value "
769 + CALCULATED_NUMBER_FORMAT
770 + ": %s (source: %s)", host->hostname, rc->chart ? rc->chart : "NOCHART",
771 + rc->name, rc->critical->result, buffer_tostring(rc->critical->error_msg),
772 + rc->source
773 + );
774 + critical_status = rrdcalc_value2status(rc->critical->result);
775 + }
776 + }
777 +
778 + // --------------------------------------------------------
779 + // decide the final alarm status
780 +
781 + RRDCALC_STATUS status = RRDCALC_STATUS_UNDEFINED;
782 +
783 + switch (warning_status) {
784 + case RRDCALC_STATUS_CLEAR:
785 + status = RRDCALC_STATUS_CLEAR;
786 + break;
787 +
788 + case RRDCALC_STATUS_RAISED:
789 + status = RRDCALC_STATUS_WARNING;
790 + break;
791 +
792 + default:
793 + break;
794 + }
795 +
796 + switch (critical_status) {
797 + case RRDCALC_STATUS_CLEAR:
798 + if (status == RRDCALC_STATUS_UNDEFINED)
799 + status = RRDCALC_STATUS_CLEAR;
800 + break;
801 +
802 + case RRDCALC_STATUS_RAISED:
803 + status = RRDCALC_STATUS_CRITICAL;
804 + break;
805 +
806 + default:
807 + break;
808 + }
809 +
810 + // --------------------------------------------------------
811 + // check if the new status and the old differ
812 +
813 + if (status != rc->status) {
814 + int delay = 0;
815 +
816 + // apply trigger hysteresis
817 +
818 + if (now > rc->delay_up_to_timestamp) {
819 + rc->delay_up_current = rc->delay_up_duration;
820 + rc->delay_down_current = rc->delay_down_duration;
821 + rc->delay_last = 0;
822 + rc->delay_up_to_timestamp = 0;
823 + } else {
824 + rc->delay_up_current = (int) (rc->delay_up_current * rc->delay_multiplier);
825 + if (rc->delay_up_current > rc->delay_max_duration)
826 + rc->delay_up_current = rc->delay_max_duration;
827 +
828 + rc->delay_down_current = (int) (rc->delay_down_current * rc->delay_multiplier);
829 + if (rc->delay_down_current > rc->delay_max_duration)
830 + rc->delay_down_current = rc->delay_max_duration;
831 + }
832 +
833 + if (status > rc->status)
834 + delay = rc->delay_up_current;
835 + else
836 + delay = rc->delay_down_current;
837 +
838 + // COMMENTED: because we do need to send raising alarms
839 + // if(now + delay < rc->delay_up_to_timestamp)
840 + // delay = (int)(rc->delay_up_to_timestamp - now);
841 +
842 + rc->delay_last = delay;
843 + rc->delay_up_to_timestamp = now + delay;
844
845 if(likely(!rrdcalc_isrepeating(rc))) {
846 ALARM_ENTRY *ae = health_create_alarm_entry(
@@ -858,14 +858,14 @@ void *health_main(void *ptr) {
858 rc->last_status_change = now;
859 rc->old_status = rc->status;
860 rc->status = status;
861 - }
861 + }
862
863 - rc->last_updated = now;
864 - rc->next_update = now + rc->update_every;
863 + rc->last_updated = now;
864 + rc->next_update = now + rc->update_every;
865
866 - if (next_run > rc->next_update)
867 - next_run = rc->next_update;
868 - }
866 + if (next_run > rc->next_update)
867 + next_run = rc->next_update;
868 + }
869
870 // process repeating alarms
871 RRDCALC *rc;
@@ -896,22 +896,22 @@ void *health_main(void *ptr) {
896 }
897 }
898
899 - rrdhost_unlock(host);
900 - }
899 + rrdhost_unlock(host);
900 + }
901
902 - if (unlikely(netdata_exit))
903 - break;
902 + if (unlikely(netdata_exit))
903 + break;
904
905 - // execute notifications
906 - // and cleanup
907 - health_alarm_log_process(host);
905 + // execute notifications
906 + // and cleanup
907 + health_alarm_log_process(host);
908
909 - if (unlikely(netdata_exit))
910 - break;
909 + if (unlikely(netdata_exit))
910 + break;
911
912 - } /* rrdhost_foreach */
912 + } /* rrdhost_foreach */
913
914 - rrd_unlock();
914 + rrd_unlock();
915
916
917 if(unlikely(netdata_exit))