Implement alert on InfluxDB error messages

This commit is contained in:
emanuele-f 2020-01-28 15:09:02 +01:00
parent 9ae15b7cf0
commit 9833a87cbc
3 changed files with 25 additions and 1 deletions

View file

@ -4,6 +4,8 @@
local user_scripts = require("user_scripts")
local ts_utils = require("ts_utils_core")
local alerts_api = require("alerts_api")
local alert_consts = require("alert_consts")
local script = {
-- Script category
@ -37,6 +39,7 @@ end
script.hooks["5mins"] = function(params)
if params.ts_enabled then
local influxdb = ts_utils.getQueryDriver()
local when = params.when
script._exportStats(when, influxdb)
script._measureRtt(when, influxdb)
@ -46,6 +49,26 @@ end
-- ##############################################
-- Defines an hook which is executed every minute
script.hooks["min"] = function(params)
local last_error = ntop.getCache("ntopng.cache.influxdb.last_error")
-- Note: last_error is automatically cleared once the error is gone
if(not isEmptyString(last_error)) then
local influxdb = ts_utils.getQueryDriver()
alerts_api.store(
alerts_api.influxdbEntity(influxdb.url), {
alert_type = alert_consts.alert_types.alert_influxdb_error,
alert_severity = alert_consts.alert_severities.error,
alert_granularity = alert_consts.alerts_granularities.min,
alert_type_params = {error_msg = last_error},
}, params.when)
end
end
-- ##############################################
function script.getExportStats()
local points_exported
local points_dropped