Last active
April 12, 2024 13:38
-
-
Save tokolist/aab4304c3aba3da0eb11ee72cc16ea7f to your computer and use it in GitHub Desktop.
Mikrotik stable Netwatch alternative script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:local checkHost do={ | |
:global sendTelegramMessage; | |
:global hostStatuses; | |
:local currStatus ([/ping $host count=3] != 0); | |
:local message; | |
if ($currStatus != $hostStatuses->"$host") do={ | |
:if ($currStatus) do={ | |
:set ($message) "%F0%9F%86%99 $name is UP"; | |
} else={ | |
:set ($message) "%E2%9A%A0 $name is DOWN"; | |
} | |
$sendTelegramMessage $message; | |
:set ($hostStatuses->"$host") $currStatus; | |
} | |
} | |
$checkHost host=192.168.9.101 name="Host1"; | |
$checkHost host=192.168.9.102 name="Host2"; | |
$checkHost host=192.168.9.103 name="Host3"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:global urlEncode do={ | |
:local encoded; | |
:for i from=0 to=([:len $1] - 1) do={ | |
:local char [:pick $1 $i]; | |
:if ($char = " ") do={ | |
:set $char "%20"; | |
} | |
:if ($char = "-") do={ | |
:set $char "%2D"; | |
} | |
:set encoded ($encoded . $char) | |
} | |
:return $encoded; | |
}; | |
:global sendTelegramMessage do={ | |
:global urlEncode; | |
:log info "Sending Telegram message: $1"; | |
:local message [$urlEncode $1]; | |
/tool fetch "https://api.telegram.org/bot{REPLACE_WITH_BOT_API_TOKEN}/sendmessage?chat_id={REPLACE_WITH_CHAT_ID}&text=$message" keep-result=no; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment