Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77732cd

Browse files
committed
src/utils_threshold.c: Fix creation of percentage notifications.
Joey Hess has reported a problem when creating notifications from percentage thresholds. Because the (percentage) minimum value is compared to the (raw) DS value, the following message is possible: Message: Host XXX, plugin df type df (instance root): Data source "free" is currently 1773072384.000000. That is above the warning threshold of nan%. A new section will handle this case correctly. In the inverted case, the problem should not exist.
1 parent 589c5f2 commit 77732cd

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/utils_threshold.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,15 +727,41 @@ static int ut_report_state (const data_set_t *ds,
727727
((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
728728
}
729729
}
730+
else if (th->flags & UT_FLAG_PERCENTAGE)
731+
{
732+
gauge_t value;
733+
gauge_t sum;
734+
int i;
735+
736+
sum = 0.0;
737+
for (i = 0; i < vl->values_len; i++)
738+
{
739+
if (isnan (values[i]))
740+
continue;
741+
742+
sum += values[i];
743+
}
744+
745+
if (sum == 0.0)
746+
value = NAN;
747+
else
748+
value = 100.0 * values[ds_index] / sum;
749+
750+
status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
751+
"%g (%.2f%%). That is %s the %s threshold of %.2f%%.",
752+
ds->ds[ds_index].name, values[ds_index], value,
753+
(value < min) ? "below" : "above",
754+
(state == STATE_ERROR) ? "failure" : "warning",
755+
(value < min) ? min : max);
756+
}
730757
else /* is not inverted */
731758
{
732759
status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
733-
"%f. That is %s the %s threshold of %f%s.",
760+
"%f. That is %s the %s threshold of %f.",
734761
ds->ds[ds_index].name, values[ds_index],
735762
(values[ds_index] < min) ? "below" : "above",
736763
(state == STATE_ERROR) ? "failure" : "warning",
737-
(values[ds_index] < min) ? min : max,
738-
((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
764+
(values[ds_index] < min) ? min : max);
739765
}
740766
buf += status;
741767
bufsize -= status;

0 commit comments

Comments
 (0)