Skip to content
Snippets Groups Projects
Commit e6d2757a authored by Nikolay Stanchev's avatar Nikolay Stanchev
Browse files

Updates the JSON message sent when an alert is trigerred to include the event identifier

parent e1556eed
No related branches found
No related tags found
No related merge requests found
...@@ -153,7 +153,7 @@ class TICKScriptTemplateFiller: ...@@ -153,7 +153,7 @@ class TICKScriptTemplateFiller:
@staticmethod @staticmethod
def _fill_threshold_batch_template_vars(db=None, measurement=None, field=None, influx_function=None, critical_value=None, def _fill_threshold_batch_template_vars(db=None, measurement=None, field=None, influx_function=None, critical_value=None,
comparison_operator=None, alert_period=None, topic_id=None, where_clause=None, **kwargs): comparison_operator=None, alert_period=None, topic_id=None, event_id=None, where_clause=None, **kwargs):
""" """
Creates a dictionary object ready to be posted to kapacitor to create a "threshold" task from template. Creates a dictionary object ready to be posted to kapacitor to create a "threshold" task from template.
...@@ -165,6 +165,7 @@ class TICKScriptTemplateFiller: ...@@ -165,6 +165,7 @@ class TICKScriptTemplateFiller:
:param comparison_operator: type of comparison :param comparison_operator: type of comparison
:param alert_period: alert period to query influx :param alert_period: alert period to query influx
:param topic_id: topic identifier :param topic_id: topic identifier
:param event_id: event identifier
:param where_clause: (OPTIONAL) argument for filtering the influx query by tag values :param where_clause: (OPTIONAL) argument for filtering the influx query by tag values
:return: a dictionary object ready to be posted to kapacitor to create a "threshold" task from template. :return: a dictionary object ready to be posted to kapacitor to create a "threshold" task from template.
...@@ -200,6 +201,10 @@ class TICKScriptTemplateFiller: ...@@ -200,6 +201,10 @@ class TICKScriptTemplateFiller:
"topicID": { "topicID": {
"type": "string", "type": "string",
"value": topic_id "value": topic_id
},
"eventID": {
"type": "string",
"value": event_id
} }
} }
...@@ -213,7 +218,7 @@ class TICKScriptTemplateFiller: ...@@ -213,7 +218,7 @@ class TICKScriptTemplateFiller:
@staticmethod @staticmethod
def _fill_threshold_stream_template_vars(db=None, measurement=None, field=None, critical_value=None, def _fill_threshold_stream_template_vars(db=None, measurement=None, field=None, critical_value=None,
comparison_operator=None, topic_id=None, where_clause=None, **kwargs): comparison_operator=None, topic_id=None, event_id=None, where_clause=None, **kwargs):
""" """
Creates a dictionary object ready to be posted to kapacitor to create a "threshold" task from template. Creates a dictionary object ready to be posted to kapacitor to create a "threshold" task from template.
...@@ -225,6 +230,7 @@ class TICKScriptTemplateFiller: ...@@ -225,6 +230,7 @@ class TICKScriptTemplateFiller:
:param comparison_operator: type of comparison :param comparison_operator: type of comparison
:param alert_period: alert period to query influx :param alert_period: alert period to query influx
:param topic_id: topic identifier :param topic_id: topic identifier
:param event_id: event identifier
:param where_clause: (OPTIONAL) argument for filtering the influx query by tag values :param where_clause: (OPTIONAL) argument for filtering the influx query by tag values
:return: a dictionary object ready to be posted to kapacitor to create a "threshold" task from template. :return: a dictionary object ready to be posted to kapacitor to create a "threshold" task from template.
...@@ -248,6 +254,10 @@ class TICKScriptTemplateFiller: ...@@ -248,6 +254,10 @@ class TICKScriptTemplateFiller:
"topicID": { "topicID": {
"type": "string", "type": "string",
"value": topic_id "value": topic_id
},
"eventID": {
"type": "string",
"value": event_id
} }
} }
...@@ -262,7 +272,7 @@ class TICKScriptTemplateFiller: ...@@ -262,7 +272,7 @@ class TICKScriptTemplateFiller:
@staticmethod @staticmethod
def _fill_relative_template_vars(db=None, measurement=None, field=None, influx_function=None, critical_value=None, comparison_operator=None, def _fill_relative_template_vars(db=None, measurement=None, field=None, influx_function=None, critical_value=None, comparison_operator=None,
alert_period=None, topic_id=None, where_clause=None, **kwargs): alert_period=None, topic_id=None, event_id=None, where_clause=None, **kwargs):
""" """
Creates a dictionary object ready to be posted to kapacitor to create a "relative" task from template. Creates a dictionary object ready to be posted to kapacitor to create a "relative" task from template.
...@@ -274,6 +284,7 @@ class TICKScriptTemplateFiller: ...@@ -274,6 +284,7 @@ class TICKScriptTemplateFiller:
:param comparison_operator: type of comparison :param comparison_operator: type of comparison
:param alert_period: alert period to use for relative comparison :param alert_period: alert period to use for relative comparison
:param topic_id: topic identifier :param topic_id: topic identifier
:param event_id: event identifier
:param where_clause: (OPTIONAL) argument for filtering the influx query by tag values :param where_clause: (OPTIONAL) argument for filtering the influx query by tag values
:return: a dictionary object ready to be posted to kapacitor to create a "relative" task from template. :return: a dictionary object ready to be posted to kapacitor to create a "relative" task from template.
...@@ -309,6 +320,10 @@ class TICKScriptTemplateFiller: ...@@ -309,6 +320,10 @@ class TICKScriptTemplateFiller:
"topicID": { "topicID": {
"type": "string", "type": "string",
"value": topic_id "value": topic_id
},
"eventID": {
"type": "string",
"value": event_id
} }
} }
...@@ -321,7 +336,7 @@ class TICKScriptTemplateFiller: ...@@ -321,7 +336,7 @@ class TICKScriptTemplateFiller:
return template_vars return template_vars
@staticmethod @staticmethod
def _fill_deadman_template_vars(db=None, measurement=None, critical_value=None, alert_period=None, topic_id=None, where_clause=None, **kwargs): def _fill_deadman_template_vars(db=None, measurement=None, critical_value=None, alert_period=None, topic_id=None, event_id=None, where_clause=None, **kwargs):
""" """
Creates a dictionary object ready to be posted to kapacitor to create a "deadman" task from template. Creates a dictionary object ready to be posted to kapacitor to create a "deadman" task from template.
...@@ -330,6 +345,7 @@ class TICKScriptTemplateFiller: ...@@ -330,6 +345,7 @@ class TICKScriptTemplateFiller:
:param critical_value: critical value to compare with :param critical_value: critical value to compare with
:param alert_period: alert period to use for relative comparison :param alert_period: alert period to use for relative comparison
:param topic_id: topic identifier :param topic_id: topic identifier
:param event_id: event identifier
:param where_clause: (OPTIONAL) argument for filtering the influx query by tag values :param where_clause: (OPTIONAL) argument for filtering the influx query by tag values
:return: a dictionary object ready to be posted to kapacitor to create a "deadman" task from template. :return: a dictionary object ready to be posted to kapacitor to create a "deadman" task from template.
...@@ -355,6 +371,10 @@ class TICKScriptTemplateFiller: ...@@ -355,6 +371,10 @@ class TICKScriptTemplateFiller:
"topicID": { "topicID": {
"type": "string", "type": "string",
"value": topic_id "value": topic_id
},
"eventID": {
"type": "string",
"value": event_id
} }
} }
......
...@@ -253,7 +253,7 @@ class AlertsConfigurationAPI(object): ...@@ -253,7 +253,7 @@ class AlertsConfigurationAPI(object):
# all extracted properties from the trigger are passed, the TICKScriptTemplateFiller entry point then forwards those to the appropriate function for template filling # all extracted properties from the trigger are passed, the TICKScriptTemplateFiller entry point then forwards those to the appropriate function for template filling
template_vars = TICKScriptTemplateFiller.fill_template_vars(event_type, db=db, measurement=measurement, field=field, influx_function=influx_function, template_vars = TICKScriptTemplateFiller.fill_template_vars(event_type, db=db, measurement=measurement, field=field, influx_function=influx_function,
critical_value=critical_value, comparison_operator=comparison_operator, alert_period=alert_period, critical_value=critical_value, comparison_operator=comparison_operator, alert_period=alert_period,
topic_id=topic_id, where_clause=where_clause) topic_id=topic_id, event_id=event_id, where_clause=where_clause)
# create and activate alert task through the kapacitor HTTP API # create and activate alert task through the kapacitor HTTP API
kapacitor_api_tasks_url = "http://{0}:{1}/kapacitor/v1/tasks".format(kapacitor_host, kapacitor_port) kapacitor_api_tasks_url = "http://{0}:{1}/kapacitor/v1/tasks".format(kapacitor_host, kapacitor_port)
......
...@@ -14,6 +14,8 @@ var throughputThreshold float // alerts will trigger if data points reported du ...@@ -14,6 +14,8 @@ var throughputThreshold float // alerts will trigger if data points reported du
var topicID string var topicID string
var eventID string // topicID is based on the event ID, but represents a hash value
stream stream
| from() | from()
...@@ -22,7 +24,7 @@ stream ...@@ -22,7 +24,7 @@ stream
.measurement(measurement) .measurement(measurement)
.where(whereClause) .where(whereClause)
| deadman(throughputThreshold, alertPeriod) | deadman(throughputThreshold, alertPeriod)
.id(topicID) .id(eventID)
.details('db=' + db + ',measurement=' + measurement) .details('db=' + db + ',measurement=' + measurement)
.message(messageValue) .message(messageValue)
.topic(topicID) .topic(topicID)
......
...@@ -18,6 +18,8 @@ var alertPeriod duration ...@@ -18,6 +18,8 @@ var alertPeriod duration
var topicID string var topicID string
var eventID string // topicID is based on the event ID, but represents a hash value
var current = batch var current = batch
|query('SELECT ' + influxFunction + '(' + field + ') AS value FROM "' + db + '"."' + rp + '"."' + measurement + '" WHERE ' + whereClause) |query('SELECT ' + influxFunction + '(' + field + ') AS value FROM "' + db + '"."' + rp + '"."' + measurement + '" WHERE ' + whereClause)
...@@ -39,7 +41,7 @@ past ...@@ -39,7 +41,7 @@ past
| eval(lambda: float("current.value" - "past.value")) | eval(lambda: float("current.value" - "past.value"))
.as('diff') .as('diff')
| alert() | alert()
.id(topicID) .id(eventID)
.details('db=' + db + ',measurement=' + measurement) .details('db=' + db + ',measurement=' + measurement)
.crit(comparisonLambda) .crit(comparisonLambda)
.message(messageValue) .message(messageValue)
......
...@@ -18,13 +18,14 @@ var alertPeriod duration ...@@ -18,13 +18,14 @@ var alertPeriod duration
var topicID string var topicID string
var eventID string // topicID is based on the event ID, but represents a hash value
batch batch
|query('SELECT ' + influxFunction + '(' + field + ') AS real_value FROM "' + db + '"."' + rp + '"."' + measurement + '" WHERE ' + whereClause) |query('SELECT ' + influxFunction + '(' + field + ') AS real_value FROM "' + db + '"."' + rp + '"."' + measurement + '" WHERE ' + whereClause)
.period(alertPeriod) .period(alertPeriod)
.every(alertPeriod) .every(alertPeriod)
|alert() |alert()
.id(topicID) .id(eventID)
.details('db=' + db + ',measurement=' + measurement) .details('db=' + db + ',measurement=' + measurement)
.crit(comparisonLambda) .crit(comparisonLambda)
.message(messageValue) .message(messageValue)
......
...@@ -12,6 +12,8 @@ var comparisonLambda lambda // comparison function e.g. "real_value" > 40 ...@@ -12,6 +12,8 @@ var comparisonLambda lambda // comparison function e.g. "real_value" > 40
var topicID string var topicID string
var eventID string // topicID is based on the event ID, but represents a hash value
stream stream
| from() | from()
...@@ -20,7 +22,7 @@ stream ...@@ -20,7 +22,7 @@ stream
.measurement(measurement) .measurement(measurement)
.where(whereClause) .where(whereClause)
| alert() | alert()
.id(topicID) .id(eventID)
.details('db=' + db + ',measurement=' + measurement) .details('db=' + db + ',measurement=' + measurement)
.crit(comparisonLambda) .crit(comparisonLambda)
.message(messageValue) .message(messageValue)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment