log-forward: skip multi-repeated messages

This commit is contained in:
Christian Hesse 2021-03-04 18:42:57 +01:00
parent d1741c99fe
commit f762d395eb

View file

@ -37,18 +37,28 @@ $ScriptLock $0;
$WaitFullyConnected; $WaitFullyConnected;
:local Count 0; :local Count 0;
:local Duplicates false;
:local Messages ""; :local Messages "";
:local MessageVal; :local MessageVal;
:local MessageDups [ :toarray "" ];
:foreach Message in=[ / log find where !(topics~$LogForwardFilter) !(message~$LogForwardFilterMessage) ] do={ :foreach Message in=[ / log find where !(topics~$LogForwardFilter) !(message~$LogForwardFilterMessage) ] do={
:set MessageVal [ / log get $Message ]; :set MessageVal [ / log get $Message ];
:if ($LogForwardLast = ($MessageVal->".id")) do={ :if ($LogForwardLast = ($MessageVal->".id")) do={
:set Messages "";
:set Count 0; :set Count 0;
:set Duplicates false;
:set Messages "";
:set MessageDups [ :toarray "" ];
} else={ } else={
:set Messages ($Messages . "\n" . $MessageVal->"time" . " " . \ :local DupCount ($MessageDups->($MessageVal->"message"));
[ :tostr ($MessageVal->"topics") ] . " " . $MessageVal->"message"); :if ($DupCount < 3) do={
:set Messages ($Messages . "\n" . $MessageVal->"time" . " " . \
[ :tostr ($MessageVal->"topics") ] . " " . $MessageVal->"message");
} else={
:set Duplicates true;
}
:set ($MessageDups->($MessageVal->"message")) ($DupCount + 1);
:set Count ($Count + 1); :set Count ($Count + 1);
} }
} }
@ -57,7 +67,8 @@ $WaitFullyConnected;
$SendNotification ([ $SymbolForNotification "warning-sign" ] . "Log Forwarding") \ $SendNotification ([ $SymbolForNotification "warning-sign" ] . "Log Forwarding") \
("The log on " . $Identity . " contains " . [ $IfThenElse ($Count = 1) \ ("The log on " . $Identity . " contains " . [ $IfThenElse ($Count = 1) \
"this message" ("these " . $Count . " messages") ] . " after " . \ "this message" ("these " . $Count . " messages") ] . " after " . \
[ / system resource get uptime ] . " uptime.\n" . $Messages); [ / system resource get uptime ] . " uptime." . [ $IfThenElse ($Duplicates = true) \
(" Multi-repeated messages have been skipped.") ] . "\n" . $Messages);
:set LogForwardRateLimit ($LogForwardRateLimit + 10); :set LogForwardRateLimit ($LogForwardRateLimit + 10);
:set LogForwardLast ($MessageVal->".id"); :set LogForwardLast ($MessageVal->".id");