cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1904
Views
5
Helpful
2
Replies

Moquery - not able to filter ethpmPhysIf "dn" to only return a certain Node

vv0bbLeS
Level 1
Level 1

Hello all,

 

My end goal here is to figure out whether a certain physical port on a certain Node is up or down. To accomplish this, I figured I would query the Ethernet Port Manager Physical Interface class ( ethpmPhysIf ), and return the dn and operSt fields.

 

In my moquery commands, when I query the ethpmPhysIf class, I find I am unable to "filter" (-f or query-target-filter) on the dn property for the node-xxx part of the string. (I can of course filter using grep but this won't accomplish my end goal as I need more than the dn field returned - I need the dn and operSt fields returned).

 

For example, take this ethpmPhysIf dn value:

dn: topology/pod-1/node-216/sys/phys-[eth1/19]/phys

 

I find that I am unable to filter my moquery command to return only objects for node-216. I have tried the below commands, each of which returns No Mos found :

moquery -c ethpmPhysIf -f 'ethpm.PhysIf.dn*"node-216"'
moquery -c ethpmPhysIf -x 'query-target-filter=wcard(ethpmPhysIf.dn,"node-216")'

 

Interestingly, in a dn value like topology/pod-1/node-216/sys/phys-[eth1/19]/phys , I find I am unable to filter on any field before the sys field. So if I try to filter the dn on "topology", "pod", or "node" it returns No Mos found. (It makes me wonder if the topology/pod-1/node-216/ part of the dn is actually a string in the output or not.)

 

 

Does anyone know how to filter the dn of the ethpmPhysIf class to return only results for a particular node? Or better yet, does anyone know how to use moquery to determine if a particular physical port on a Node is up or down ?

0xD2A6762E
1 Accepted Solution

Accepted Solutions

@RedNectar  Thanks for your reply. I didn't know you could set variables in bash but that makes sense, so that is cool!

 

In looking at it, your query is basically like what I was doing using grep without variables, and I'm guessing filtering using grep will be the only way to get the information I need in this particular case. Basically I will have to get all interfaces in a certain state (i.e. all "down" interfaces), and then filter the output and see if my particular interface is in the list.

 

So, let's say I wanted to see if eth1/6 was down on node 216, I would use this command and see if I got any output:

 

moquery -c ethpmPhysIf -f 'ethpm.PhysIf.operSt=="down"' | grep node-216 | grep eth1/6

 

If I did get a line of output, it means the interface is down. If I didn't get any output, I could change the .operSt filter to "up" and run the command again to confirm the interface is up. So that is probably the best solution in this case. Thanks for the confirmation of my syntax, and also that there might be a bug in filtering the dn on the ethpmPhysIf class!

 

 

SIDE NOTE:

Interestingly, in my searching Google for moquery stuff I ended up reading a little bit of a blog post yesterday without knowing it was yours, and you mentioned using awk filtering (which I then became very curious about, and discovered awk stands for the inventors of it, Aho, Weinberger, and Kernighan). Compared to grep (created of course by Ken Thompson, "get [regular expression] print" ) , awk definitely gives better performance when parsing large files/output since awk is stream-based, so it doesn't need to read the whole file/output into memory before it begins parsing for matches. The only caveat with awk is it is a bit more difficult/awkward (pun intended) to format a command with awk than with grep

 

So we can achieve the same result as above using awk :

moquery -c ethpmPhysIf -f 'ethpm.PhysIf.operSt=="down"' | awk '{if (($3 ~ "node-216") && ($3 ~ "eth1/6")) print $3}'

 

But of course that is much more difficult to type on the fly, and for this small of a result set awk only gives about 1 second of improved performance over grep, so in this case using grep would be more desirable. However, I could definitely see a good use for awk in ACI for parsing through large result sets, such as ACI log messages. So, I appreciate you mentioning awk in your blog post, as it gave me another option to have in my toolkit for filtering ACI output!

0xD2A6762E

View solution in original post

2 Replies 2

RedNectar
VIP
VIP

Hi @vv0bbLeS ,

moquery is a beast - and has some bugs to boot.  And I suspect that your example above may be one of them. I don't see any problem with your construction.

You may be better of trying curl or icurl - but that too is a mine field.

In the maentime, is the following snippet any use to you? By setting the nodeid, it will list all interfaces for a node that have a state of up or down based on the variation you use.  I used leaf switch with an ID of 1202, so for yours you would use 216

apic1# bash
admin@apic1:~> nodeid=1202
admin@apic1:~> moquery -c ethpmPhysIf -f 'ethpm.PhysIf.operSt=="down"' | egrep "node-$nodeid" dn : topology/pod-1/node-1202/sys/phys-[eth192/1/43]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/44]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/45]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/46]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/47]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/48]/phys dn : topology/pod-1/node-1202/sys/phys-[eth1/2]/phys dn : topology/pod-1/node-1202/sys/phys-[eth1/3]/phys dn : topology/pod-1/node-1202/sys/phys-[eth1/5]/phys dn : topology/pod-1/node-1202/sys/phys-[eth1/8]/phys dn : topology/pod-1/node-1202/sys/phys-[eth1/9]/phys dn : topology/pod-1/node-1202/sys/phys-[eth1/49]/phys dn : topology/pod-1/node-1202/sys/phys-[eth1/51]/phys dn : topology/pod-1/node-1202/sys/phys-[eth1/52]/phys dn : topology/pod-1/node-1202/sys/phys-[eth1/53]/phys dn : topology/pod-1/node-1202/sys/phys-[eth1/54]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/1]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/2]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/3]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/4]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/5]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/6]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/7]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/8]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/9]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/29]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/30]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/31]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/32]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/33]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/34]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/35]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/36]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/37]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/38]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/39]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/40]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/41]/phys dn : topology/pod-1/node-1202/sys/phys-[eth192/1/42]/phys

