Community discussions

 
User avatar
simeitg
just joined
Topic Author
Posts: 15
Joined: Tue May 30, 2017 4:44 am

Script to monitor temperature

Wed Jan 10, 2018 1:44 pm

Hi! I have used a lot this forum to solve a bunch of problems, and today i would like to contribute a little.
Here is a small script to monitore the temperature of a CCR 1036, and send a email if its ok, or send a sms if its above the limit.
Here in brazil temperatures can rise very quick in the summer, so i want to know if the A/C its ok!
After the script just make a scheduler to run every 30min.
________________________________________________________________________________
:global tcasinha [/system health get temperature]
:local emessage ("Temperature is " . [:pick $tcasinha 0 2] . "." . [:pick $tcasinha 2 3])
:if ($tcasinha >= 40) do={
:log info $tcasinha
/tool sms send usb3 "yourcellphonehere" message=$emessage
} else={
/tool e-mail send to="youremailhere" subject="TEMP_CASINHA" body=$emessage start-tls=yes
}
________________________________________________________________________________
 
User avatar
frank333
Member Candidate
Member Candidate
Posts: 117
Joined: Mon Dec 18, 2017 12:17 pm
Location: italy Router model: RB3011UiAS-RM

Re: Script to monitor temperature

Sun Jan 14, 2018 6:02 pm

Here in brazil temperatures can rise very quick in the summer, so i want to know if the A/C its ok!
works wonderfully!!
typical Brazilian temperature 40C° :-P :-P
Obrigado!
 
plisken
Forum Guru
Forum Guru
Posts: 2409
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: Script to monitor temperature

Fri Feb 02, 2018 2:50 am

Working like a charm thanks :)
 
User avatar
nichky
Long time Member
Long time Member
Posts: 522
Joined: Tue Jun 23, 2015 2:35 pm

Re: Script to monitor temperature

Fri Feb 02, 2018 5:55 am

nice :)

Thanks
Nikola Suminoski
MikroTik Consultan
MTCRE l MTCWE

!) Safe Mode is your friend;
 
nikpefan
just joined
Posts: 1
Joined: Thu Dec 08, 2016 12:20 pm

Re: Script to monitor temperature

Wed Feb 07, 2018 9:42 am

In a situation where you have other schedulers on your router, how will the scheduler know which script to run??
 
User avatar
aacable
Member
Member
Posts: 423
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: Script to monitor temperature

Sat Mar 03, 2018 6:18 pm

Seems Good.
I would like to provide some feedback on the script.

Let's say what if we schedule it to run every 5 minutes? It will run, & do following
- Check temperature, compare it with threshold value , if condition true, LOG & Send SMS Alert.

Now after 5 minutes , the script executes again, & do the following ...
- Check temperature, compare it with threshold value , if condition true, LOG & Send SMS Alert AGAIN.

& repeats actions after every 5 minutes. What if the temperature remains above threshold value all day long & no one available at support to rectify that? You will receive annoying messages many many times or specific action many times.

To prevent this, what you can do is to add IF statement . like IF the Threshold value reaches, send SMS, and then create an empty file name sms_sent.txt
Now you should add a check option before sending sms that if "sms_sent.txt" file is available, then Don't sms send, because sms already sent , just log warning in LOG window. once temperature goes ok, then just delete sms_sent.txt file, there are other tuning you might want to do like once temperate comes ok, then send OK sms once only by adding second check as well.
_____________
Regard's

Syed Jahanzaib
Web: http://aacable.wordpress.com
Email: aacable [at] hotmail.com
 
theycallmetimmy
just joined
Posts: 3
Joined: Fri Sep 06, 2019 3:13 pm

Re: Script to monitor temperature

Fri Sep 06, 2019 3:58 pm

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.
Last edited by theycallmetimmy on Mon Sep 09, 2019 2:22 pm, edited 1 time in total.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1291
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Script to monitor temperature

Mon Sep 09, 2019 8:05 am

I know this post is well over a year old, but since no one has responded to it I thought I would.
Please edit your post.
Select code block and click the </> button above the text field to code tag scripts.
like this
:global "systemtemp" [/system health get temperature]
:global "cputemp" [/system health get cpu-temperature]
Scipt should also test if these two gives a value in return since hAP lite does not give none, hex gives temperature but not cpu-temperature, so they will fail.

Why use global variable? her could local variable be used.
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
theycallmetimmy
just joined
Posts: 3
Joined: Fri Sep 06, 2019 3:13 pm

Re: Script to monitor temperature

Mon Sep 09, 2019 2:31 pm

Thanks for the tip on the code tags Jotne, I have edited my original post.

As for using :global instead of :local, there wasn't a reason besides being able to see the script output on the script>Environment tab. That way you can check your work to make sure it's outputting the correct data. Also since I'm using global, I can use the temperature readings for other scripts if I needed to.

My script doesn't check for returned values because I wrote it for the RB3011 and CCR1036. Anyone can alter it for whatever MikroTik they choose to use. I wrote two sample scripts, one to check for system temperature and one to check for system&cpu temperature.

I know this post is well over a year old, but since no one has responded to it I thought I would.
Please edit your post.
Select code block and click the </> button above the text field to code tag scripts.
like this
:global "systemtemp" [/system health get temperature]
:global "cputemp" [/system health get cpu-temperature]
Scipt should also test if these two gives a value in return since hAP lite does not give none, hex gives temperature but not cpu-temperature, so they will fail.

Why use global variable? her could local variable be used.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1291
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Script to monitor temperature

Mon Sep 09, 2019 3:42 pm

As for using :global instead of :local, there wasn't a reason besides being able to see the script output on the script>Environment tab.
I do always run the script from command line using :put to see whats going on like this:
{
:local systemtemp [/system health get temperature]
:put $systemtemp 
}

PS Do not quote the complete post above you. To reply on a post click "Post Reply" below the post.
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
theycallmetimmy
just joined
Posts: 3
Joined: Fri Sep 06, 2019 3:13 pm

Re: Script to monitor temperature

Mon Sep 09, 2019 3:54 pm

Okay. Like I said, you can configure the script however you want for whatever MikroTik you use.
 
User avatar
aacable
Member
Member
Posts: 423
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: Script to monitor temperature

Wed Sep 11, 2019 9:46 am

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.
Nice One mate !
_____________
Regard's

Syed Jahanzaib
Web: http://aacable.wordpress.com
Email: aacable [at] hotmail.com

Who is online

Users browsing this forum: No registered users and 8 guests