Я знаю, что этому посту больше года, но раз на него никто не ответил, решил сделать это я. Это ответ aacable. Вот несколько примеров скриптов, которые я создал для мониторинга температуры системы на MikroTik, записи текущей температуры в лог и отправки уведомлений при достижении разных температурных порогов. Скрипт также сбрасывает себя, чтобы отправлять только одно уведомление на каждый температурный порог, пока температура не вернётся в норму.
Первый скрипт запущен на RB3011 и является прямым экспортом из MikroTik с WinBox 6.45.3. Скрипт считывает только температуру системы, а не процессора.
/system script add dont-require-permissions=no name=Check-system-Temp owner=admin policy= ftp,reboot,read,write,policy,test,password,sniff,sensitive source=“:global _"tempstatus"\r\n:global "templaststatus"\r\n:global "systemtemp" [/system health get temperature]\r\n:if (systemtemp > "50") do={:set "tempstatus" "system temp is too high"}\r\n:if (systemtemp > "60") do={:set "tempstatus" "system temp is critical"}\r\n:if (systemtemp < "40") do={:set "tempstatus" "system temp is within spec"}\r\n:if ($"tempstatus" != $"templaststatus") do {\r\n/tool e-mail send to="your-email-here@email.com" subject=("This router $[/system identity get name] has a temperature alert. $[/system clock get date] $tempstatus") body=("This router $[/system identity get name] has a temperature alert. $[/system clock get date] $tempstatus - $systemtemp Celcius")\r\n:log info "Email sent about system $tempstatus status"\r\n:set "templaststatus" $"tempstatus"\r\n}“
Вот тот же скрипт, но для «простых смертных», без указания политик разрешений и имени скрипта:
:global “tempstatus”
:global “templaststatus”
:global “systemtemp” [/system health get temperature]
:if (systemtemp > “50”) do={:set “tempstatus” “system temp is too high”}
:if (systemtemp > “60”) do={:set “tempstatus” “system temp is critical”}
:if (systemtemp < “40”) do={:set “tempstatus” “system temp is within spec”}
:if ($“tempstatus” != $“templaststatus”) do {
/tool e-mail send to="your-email-here@email.com" subject=(“This router $[/system identity get name] has a temperature alert. $[/system clock get date] $tempstatus”) body=(“This router $[/system identity get name] has a temperature alert. $[/system clock get date] $tempstatus - $systemtemp Celcius”)
:log info “Email sent about system $tempstatus status”
:set “templaststatus” $“tempstatus”
}
А вот планировщик, который запускает этот скрипт каждые 10 минут для проверки изменений. Это прямой экспорт из MikroTik.
/system scheduler add interval=10m name=“Check system Temp” on-event=Check-system-Temp policy= ftp,reboot,read,write,policy,test,password,sniff,sensitive start-time=startup
Ниже скрипт, который проверяет и температуру системы, и процессора, записывает данные в лог и отправляет письма при достижении каждого температурного порога. Запускался на CCR1036 с WinBox 6.42.6.
:global “tempstatus”
:global “templaststatus”
:global “cputempstatus”
:global “cputemplaststatus”
:global “systemtemp” [/system health get temperature]
:global “cputemp” [/system health get cpu-temperature]
:if (systemtemp > “50”) do={:set “tempstatus” “system temp is too high”}
:if (systemtemp > “60”) do={:set “tempstatus” “system temp is critical”}
:if (systemtemp < “40”) do={:set “tempstatus” “system temp is within spec”}
:if (cputemp > “65”) do={:set “cputempstatus” “cpu temp is too high”}
:if (cputemp > “75”) do={:set “cputempstatus” “cpu temp is critical”}
:if (cputemp < “64”) do={:set “cputempstatus” “cpu temp is within spec”}
:if ($“tempstatus” != $“templaststatus”) do {
/tool e-mail send to="your-email-here@email.com" subject=(“This router $[/system identity get name] has a temperature alert. $[/system clock get date] $tempstatus”) body=(“This router $[/system identity get name] has a temperature alert. $[/system clock get date] $tempstatus - $systemtemp Celcius”)
:log info “Email sent about system $tempstatus status”
:set “templaststatus” $“tempstatus”
}
:if ($“cputempstatus” != $“cputemplaststatus”) do {
/tool e-mail send to="your-email-here@email.com" subject=(“This router $[/system identity get name] has a temperature alert. $[/system clock get date] $cputempstatus”) body=(“This router $[/system identity get name] has a temperature alert. $[/system clock get date] $cputempstatus - $cputemp Celcius”)
:log info “Email sent about system $cputempstatus status”
:set “cputemplaststatus” $“cputempstatus”
}
Можно сделать такой же планировщик для скрипта, мониторящего и системную, и процессорную температуру, с запуском каждые 10 минут. Я столько раз переделывал этот скрипт, взятый когда-то из интернета, что уже и забыл, откуда он вообще. Видимо, исходный скрипт, который я нашёл, был гораздо проще и предназначался для совсем другой задачи.