Community discussions

MikroTik App
 
ropebih
Member Candidate
Member Candidate
Topic Author
Posts: 113
Joined: Tue May 22, 2007 5:35 pm

Possible bug with get in /routing bgp advertisements

Tue Aug 09, 2016 9:03 pm

Hi,when I try to get prefix from bgp advertisements I get empty result
/routing bgp advertisements get [find peer="XXX"] value-name=prefix
Does anyone know how to get prefix from advertisements?
 
nikolasc
just joined
Posts: 11
Joined: Wed Jun 04, 2008 10:30 am

Re: Possible bug with get in /routing bgp advertisements

Sun Aug 14, 2016 8:43 am

Unfortunately the only thing that you can get from the “/routing bgp advertisements get” is the internal ID number, not the value-name=prefix
For example
 :put [routing bgp advertisements get number=*0]
.id=*0

One peer have many prefix to advertise and you need :foreach command to find all of those
You can try something like this
:foreach advr in=[/routing bgp advertisements print peer="RR" as-value] do={:put ($advr->"prefix")}
RR (routing reflect) is one of my peer name for example

Something more complex i hade already handy
You can remove the single hash # at :log info to fit your needs
:local pname
:local advrn
:local advrdata
:local advrprefix
:local advrid
:local advrpath
:local aa
:local taa

##  find active peers
:foreach peerid in=[/routing bgp peer find where established] do={
#:log info "$peerid"

## get peer name 
	:set pname [/routing bgp peer get value-name=name number=$peerid]
	
## get how many prefix count it have. at ver 5 is an error thats gives always -1
	:set advrn [/routing bgp advertisements print $peerid count-only as-value]
#	:log info "checking $pname with $advrn advertisment"
## save advertisements to file
# /routing bgp advertisements print peer=$peerid terse file=$pname
# get advertisements to var as array
	:set advrdata [/routing bgp advertisements print $pname as-value]
	
## parse data to vars 
		:foreach advr in=$advrdata do={
		:set advrprefix ($advr->"prefix")
		:set advrid ($advr->".id")
		:set advrpath ($advr->"as-path")
		:set aa ($aa +1)
		:set taa ($taa +1)
#:log info "$advr"
:log info "$aa of peer $pname $taa total with ID $advrid Prefix $advrprefix path $advrpath "
		}

#:log info "Peer $pname result find $aa entrys" 
# reset counter for peer		
:set aa 0		
}
I hope this is helpful for you