I currently have an implementation using the pexpect python module, which interacts with Juniper, Cisco routers. It spawns a child application and runs command like ‘show version’ and logs the output.
I am looking for a better way to carry out this process, since if something changes on the switch end (a space or a colon in the prompt after an OS upgrade), then the program will not work. I think Juniper has an API to carry out such operations, but I don’t think Cisco has one. I also need to extend this to other switches like HP etc.
Is there a generalized way I can approach this?
I also don’t mind writing different code for different devices if required, if a more standard approach than pexpect exists.
Thanks
Using some version of expect is the accepted way of doing this. There’s already a mature piece of OSS scripts for doing terminal interaction with most networking devices form most vendors. The same problem exists, but a lot more eyeballs are looking at it and updating things when vendors change prompts.
Check out RANCID.
Here’s a quick example of a script I wrote based on RANCID to harvest ACL hit counts on ASAs: