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
(cherry picked from commit dea148d2e3)
This commit is contained in:
Julien Danjou 2016-01-28 14:25:50 +01:00
parent 6b3113c23f
commit 36c656d6e3
1 changed files with 1 additions and 1 deletions

View File

@ -160,7 +160,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: