Community discussions

MikroTik App
 
saied
just joined
Topic Author
Posts: 5
Joined: Tue Mar 17, 2020 7:04 pm

Help with where statement

Wed Sep 29, 2021 7:10 pm

Hello,
I am a newbie in Mikrotik scritpting and just learning the ropes right now. I have a script that works correctly but I need to put a where statement in this script to not run where it detects an agent remote id field.
the current script is :
/ip dhcp-server lease
 :foreach dhcplease in=[find] do={
 :local dhcpip [get $dhcplease address]
 :local dhcpmac [get $dhcplease mac-address]
 :put $dhcpmac
 :put $dhcpip
 :do { /tool fetch url="https://$url/api/v1/network/ipam/dynamic_ip_assignment?ip_address=$dhcpip&mac_address=$dhcpmac" mode=https keep-result=yes user=$username password=$password } on-error={} ;
		}	
I would like to put where statement on this script to not run when it detects the agent-remote-id is not Null. But I am not sure where to put this where statement at..
Thanks
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help with where statement

Wed Sep 29, 2021 7:55 pm

I would like to put where statement on this script to not run when it detects the agent-remote-id is not Null
->
I would like to put where statement on this script to not run when it detects the agent-remote-id is not Null.

/ip dhcp-server lease
:foreach dhcplease in=[find] do={
    :local dhcpip [get $dhcplease address]
    :local dhcpmac [get $dhcplease mac-address]
    :local dhcprid [get $dhcplease agent-remote-id]
    :if ([:typeof $dhcprid] = "nil") do={
        :do {
            /tool fetch user=$username password=$password \
            url="https://$url/api/v1/network/ipam/dynamic_ip_assignment?ip_address=$dhcpip&mac_address=$dhcpmac"
        } on-error={ }
    }
}
 
saied
just joined
Topic Author
Posts: 5
Joined: Tue Mar 17, 2020 7:04 pm

Re: Help with where statement

Wed Sep 29, 2021 11:02 pm

I would like to put where statement on this script to not run when it detects the agent-remote-id is not Null
->
I would like to put where statement on this script to not run when it detects the agent-remote-id is not Null.

/ip dhcp-server lease
:foreach dhcplease in=[find] do={
    :local dhcpip [get $dhcplease address]
    :local dhcpmac [get $dhcplease mac-address]
    :local dhcprid [get $dhcplease agent-remote-id]
    :if ([:typeof $dhcprid] = "nil") do={
        :do {
            /tool fetch user=$username password=$password \
            url="https://$url/api/v1/network/ipam/dynamic_ip_assignment?ip_address=$dhcpip&mac_address=$dhcpmac"
        } on-error={ }
    }
}
Thank you . I will run this.
I need to learn Mikrotik Scripting. Does anyone offer any scripting courses or something or any video tutorials? I feel like I don't know how any of this works.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help with where statement

Wed Sep 29, 2021 11:54 pm

You sure?
Did you notice that I have changed very few things?
Your script was almost all written correctly...
Often other scripts that I correct are monstrous...

You are on your way.
I didn't take any courses, I learned easily because I had already programmed in the past on other languages​...
Unfortunately I don't know what to recommend...

Who is online

Users browsing this forum: GoogleOther [Bot] and 14 guests