mirror of
https://github.com/xcat2/confluent.git
synced 2025-01-17 21:23:18 +00:00
Force Input data to be correct data
Provide a way to coerce input string data to integer for alert parameters that are numeric.
This commit is contained in:
parent
24eb872090
commit
f52eec6c19
@ -692,11 +692,11 @@ class AlertDestination(ConfluentMessage):
|
||||
|
||||
|
||||
class InputAlertDestination(ConfluentMessage):
|
||||
valid_alert_params = (
|
||||
'acknowledge',
|
||||
'ip',
|
||||
'retries'
|
||||
)
|
||||
valid_alert_params = {
|
||||
'acknowledge': lambda x: x,
|
||||
'ip': lambda x: x,
|
||||
'retries': lambda x: int(x)
|
||||
}
|
||||
|
||||
def __init__(self, path, nodes, inputdata, multinode=False):
|
||||
self.alertcfg = {}
|
||||
@ -709,14 +709,22 @@ class InputAlertDestination(ConfluentMessage):
|
||||
'Unrecognized alert parameter ' + key)
|
||||
if isinstance(inputdata[node][key], dict):
|
||||
self.alertcfg[node][key] = \
|
||||
inputdata[node][key]['value']
|
||||
self.valid_alert_params[key](
|
||||
inputdata[node][key]['value'])
|
||||
else:
|
||||
self.alertcfg[node][key] = \
|
||||
self.valid_alert_params[key](inputdata[node][key])
|
||||
else:
|
||||
for key in inputdata:
|
||||
if key not in self.valid_alert_params:
|
||||
raise exc.InvalidArgumentException(
|
||||
'Unrecognized alert parameter ' + key)
|
||||
if isinstance(inputdata[key], dict):
|
||||
inputdata[key] = inputdata[key]['value']
|
||||
inputdata[key] = self.valid_alert_params[key](
|
||||
inputdata[key]['value'])
|
||||
else:
|
||||
inputdata[key] = self.valid_alert_params[key](
|
||||
inputdata[key])
|
||||
for node in nodes:
|
||||
self.alertcfg[node] = inputdata
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user