Community discussions

 
User avatar
Jotne
Forum Veteran
Forum Veteran
Topic Author
Posts: 977
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

How to get multiple data using "value-name"

Fri May 17, 2019 10:58 pm

This script does print comment, address and host-name from all dhcp lease
/ip dhcp-server lease
:foreach i in=[find] do={
: put "$[get value-name=comment $i] $[get value-name=address $i] $[get value-name=host-name $i]"
}
Can this be shorten in any way?

I was looking for some like the example below
value-name=(comment|address|host-name)
value-name=comment,address,host-name
value-name="comment address host-name"
But this does not work.
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 213
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: How to get multiple data using "value-name"

Sun May 19, 2019 2:08 am

Solved
:do {/ip dhcp-server lease
 :foreach i in=[find] do={
 :put ("comment=" . [get $i value-name=comment] . ", address=" . [get $i value-name=address] . ", host-name=" . [get $i value-name=host-name]);
 }
} on-error={}
 
User avatar
Jotne
Forum Veteran
Forum Veteran
Topic Author
Posts: 977
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: How to get multiple data using "value-name"

Sun May 19, 2019 8:10 am

This was even more code than what I have used. Gol was to do it more simple. (shorten)
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
User avatar
eworm
Member Candidate
Member Candidate
Posts: 283
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: How to get multiple data using "value-name"

Mon May 20, 2019 3:20 pm

How about this?
:foreach i in=[ print as-value ] do={
  :put (($i->"comment") . " " . ($i->"address") . " " . ($i->"host-name"));
}
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts
 
User avatar
Jotne
Forum Veteran
Forum Veteran
Topic Author
Posts: 977
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: How to get multiple data using "value-name"

Mon May 20, 2019 3:31 pm

Interesting and shorter.

Trying to understand how it works ;)

To make sure it works in all location i would have used full command like this:
:foreach i in=[ /ip dhcp-server lease print as-value ] do={
  :put (($i->"comment") . " " . ($i->"address") . " " . ($i->"host-name"));
}
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
User avatar
eworm
Member Candidate
Member Candidate
Posts: 283
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: How to get multiple data using "value-name"

Mon May 20, 2019 4:23 pm

To make sure it works in all location i would have used full command like this:
Usually I do. I started from your code, but did not notice the first line was appended to your written text. :lol:
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts

Who is online

Users browsing this forum: No registered users and 8 guests