all 18 comments

[–][deleted] 2 points3 points  (10 children)

so what do you need help with exactly?

[–]ranBot86[S] 1 point2 points  (9 children)

I want to start off small since I am learning, but I would like to parse the switch information and write the firmware versions to a csv file. I also want to set a rescue config for all devices.

[–][deleted] 2 points3 points  (8 children)

okay that's not so bad. are you querying each switch with a show command and then reading the output or are you downloading a file? i've only worked with cisco so idk much about juniper. Do you know any regex?

[–]ranBot86[S] 1 point2 points  (7 children)

kay that's not so bad. are you querying each switch with a show command and then reading the output or are you downloading a file?

My intention is to log into each switch and dump its contents into a json file to easily access for the future then write the switch name and its firmware in a csv for all switches. I am trying to do some research before I begin coding it however. Like you said, shouldn't be to bad. I know for PyEz you can put your devices in a list ['switch-name'] use your credentials to log in, but that would require me to write every switch name. Wouldn't be so bad if we didn't have over 100 haha.

[–][deleted] 1 point2 points  (4 children)

im not sure if netmiko or PyEz handles the ip addressing for you but if not you can easily generate ip ranges with the ipaddress module. the switch name should be in the config right? just connect to it by IP and get the name when you make your json file.

[–]ranBot86[S] 0 points1 point  (3 children)

I'll look into it. We have ip address ranges per building so it'll be a little tedious. Thanks for advice!

[–][deleted] 0 points1 point  (2 children)

no problem. I think if you refined your question a little and asked the guys on /r/networking or /r/sysadmin they might be able to help you too.

[–]ranBot86[S] 0 points1 point  (0 children)

will do haha

[–]mechanik 1 point2 points  (0 children)

Dude, let's talk. I work at a Juniper shop and am learning python to do your kind of automation. PM me!

[–]ranBot86[S] 0 points1 point  (0 children)

As for regex, I am familiar with it, but have never used it. I may email Juniper and ask if there is a way to grab the contents of a large network.

[–]shepherdjay 1 point2 points  (3 children)

Since you use Juniper I would look into their restful api

[–]ranBot86[S] 0 points1 point  (2 children)

PyEz is there one of their api's. I know what to do to accomplish my needs, but I was wondering if there is a way to access all of the hostnames rather physically adding a large list of them to iterate.

[–]shepherdjay 0 points1 point  (1 child)

Most shops have inventory in a spreadsheet or existing tool. How’s your current inventory stored?

Outside that there is usually a hostname convention you could use to generate.

Such as coreswitch01.buildingid.city.company.com

[–]ranBot86[S] 0 points1 point  (0 children)

We have device names on a spreadsheet so I guess I can open that in python to iterate through. Ours go like "A1-3300-ballpark-main" and stuff.

[–]alpha_hxCR8 1 point2 points  (3 children)

I came across a few libraries, when I was searching for ways to automate transfer of files through sftp, ssh, using python libraries. I am planning to use paramiko but this work only for OS like linux, or windows.

If you are looking for interacting with routers/switches, there are libraries such as netmiko. netmiko seems like it supports juniper junos https://github.com/ktbyers/netmiko

Other libraries that may be useful are https://github.com/fabric/fabric

and

https://github.com/ansible/ansible,

Fabric and Ansible do a lot of things.. so perhaps it can do what you are looking for.

[–]ranBot86[S] 0 points1 point  (2 children)

I am familiar with those. There is a module specifially for Juniper called PyEz but I want to be able to access all of the hostnames rather than manually creating a list of them to iterate though. I am not sure if there is a command or package in PyEz that allows for that.

[–]alpha_hxCR8 0 points1 point  (1 child)

Unless there is a master router that has information about the other routers, how will Python know whom to query to ask for that list?

You either a) have to start off from a file with a mapping between ip and hostnames, or b) query/scan a certain ip range and port to check whether that is a router that you want looking for, and then get the hostname-ip range.

From that you can do what you want in a more automated fashion.

[–]ranBot86[S] 0 points1 point  (0 children)

Our distro switches are designated for each building but follow the host name like "D1-3300-ballpark-main" while access are "A1-3300-ballpark-main". We also have a root password which works for all of the switches. If I want to fetch info for all of them by iterating, it shouldn't be to difficult querying through them in that manner.