I know this post is well over a year old, but since no one has responded to it I thought I would.
This is a reply to aacable.
These are a few sample scripts I created that looks for the system temperature on a MikroTik, logs the current temp, and sends an alert at different temperature checkpoints. It also resets itself so it only sends one alert per temperature checkpoint until it is finally back within spec.
The first script runs on a RB3011 and is a direct export from the MikroTik running WinBox 6.45.3. The script only reads the system temperature, not the CPU temperature.
Code: Select all
/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 ge\
t date] \$tempstatus\") body=(\"This router \$[/system identity get name] \
has a temperature alert. \$[/system clock get date] \$tempstatus - \$syste\
mtemp Celcius\")\r\
\n:log info \"Email sent about system \$tempstatus status\"\r\
\n:set \"templaststatus\" \$\"tempstatus\"\r\
\n}"
Here is the same script but for "us simple folk", it does not include the permissions policies or script name.
Code: Select all
: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"
}
Here is the scheduler to run the script every 10 minutes to check for changes. This is a direct export from the MikroTik.
Code: Select all
/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
This below script checks the system temp and cpu temp, logs the data and emails you alerts at each temperature checkpoint. This was run on a CCR1036 running WinBox 6.42.6.
Code: Select all
: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"
}
You could build the same scheduler for the system temp and cpu temp script and have it run every 10 minutes as well.
I have altered the script so many times from the original one I found online that I forgot where it came from. Obviously the sample script I found online was a lot simpler than mine and was for something else entirely.