Community discussions

MikroTik App
 
axon
just joined
Topic Author
Posts: 2
Joined: Tue May 03, 2022 3:59 pm

Finding etherX from supplied MAC addresses to switch PoE on/off

Tue May 03, 2022 4:18 pm

Hi there :)
With increasing gas/electricity prices, I want to automate PoE nightly downtime for some of my devices. Currently, I have a fixed number of etherX ports, which are automatically turned off in the evening and on again in the morning, namely VoIP phones. I want to widen this and include some of my my single board computers, capable of being powered via PoE as well.
I would like this to be less specific regarding the Miktorik's connection name and more about the network devices' MAC addresses instead. Is this possible?
My current scripts are very minimal and run with two schedulers on my CRS328-24P-4S+

turning off
:foreach ethname in={"ether2"; "ether16"; "ether18"; "ether19"; "ether20"} do={/interface ethernet poe set poe-out=off $ethname}

turning on
:foreach ethname in={"ether2"; "ether16"; "ether18"; "ether19"; "ether20"} do={/interface ethernet poe set poe-out=auto-on $ethname}
My thinking is to provide the script with a list of MAC addresses that then finds the correct ethname where the device is connected and then turns them on/off.
Would it be possible to have partial MAC addresses as well e.g. like a device family and then find all that match it e.g. finding all Voip phones of a certain manufacturer or all single board computers.

I am quite new to scripting with this and the energy preserving geek in me wants to reduce the electricity usage if possible. Every W(att) counts :D

Thanks, axon
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Finding etherX from supplied MAC addresses to switch PoE on/off

Tue May 03, 2022 4:57 pm

Is possible to "search" the devices UNTIL the MAC are on ARP CACHE or Bridge Hosts, but is unaffidable,
precisely because there are caches,
and they do not represent whether the devices are connected or not.

Hint: put inside a interface comment something like "powersave" and do:
/interface ethernet poe
set [find where comment~"powersave"] poe-out=off


/interface ethernet poe
set [find where comment~"powersave"] poe-out=auto-on
 
axon
just joined
Topic Author
Posts: 2
Joined: Tue May 03, 2022 3:59 pm

Re: Finding etherX from supplied MAC addresses to switch PoE on/off  [SOLVED]

Tue May 10, 2022 11:54 am

Hi,
Thanks for the initial idea! I cannot get this to work though.
I added the keyword that is used in the "find" command to those ether entries, that are using PoE and can be powered down. Then I created a new script using the supplied code. I have tried to use Terminal, as well as running the script, but there are no error messages. I am a bit clueless as to what to consult in order to find out, where this is going wrong or not working. The log file does not seem to include much detail on this either.

Edit: I have tried to play around with :put to see some/any output on the terminal for find, but do not get any feedback e.g.
:put [find where comment~"powersave"]
, but that returns just an error.

Edit2: I played a bit with the find part of the script and it seems it works in general, but not for the comment field, or with the regex. When using the "name" field(?) of an interface, it seems to work. Any idea, why this does not work for the "Comment" field?

Edit3/Solution: It seems the "Comment" field is just unable to work with find - I am not sure if I can/should turn the field into string to behave well with the regex check as per find command. A quick test by adding powersave to the name field at the end shows, that this can work indeed. In another late night going through the forum, I read about the consistently inconsistent behaviour and implementation on Mikrotik, which I guess is very applicable in this case. I don't think this should be the solution, but at least this might help someone else.
So, in short:

Add the keyword "powersave" to the name field e.g. if it is called ether8, corresponding by default with port 8, and add powersave to the end, thus renaming it to ether8powersave. Then the following commands will indeed turn alll of these off or on:
/interface ethernet poe set [find where name~"powersave"] poe-out=off
/interface ethernet poe set [find where name~"powersave"] poe-out=auto-on
 

Who is online

Users browsing this forum: No registered users and 20 guests