I would like some help on a couple of scripts that should work but don't.
1. This one is supposed to warn me about the device's board temperature rising:
Code: Select all
:log info ("$[/system health get temperature] $[/system health get voltage]")
:if ([/system health get temperature]>45) do={/tool e-mail send to="mikrotik@xxx.info" subject=[/system identity get name] body=("High temperature. Current temperature is: ".[/system health get temperature])}
:if ([/system health get voltage]<245) do={/tool e-mail send to="me@somewhere.net" subject=[/system identity get name] body=("Low Voltage Alarm. Current voltage is: ".[/system health get voltage])}
: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"
}
:local emailTo "mikrotik@xxx.info"
:local thresholdTemperature 60 ; Заменете с желаната температурна прагова стойност в градуси Целзий
:local currentTemperature [ /system health get temperature ]
:if ($currentTemperature >= $thresholdTemperature) do={
:log warning ("High temperature detected! Current temperature: " . $currentTemperature . " C")
/tool e-mail send to=$emailTo subject="High Temperature Warning" body=("High temperature detected on MikroTik. Current temperature: " . $currentTemperature . " C")
}
2.This one should warn me about the appearance of a specific MAC address on the network:
Code: Select all
:log info "Starting script...";
:log info ("Email to: " . $mikrotik@xxx.info);
:local emailTo "mikrotik@xxx.info"
:local subject "otkrit nov MAC adres"
:local monitoredMac "A8:5E:45:18:xx:xx" ; ???????? ? ?????????? MAC ?????, ????? ?????? ?? ???????
:local knownMacs
# ?????? ?? ???????? ????? ???????? MAC ?????? ?? ????
:if ([/file find name="known-macs.txt"] != "") do={
:set knownMacs [/file get [find name="known-macs.txt"] contents]
} else {
:set knownMacs ""
}
# ??????????? ARP ?????????? ?? ???? MAC ??????
:foreach i in=[/ip arp find where dynamic=yes] do={
:local currentMac [/ip arp get $i mac-address]
# ???????????, ???? MAC ??????? ? ????????
:if ([:find $knownMacs $currentMac] = -1) do={
# ????????? ?????, ??? ? ??? MAC ?????
/tool e-mail send to="mikrotik@xxx.info"=$subject body=("Otkrit new MAC adres: " . $currentMac)
# ???????? MAC ?????? ??? ??????????
:set knownMacs ($knownMacs . "," . $currentMac)
}
}
# ????????? ?????????? MAC ?????? ??? ????
/file set [find name="known-macs.txt"] contents=$knownMacs