From 6d9eb99e08fb0a1ac8dc03213edfd5f590655ee4 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 16 Oct 2020 22:51:51 +0200 Subject: check-health: add deviation on temperature recovery threshold This helps against notification flooding. --- check-health | 19 +++++++++++++------ global-config | 4 +++- global-config-overlay | 2 +- global-config.changes | 1 + global-functions | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/check-health b/check-health index c27178d..ff4cf36 100644 --- a/check-health +++ b/check-health @@ -8,6 +8,8 @@ :global CheckHealthLast; :global CheckHealthTemperature; +:global CheckHealthTemperatureDeviation; +:global CheckHealthTemperatureNotified; :global CheckHealthVoltagePercent; :global Identity; @@ -26,6 +28,10 @@ $LogPrintExit error ("Your device does not provide any health values.") true; } +:if ([ :typeof $CheckHealthTemperatureNotified ] != "array") do={ + :set CheckHealthTemperatureNotified [ :toarray "" ]; +} + :foreach Voltage in={ "battery"; "psu1-voltage"; "psu2-voltage"; "voltage" } do={ :if ([ :typeof ($CheckHealthLast->$Voltage) ] = "num" && \ [ :typeof ($CheckHealthCurrent->$Voltage) ] = "num") do={ @@ -56,23 +62,24 @@ } :foreach Temperature in={ "temperature"; "cpu-temperature"; "board-temperature1"; "board-temperature2" } do={ - :if ([ :typeof ($CheckHealthLast->$Temperature) ] = "num" && \ - [ :typeof ($CheckHealthCurrent->$Temperature) ] = "num") do={ + :if ([ :typeof ($CheckHealthCurrent->$Temperature) ] = "num") do={ :if ([ :typeof ($CheckHealthTemperature->$Temperature) ] != "num" ) do={ $LogPrintExit warning ("No threshold given for " . $Temperature . ", assuming 50C.") false; :set ($CheckHealthTemperature->$Temperature) 50; } - :if ($CheckHealthLast->$Temperature <= $CheckHealthTemperature->$Temperature && \ - $CheckHealthCurrent->$Temperature > $CheckHealthTemperature->$Temperature) do={ + :if ($CheckHealthCurrent->$Temperature > $CheckHealthTemperature->$Temperature && \ + $CheckHealthTemperatureNotified->$Temperature != true) do={ $SendNotification ([ $SymbolForNotification "fire" ] . "Health warning: " . $Temperature) \ ("The " . $Temperature . " on " . $Identity . " is above threshold: " . \ $CheckHealthCurrent->$Temperature . "\C2\B0" . "C"); + :set ($CheckHealthTemperatureNotified->$Temperature) true; } - :if ($CheckHealthLast->$Temperature > $CheckHealthTemperature->$Temperature && \ - $CheckHealthCurrent->$Temperature <= $CheckHealthTemperature->$Temperature) do={ + :if ($CheckHealthCurrent->$Temperature <= ($CheckHealthTemperature->$Temperature - $CheckHealthTemperatureDeviation) && \ + $CheckHealthTemperatureNotified->$Temperature = true) do={ $SendNotification ([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Temperature) \ ("The " . $Temperature . " on " . $Identity . " dropped below threshold: " . \ $CheckHealthCurrent->$Temperature . "\C2\B0" . "C"); + :set ($CheckHealthTemperatureNotified->$Temperature) false; } } } diff --git a/global-config b/global-config index c90c4cb..8721f8d 100644 --- a/global-config +++ b/global-config @@ -8,7 +8,7 @@ # Make sure all configuration properties are up to date and this # value is in sync with value in script 'global-functions'! -:global GlobalConfigVersion 32; +:global GlobalConfigVersion 33; # This is used for DNS and backup file. :global Domain "example.com"; @@ -71,6 +71,8 @@ board-temperature1=50; board-temperature2=50; } +# This is deviation on recovery threshold against notification flooding. +:global CheckHealthTemperatureDeviation 2; :global CheckHealthVoltagePercent 10; # This controls what configuration is activated by bridge-port-to-default. diff --git a/global-config-overlay b/global-config-overlay index 246c013..984e577 100644 --- a/global-config-overlay +++ b/global-config-overlay @@ -9,7 +9,7 @@ # Make sure all configuration properties are up to date and this # value is in sync with value in script 'global-functions'! # Comment or remove to disable change notifications. -:global GlobalConfigVersion 32; +:global GlobalConfigVersion 33; # Copy configuration from global-config here and modify it. diff --git a/global-config.changes b/global-config.changes index aadc588..04f8a53 100644 --- a/global-config.changes +++ b/global-config.changes @@ -36,4 +36,5 @@ 30="Implemented simple rate limit for 'log-forward' to prevent flooding."; 31="Switched Telegram notifications to fixed-width font, with opt-out."; 32="Merged mode (& reset) button scripts in single new script 'mode-button'."; + 33="Added configurable deviation on health temperature recovery threshold against notification flooding."; }; diff --git a/global-functions b/global-functions index 38c6cde..10f14f6 100644 --- a/global-functions +++ b/global-functions @@ -8,7 +8,7 @@ # https://git.eworm.de/cgit/routeros-scripts/about/ # expected configuration version -:global ExpectedConfigVersion 32; +:global ExpectedConfigVersion 33; # global variables not to be changed by user :global GlobalFunctionsReady false; -- cgit v1.2.3-70-g09d2