From 6e4d7159378259a521e467504509de871381d078 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Nov 2018 14:08:14 +0100 Subject: global-functions: add identity tag in $SendNotification ... and send subject in telegram message. --- check-certificates | 2 +- check-routeros-update | 4 ++-- collect-wireless-mac.capsman | 2 +- collect-wireless-mac.local | 2 +- collect-wireless-mac.template | 2 +- daily-psk | 2 +- global-config | 2 +- global-functions | 6 ++++-- sms-forward | 2 +- 9 files changed, 13 insertions(+), 11 deletions(-) diff --git a/check-certificates b/check-certificates index 566b013..557589e 100644 --- a/check-certificates +++ b/check-certificates @@ -36,7 +36,7 @@ :local fingerprint [ / certificate get $cert fingerprint ]; :local invalidbefore [ / certificate get $cert invalid-before ]; :local invalidafter [ / certificate get $cert invalid-after ]; - $SendNotification ("[" . $identity . "] Certificate warning!") \ + $SendNotification ("Certificate warning!") \ ("A certificate on " . $identity . " is about to expire.\n\n" . \ "Certificate Name: " . $certname . "\n" . \ "Common Name: " . $commonname . "\n" . \ diff --git a/check-routeros-update b/check-routeros-update index caafe3f..ee7afb5 100644 --- a/check-routeros-update +++ b/check-routeros-update @@ -32,7 +32,7 @@ "&latest=" . $latestversion) output=user as-value ]; :if ($result->"status" = "finished" && $result->"data" = $latestversion) do={ :log info ("Version " . $latestversion . " is assumed safe, updating..."); - $SendNotification ("[" . $identity . "] RouterOS update notification") \ + $SendNotification ("RouterOS update notification") \ ("Version " . $latestversion . " is assumed safe for " . $channel . \ ", updating on " . $identity . "..."); / system package update install; @@ -45,7 +45,7 @@ $latestversion . "."); } - $SendNotification ("[" . $identity . "] RouterOS update notification") \ + $SendNotification ("RouterOS update notification") \ ("There is a RouterOS update available\n\n" . \ "Routerboard: " . $model . "\n" . \ "Serial number: " . $serialnumber . "\n" . \ diff --git a/collect-wireless-mac.capsman b/collect-wireless-mac.capsman index 2d7885f..46bf7fd 100644 --- a/collect-wireless-mac.capsman +++ b/collect-wireless-mac.capsman @@ -40,7 +40,7 @@ $datetime . " connected to SSID " . $ssid . ", interface " . $interface); / log info $message; / caps-man access-list add place-before=$"place-before" comment=$message mac-address=$mac disabled=yes; - $SendNotification ("[" . $identity . "] " . $mac . " connected to " . $ssid) \ + $SendNotification ($mac . " connected to " . $ssid) \ ("A device with unknown MAC address connected to " . $ssid . " on " . $identity . ".\n\n" . \ "Controller: " . $identity . "\n" . \ "Interface: " . $interface . "\n" . \ diff --git a/collect-wireless-mac.local b/collect-wireless-mac.local index 9800fab..3416046 100644 --- a/collect-wireless-mac.local +++ b/collect-wireless-mac.local @@ -40,7 +40,7 @@ $datetime . " connected to SSID " . $ssid . ", interface " . $interface); / log info $message; / interface wireless access-list add place-before=$"place-before" comment=$message mac-address=$mac disabled=yes; - $SendNotification ("[" . $identity . "] " . $mac . " connected to " . $ssid) \ + $SendNotification ($mac . " connected to " . $ssid) \ ("A device with unknown MAC address connected to " . $ssid . " on " . $identity . ".\n\n" . \ "Controller: " . $identity . "\n" . \ "Interface: " . $interface . "\n" . \ diff --git a/collect-wireless-mac.template b/collect-wireless-mac.template index ec6cff0..784bfb9 100644 --- a/collect-wireless-mac.template +++ b/collect-wireless-mac.template @@ -42,7 +42,7 @@ $datetime . " connected to SSID " . $ssid . ", interface " . $interface); / log info $message; / %PATH% access-list add place-before=$"place-before" comment=$message mac-address=$mac disabled=yes; - $SendNotification ("[" . $identity . "] " . $mac . " connected to " . $ssid) \ + $SendNotification ($mac . " connected to " . $ssid) \ ("A device with unknown MAC address connected to " . $ssid . " on " . $identity . ".\n\n" . \ "Controller: " . $identity . "\n" . \ "Interface: " . $interface . "\n" . \ diff --git a/daily-psk b/daily-psk index 37302d8..ca1702e 100644 --- a/daily-psk +++ b/daily-psk @@ -93,7 +93,7 @@ :set attach ""; } - $SendNotification ("[" . $identity . "] daily PSK " . $ssid) \ + $SendNotification ("daily PSK " . $ssid) \ ("This is the daily PSK on " . $identity . ":\n\n" . \ "SSID: " . $ssid . "\n" . \ "PSK: " . $newpsk . "\n" . \ diff --git a/global-config b/global-config index b60ea3c..cff8974 100644 --- a/global-config +++ b/global-config @@ -66,7 +66,7 @@ # Run different commands with multiple mode-button presses. :global "mode-button" { 1="/ system script run leds-toggle-mode;"; - 2=":global SendNotification; :global identity; \$SendNotification (\"[\" . \$identity . \"] Hello...\") (\"Hello world, \" . \$identity . \" calling!\");"; + 2=":global SendNotification; :global identity; \$SendNotification (\"Hello...\") (\"Hello world, \" . \$identity . \" calling!\");"; 3="/ system shutdown;"; 4="/ system reboot;"; 5="/ system script run bridge-port-toggle;"; diff --git a/global-functions b/global-functions index 5f38150..ff689d8 100644 --- a/global-functions +++ b/global-functions @@ -61,6 +61,7 @@ :local message [ :tostr $2 ]; :local attach [ :tostr $3 ]; + :global "identity"; :global "email-general-to"; :global "email-general-cc"; :global "telegram-tokenid"; @@ -72,7 +73,7 @@ :if ([ :len $"email-general-to" ] > 0) do={ :do { / tool e-mail send to=$"email-general-to" cc=$"email-general-cc" \ - subject=$subject body=$message file=$attach; + subject=("[" . $"identity" . "] " . $subject) body=$message file=$attach; } on-error={ :log warning "Failed sending notification mail!"; } @@ -83,7 +84,8 @@ :do { / tool fetch check-certificate=yes-without-crl keep-result=no http-method=post \ ("https://api.telegram.org/bot" . $"telegram-tokenid" . "/sendMessage") \ - http-data=("chat_id=" . $"telegram-chatid" . "&text=" . [ $UrlEncode $message ]); + http-data=("chat_id=" . $"telegram-chatid" . "&text=" . \ + [ $UrlEncode ("[" . $"identity" . "] " . $subject . "\n\n" . $message) ]); } on-error={ :log warning "Failed sending telegram notification!"; } diff --git a/sms-forward b/sms-forward index 644e6c9..cc7eccd 100644 --- a/sms-forward +++ b/sms-forward @@ -26,7 +26,7 @@ :if ($phone = $allowed && message~("^:cmd " . $secret . " script ")) do={ :log debug "Ignoring SMS, which starts a script."; } else={ - $SendNotification ("[" . $identity . "] SMS Forwarding") \ + $SendNotification ("SMS Forwarding") \ ("A message was received by " . $identity . ":\n\n" . \ "Phone: " . $phone . "\n" . \ "Timestamp: " . $timestamp . "\n" . \ -- cgit v1.2.3-54-g00ecf