Community discussions

 
CR24
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 56
Joined: Wed Dec 04, 2013 10:32 pm

DHCP Binding Triggers Script

Tue Dec 11, 2018 9:37 pm

I currently have a script that adds bound DHCP entries to an address list, this script is set to run every 30 seconds. Rather than have it scheduled to run every 30 seconds is it possible to have another script that parses the logs and searches for an entry with "Msg-Type = ack" in it then runs the first script? If so can someone assist with the creation of that script?
Last edited by CR24 on Tue Dec 11, 2018 9:57 pm, edited 1 time in total.
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1776
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

Re: DHCP Binding Triggers Script

Tue Dec 11, 2018 9:51 pm

Hey, you could attach a script to dhcp server, to do something on ip assignment.

See https://wiki.mikrotik.com/wiki/Manual:I ... er#General -> lease-script (string; Default: "")
 
CR24
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 56
Joined: Wed Dec 04, 2013 10:32 pm

Re: DHCP Binding Triggers Script

Tue Dec 11, 2018 10:24 pm

I tried this, no luck, did I do something wrong?
#Add Lease to Address List
#DCHP Script
 
 
:if ($leaseBound = "1") do={
    /ip firewall address-list add list=DHCP-WL address=($leaseActIP) timeout="03:00:00"
}
Last edited by CR24 on Tue Dec 11, 2018 10:34 pm, edited 1 time in total.
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1776
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

Re: DHCP Binding Triggers Script

Tue Dec 11, 2018 10:32 pm

To start with (debug phase), try logging the values received.
You could also test the script by invoking it manually, and when happy paste/call it.
 
CR24
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 56
Joined: Wed Dec 04, 2013 10:32 pm

Re: DHCP Binding Triggers Script

Tue Dec 11, 2018 10:34 pm

It worked actually, just only for new entries, I was reconnecting a current entry to the network and the lease was refreshing but it was not triggering the script. Do you know what tweaks I would need to make to get it to refresh current leases?
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1776
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

Re: DHCP Binding Triggers Script

Tue Dec 11, 2018 10:46 pm

If it behaves like the dhcp client part, it will only be triggered on assignment, de-assignment & change (!=previous ip).
Hack: remove all current leases ;-)
 
CR24
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 56
Joined: Wed Dec 04, 2013 10:32 pm

Re: DHCP Binding Triggers Script

Tue Dec 11, 2018 10:50 pm

My worry is once the timeout expires on the address list, will it get re-added to the address list if the lease is still active?
 
CR24
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 56
Joined: Wed Dec 04, 2013 10:32 pm

Re: DHCP Binding Triggers Script

Tue Dec 11, 2018 10:57 pm

Instead of running the script at the DHCP script I just had to call the system script that I was running on a schedule before. Got it working as I need.

Thanks for the help.





#Add Lease to Address List
 
 
:if ($leaseBound = "1") do={
    /system script run 0
}
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1776
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

Re: DHCP Binding Triggers Script

Tue Dec 11, 2018 11:05 pm

Good to hear. Note: you might want to run script by name, so you won't brake it in future
/system script run <name>

Edit: indeed a "typo"
Last edited by sebastia on Wed Dec 12, 2018 1:41 am, edited 1 time in total.
 
User avatar
CZFan
Forum Guru
Forum Guru
Posts: 1393
Joined: Sun Oct 09, 2016 8:25 pm
Location: South Africa, Randburg
Contact:

Re: DHCP Binding Triggers Script

Tue Dec 11, 2018 11:37 pm

Good to hear. Note: you might want to run script by name, so you won't brake it in future
/system run script <name>
/system script run <name> :-)
MTCNA, MTCTCE, MTCRE & MTCINE

Who is online

Users browsing this forum: No registered users and 3 guests