threshold: fix statistics empty case

If no statistics are return, it's then impossible to log the last
result. Accessing this provokes an IndexError.

Change-Id: I6929d3e4b1549b941df434ca708a5c839edb8d77
Closes-Bug: #1539069
This commit is contained in:
Julien Danjou 2016-01-28 14:25:50 +01:00
parent 5a2acf7930
commit dea148d2e3

View File

@ -131,7 +131,7 @@ class ThresholdEvaluator(evaluator.Evaluator):
"""Fabricate reason string."""
count = len(statistics)
disposition = 'inside' if state == evaluator.OK else 'outside'
last = statistics[-1]
last = statistics[-1] if count else None
transition = alarm.state != state
reason_data = cls._reason_data(disposition, count, last)
if transition: