Community discussions

MikroTik App
 
psu
just joined
Topic Author
Posts: 4
Joined: Thu Nov 23, 2023 9:19 am

Script's

Thu Nov 23, 2023 9:32 am

Hello
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:

: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:

: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
Last edited by tangent on Thu Nov 23, 2023 11:06 am, edited 1 time in total.
Reason: wrapped scripts in code blocks
 
psu
just joined
Topic Author
Posts: 4
Joined: Thu Nov 23, 2023 9:19 am

Re: Script's

Wed Nov 29, 2023 4:09 pm

Can anyone help?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12032
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script's

Fri Dec 01, 2023 2:37 am

that should work but don't
And who decided that they should work?

Ask the original author.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3610
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Script's

Fri Dec 01, 2023 3:14 am

Ask the original author.
LOL... Oh, @rextended, I think you and I know the author...

But OP can tell "the author" that RouterOS script uses # as a comment line and does not support them "inline" with script. So it needs to fix the code since the generated code is incorrectly using semi-colons before a inline comment – that's wrong.
 
psu
just joined
Topic Author
Posts: 4
Joined: Thu Nov 23, 2023 9:19 am

Re: Script's

Fri Dec 01, 2023 3:27 pm

Hello,
The script for detecting mac addresses was written for me by a person who told me that he was interested in the idea, but I had to manage the settings myself.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3610
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Script's

Fri Dec 01, 2023 3:56 pm

Hello,
The script for detecting mac addresses was written for me by a person who told me that he was interested in the idea, but I had to manage the settings myself.
It looks like ChatGPT, which is pretty bad a writing routeros script... thus the commentary.

But as I said, the lines with the semi-colon are not valid as comments are not allowed after the semi-colon ( # is comment and must be on separate line)

The script had some line like:
:local thresholdTemperature 60 ; Заменете с желаната температурна прагова стойност в градуси Целзий

:local monitoredMac "A8:5E:45:18:xx:xx" ; ???????? ? ?????????? MAC ?????, ????? ?????? ?? ???????
You need to remove the semi-colon and the text after it.

If you search this forum there are few scripts to monitor temp and email. Or suggest what error's your getting, that might help.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12032
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script's

Sat Dec 02, 2023 11:17 am

was written for me by a person who told me that he was interested in the idea,
but I had to manage the settings myself.
It's always a "vague person" who writes things anyway, there's always somephone who believes it...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12032
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script's

Sat Dec 02, 2023 11:18 am

Ask the original author.
LOL... Oh, @rextended, I think you and I know the author...
Yes, that's why my answer was that... :lol:

Who is online

Users browsing this forum: Ahrefs [Bot] and 5 guests