I hope this helps.


Don't forget to mark answers as correct if it solves your problem. This helps others find the correct answer if they search for the same problem.

 

RedNectar aka Chris Welsh.
Forum Tips: 1. Paste images inline - don't attach. 2. Always mark helpful and correct answers, it helps others find what they need.

@RedNectar  Thanks for your reply. I didn't know you could set variables in bash but that makes sense, so that is cool!

 

In looking at it, your query is basically like what I was doing using grep without variables, and I'm guessing filtering using grep will be the only way to get the information I need in this particular case. Basically I will have to get all interfaces in a certain state (i.e. all "down" interfaces), and then filter the output and see if my particular interface is in the list.

 

So, let's say I wanted to see if eth1/6 was down on node 216, I would use this command and see if I got any output:

 

moquery -c ethpmPhysIf -f 'ethpm.PhysIf.operSt=="down"' | grep node-216 | grep eth1/6

 

If I did get a line of output, it means the interface is down. If I didn't get any output, I could change the .operSt filter to "up" and run the command again to confirm the interface is up. So that is probably the best solution in this case. Thanks for the confirmation of my syntax, and also that there might be a bug in filtering the dn on the ethpmPhysIf class!

 

 

SIDE NOTE:

Interestingly, in my searching Google for moquery stuff I ended up reading a little bit of a blog post yesterday without knowing it was yours, and you mentioned using awk filtering (which I then became very curious about, and discovered awk stands for the inventors of it, Aho, Weinberger, and Kernighan). Compared to grep (created of course by Ken Thompson, "get [regular expression] print" ) , awk definitely gives better performance when parsing large files/output since awk is stream-based, so it doesn't need to read the whole file/output into memory before it begins parsing for matches. The only caveat with awk is it is a bit more difficult/awkward (pun intended) to format a command with awk than with grep

 

So we can achieve the same result as above using awk :

moquery -c ethpmPhysIf -f 'ethpm.PhysIf.operSt=="down"' | awk '{if (($3 ~ "node-216") && ($3 ~ "eth1/6")) print $3}'

 

But of course that is much more difficult to type on the fly, and for this small of a result set awk only gives about 1 second of improved performance over grep, so in this case using grep would be more desirable. However, I could definitely see a good use for awk in ACI for parsing through large result sets, such as ACI log messages. So, I appreciate you mentioning awk in your blog post, as it gave me another option to have in my toolkit for filtering ACI output!

0xD2A6762E

Review Cisco Networking for a $25 gift card

Save 25% on Day-2 Operations Add-On License