Script's

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

Can anyone help?

And who decided that they should work?

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.

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.

It’s always a “vague person” who writes things anyway, there’s always some_phone_ who believes it…

Yes, that's why my answer was that... :laughing: