diff --git a/src/service/clmcservice/alertsapi/utilities.py b/src/service/clmcservice/alertsapi/utilities.py index 5a2f3afb45a4264dcb73eddbb13bde7758fb0549..eba22f2c3e631b8548ed4d3c79dcff591d302187 100644 --- a/src/service/clmcservice/alertsapi/utilities.py +++ b/src/service/clmcservice/alertsapi/utilities.py @@ -153,7 +153,7 @@ class TICKScriptTemplateFiller: @staticmethod 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. @@ -165,6 +165,7 @@ class TICKScriptTemplateFiller: :param comparison_operator: type of comparison :param alert_period: alert period to query influx :param topic_id: topic identifier + :param event_id: event identifier :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. @@ -200,6 +201,10 @@ class TICKScriptTemplateFiller: "topicID": { "type": "string", "value": topic_id + }, + "eventID": { + "type": "string", + "value": event_id } } @@ -213,7 +218,7 @@ class TICKScriptTemplateFiller: @staticmethod 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. @@ -225,6 +230,7 @@ class TICKScriptTemplateFiller: :param comparison_operator: type of comparison :param alert_period: alert period to query influx :param topic_id: topic identifier + :param event_id: event identifier :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. @@ -248,6 +254,10 @@ class TICKScriptTemplateFiller: "topicID": { "type": "string", "value": topic_id + }, + "eventID": { + "type": "string", + "value": event_id } } @@ -262,7 +272,7 @@ class TICKScriptTemplateFiller: @staticmethod 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. @@ -274,6 +284,7 @@ class TICKScriptTemplateFiller: :param comparison_operator: type of comparison :param alert_period: alert period to use for relative comparison :param topic_id: topic identifier + :param event_id: event identifier :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. @@ -309,6 +320,10 @@ class TICKScriptTemplateFiller: "topicID": { "type": "string", "value": topic_id + }, + "eventID": { + "type": "string", + "value": event_id } } @@ -321,7 +336,7 @@ class TICKScriptTemplateFiller: return template_vars @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. @@ -330,6 +345,7 @@ class TICKScriptTemplateFiller: :param critical_value: critical value to compare with :param alert_period: alert period to use for relative comparison :param topic_id: topic identifier + :param event_id: event identifier :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. @@ -355,6 +371,10 @@ class TICKScriptTemplateFiller: "topicID": { "type": "string", "value": topic_id + }, + "eventID": { + "type": "string", + "value": event_id } } diff --git a/src/service/clmcservice/alertsapi/views.py b/src/service/clmcservice/alertsapi/views.py index 027302e47802306fe74b3f0f9b36384b224cd249..74ce6e928c2495243c64dec30906d4f942755fb7 100644 --- a/src/service/clmcservice/alertsapi/views.py +++ b/src/service/clmcservice/alertsapi/views.py @@ -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 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, - 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 kapacitor_api_tasks_url = "http://{0}:{1}/kapacitor/v1/tasks".format(kapacitor_host, kapacitor_port) diff --git a/src/service/resources/TICKscript/deadman-template.tick b/src/service/resources/TICKscript/deadman-template.tick index 2392b7716a3ee60acbaaaef4e6319e13b35f1bf2..5762d4ad5505972b989f1561a36ede5e3bc099b7 100644 --- a/src/service/resources/TICKscript/deadman-template.tick +++ b/src/service/resources/TICKscript/deadman-template.tick @@ -14,6 +14,8 @@ var throughputThreshold float // alerts will trigger if data points reported du var topicID string +var eventID string // topicID is based on the event ID, but represents a hash value + stream | from() @@ -22,7 +24,7 @@ stream .measurement(measurement) .where(whereClause) | deadman(throughputThreshold, alertPeriod) - .id(topicID) + .id(eventID) .details('db=' + db + ',measurement=' + measurement) .message(messageValue) .topic(topicID) diff --git a/src/service/resources/TICKscript/relative-template.tick b/src/service/resources/TICKscript/relative-template.tick index 2363ef4e2ddd284040e825af1433c2ee658e6ee1..30ac95c962a6bf547c93935810beb2d108a38b3f 100644 --- a/src/service/resources/TICKscript/relative-template.tick +++ b/src/service/resources/TICKscript/relative-template.tick @@ -18,6 +18,8 @@ var alertPeriod duration var topicID string +var eventID string // topicID is based on the event ID, but represents a hash value + var current = batch |query('SELECT ' + influxFunction + '(' + field + ') AS value FROM "' + db + '"."' + rp + '"."' + measurement + '" WHERE ' + whereClause) @@ -39,7 +41,7 @@ past | eval(lambda: float("current.value" - "past.value")) .as('diff') | alert() - .id(topicID) + .id(eventID) .details('db=' + db + ',measurement=' + measurement) .crit(comparisonLambda) .message(messageValue) diff --git a/src/service/resources/TICKscript/threshold-batch-template.tick b/src/service/resources/TICKscript/threshold-batch-template.tick index 5518814f5a4c652fdf9c6b70496de486261a5678..379a49c4fffb030f8f1775c658c1b25cf8f64d2e 100644 --- a/src/service/resources/TICKscript/threshold-batch-template.tick +++ b/src/service/resources/TICKscript/threshold-batch-template.tick @@ -18,13 +18,14 @@ var alertPeriod duration var topicID string +var eventID string // topicID is based on the event ID, but represents a hash value batch |query('SELECT ' + influxFunction + '(' + field + ') AS real_value FROM "' + db + '"."' + rp + '"."' + measurement + '" WHERE ' + whereClause) .period(alertPeriod) .every(alertPeriod) |alert() - .id(topicID) + .id(eventID) .details('db=' + db + ',measurement=' + measurement) .crit(comparisonLambda) .message(messageValue) diff --git a/src/service/resources/TICKscript/threshold-stream-template.tick b/src/service/resources/TICKscript/threshold-stream-template.tick index f0800ddf73ef335388c08c9e0496b1f5b9926e95..6ee92fd2c03b7d68efa871bff02dc53b29f1c1fd 100644 --- a/src/service/resources/TICKscript/threshold-stream-template.tick +++ b/src/service/resources/TICKscript/threshold-stream-template.tick @@ -12,6 +12,8 @@ var comparisonLambda lambda // comparison function e.g. "real_value" > 40 var topicID string +var eventID string // topicID is based on the event ID, but represents a hash value + stream | from() @@ -20,7 +22,7 @@ stream .measurement(measurement) .where(whereClause) | alert() - .id(topicID) + .id(eventID) .details('db=' + db + ',measurement=' + measurement) .crit(comparisonLambda) .message(messageValue)