@rlkoshak why are you assigning the timer to a variable and then adding it to the dict? Have you tried adding it directly to the dict to see if the global is still required?
if event.itemName in alertTimers: alertTimers[event.itemName].stop() del alertTimers[event.itemName] status_alert.log.warning(name + " is flapping!") return
if alerted == str(items[event.itemName]): # Wait one minute before alerting to make sure it isn't flapping alertTimers[event.itemName] = Timer(60, lambda: alert_timer_expired(event.itemName, name, event.itemState)) alertTimers[event.itemName].start()
str() conversion necessary? The metadata functions should be returning values of the same type as the data.
Static="meta"[name="Grafana"] should return a string when fetching the
name value. If you were having issues with it, try
status_alert_rule.log.warn(type(get_key_value(event.itemName, "Alert", "alerted"))) to print the data type to the log.
You are doing two different
None checks here. For
alerted you are doing a check for the value being the string
"None", is that what
get_key_value() is returning? For
name you are checking
== None which is no Pythonic, the correct way to make this check is
if nameKeyVal is not None. In this case the simplest way to write this would be:
name = nameKeyVal if nameKeyVal else event.itemName
This checks if
nameKeyVal has a true-ish value (essentially anything that is not