From a123f6c037eb267010244b969910018bc6eab9df Mon Sep 17 00:00:00 2001 From: Massimo Candela Date: Sun, 27 Oct 2019 14:38:28 +0100 Subject: [PATCH] introduced alertOnlyOnce configuration parameter --- config.yml.example | 16 +++++++++++++++- docs/configuration.md | 5 ++--- env.js | 1 + monitors/monitor.js | 9 ++++++--- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/config.yml.example b/config.yml.example index dd3fc4f..6acd784 100644 --- a/config.yml.example +++ b/config.yml.example @@ -99,7 +99,21 @@ reports: # default: bgpalerter -notificationIntervalSeconds: 7200 # Repeat the same alert (which keeps being triggered) after x seconds +############################ +# Notification settings: +# - notificationIntervalSeconds +# Defines the amount of seconds after which an alert can be repeated. An alert is repeated only if the event that +# triggered it is not yet solved. Please, don't set this value to Infinity, use instead alertOnlyOnce. +# +# - alertOnlyOnce - A boolean that, if set to true, will prevent repetitions of the same alert even if the event that +# triggered it is not yet solved. In this case notificationIntervalSeconds will be ignored. +# If set to true, the signature of all alerts will be cached in order to recognize if they already happened in +# the past. This may lead to a memory leak if the amount of alerts is considerable. + +notificationIntervalSeconds: 7200 +alertOnlyOnce: false + +############################ # Below the files containing the monitored prefixes. Please see prefixes.yml for an example. # This is an array (use new lines and dashes!) diff --git a/docs/configuration.md b/docs/configuration.md index 6f9be11..8633217 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -7,9 +7,8 @@ The following are common parameters which it is possible to specify in the confi | Parameter | Description | Expected format | Example | Required | |---|---|---|---|---| |environment| You can specify various environments. The values "production" (not verbose) and "development" (verbose) will affect the verbosity of the error/debug logs. Other values don't affect the functionalities, they will be used to identify from which environment the log is coming from. | A string | production | Yes | -|notificationIntervalSeconds| The amount of seconds before the same alert can be repeated. An alert is repeated only if the cause of it has not being solved. | An integer | 1800 | Yes | -|clearNotificationQueueAfterSeconds| If the cause of an alert is resolved, then stop waiting for more information about the issue. | An integer (greater than notificationIntervalSeconds) | 1900 | Yes | -|checkStaleNotificationsSeconds| The amount of seconds between a check on stale alerts. A stale alert happens when the cause of an alert is resolved before the next notification round, in such a case send it anyway. | An integer | 60 | Yes | +|notificationIntervalSeconds|Defines the amount of seconds after which an alert can be repeated. An alert is repeated only if the event that triggered it is not yet solved. Please, don't set this value to Infinity, use instead alertOnlyOnce. | An integer | 1800 | Yes | +|alertOnlyOnce| A boolean that, if set to true, will prevent repetitions of the same alert even if the event that triggered it is not yet solved. In this case notificationIntervalSeconds will be ignored. If set to true, the signature of all alerts will be cached in order to recognize if they already happened in the past. This may lead to a memory leak if the amount of alerts is considerable. | A boolean | false | No | |monitoredPrefixesFiles| The [list](docs/prefixes.md#array) of files containing the prefixes to monitor. See [here](docs/prefixes.md#prefixes) for more informations. | A list of strings (valid .yml files) | -prefixes.yml | Yes | |logging| A dictionary of parameters containing the configuration for the file logging. | || Yes| |logging.directory| The directory where the log files will be generated. The directory will be created if not existent. | A string | logs | Yes | diff --git a/env.js b/env.js index 6be33cd..17c213d 100644 --- a/env.js +++ b/env.js @@ -107,6 +107,7 @@ let config = { } ], notificationIntervalSeconds: 7200, + alarmOnlyOnce: false, monitoredPrefixesFiles: ["prefixes.yml"], logging: { directory: "logs", diff --git a/monitors/monitor.js b/monitors/monitor.js index 6843527..a5c8a71 100644 --- a/monitors/monitor.js +++ b/monitors/monitor.js @@ -134,8 +134,9 @@ export default class Monitor { }; _clean = (group) => { - - if (new Date().getTime() > group.latest + (this.internalConfig.clearNotificationQueueAfterSeconds * 1000)) { + if (this.config.alertOnlyOnce) { + delete this.alerts[group.id]; + } else if (this.config.alertOnlyOnce && new Date().getTime() > group.latest + (this.internalConfig.clearNotificationQueueAfterSeconds * 1000)) { delete this.alerts[group.id]; delete this.sent[group.id]; @@ -148,7 +149,9 @@ export default class Monitor { _checkLastSent = (group) => { const lastTimeSent = this.sent[group.id]; - if (lastTimeSent) { + if (lastTimeSent && this.config.alertOnlyOnce) { + return false; + } else if (lastTimeSent) { const isThereSomethingNew = lastTimeSent < group.latest; const isItTimeToSend = new Date().getTime() > lastTimeSent + (this.internalConfig.notificationIntervalSeconds * 1000);