sample scripts for SSH and collecting outputs

56 views
Skip to first unread message

trigger-man

unread,
Feb 9, 2014, 3:42:40 PM2/9/14
to trigge...@googlegroups.com
Started working on trigger few hours ago. So please pardon my ignorance.

Could someone please provide some sample scripts that you might have used to ssh to multiple routers/fws and collect outputs and write the outputs to a file? I followed the documentation, but my script fails everytime with the nd.find () function. Is there anything to make it work with my keyword?



Traceback (most recent call last):
  File "./triggertest.py", line 6, in <module>
    dev = nd.find('ac')
  File "build/bdist.linux-x86_64/egg/trigger/netdevices/__init__.py", line 726, in find
KeyError: 'ac'

netdevices.csv file
**********************

ac25-xxxx.xx.net,cisco,router
ac26-xxxx.xx.net,cisco,router

trigger-man

unread,
Feb 9, 2014, 5:16:43 PM2/9/14
to trigge...@googlegroups.com
Figured the find function needs to be fed everything in the hostname before the domain. 

Jathan McCollum

unread,
Feb 13, 2014, 11:24:38 AM2/13/14
to trigge...@googlegroups.com
Hey there-

My apologies on the delayed response!  

First of all the "gnng" tool that comes bundled with Trigger is a good example of how one may subclass the trigger.cmds.Commando class to create custom command templates to send commands and react based on the output of those commands.

Next, the .find() method of NetDevices currently searches by comparing the string you pass in (e.g. "ac") against the hostname section of the fully-qualified domain name (fqdn).


--
You received this message because you are subscribed to the Google Groups "Trigger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trigger-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Jathan.
--

Jathan McCollum

unread,
Feb 13, 2014, 11:26:44 AM2/13/14
to trigge...@googlegroups.com
One more thing, sorry!

If you would like to search on a partial match, you may use the .match() method, for example:

nd.match(nodeName='ac')

Would return all devices with "ac" in their nodeName attribute.
--
Jathan.
--

trigger-man

unread,
Feb 15, 2014, 3:05:05 PM2/15/14
to trigge...@googlegroups.com
Thanks Jathan. nd.match(nodeName='ac') worked great. I wanted to match all the 'ac' devices in a datacenter (was -> Washington) and I tried doing the below. No luck. Anyways to do this?

dev = nd.match(nodeName= 'ac' and 'was')                                          -> matches everything that has 'was' not just the 'ac' ones.
dev = nd.match(nodeName= 'ac') and nd.match(nodeName= 'was')        -> same as above

Jathan McCollum

unread,
Feb 20, 2014, 11:10:47 AM2/20/14
to trigge...@googlegroups.com
So this is only going to match on the hostname:

dev = nd.match(nodeName= 'ac') and nd.match(nodeName= 'was')

And that's not quite the right syntax you want. You can use the "+" operator to add two lists together. Since the .match() method returns a list, this should work:

devices = nd.match(nodeName='ac') + nd.match(nodeName='was')

Are you populating the .site attribute in your NetDevices metadata? If so you could use this:

devices = nd.match(nodeName='ac', site='was')
Reply all
Reply to author
Forward
0 new messages