Python

SolarWinds Orion API & SDK can do that?

My life was a one-track record on repeat, tirelessly playing the same tune over and over. New nodes added to the network means new nodes to monitor. The manual, arduous tasks of clicking through monitoring tool menus, selecting appropriate polling agents, configuring appropriate properties, and validating node status can lead a man to madness. There must be a better way!

When I first heard that I could “easily” script and automate some tasks in SolarWinds, I stared askance, knowing good and well this wouldn’t be easy, if it worked at all.  A couple of years later, and several hundred more managed nodes in the pocket,  I figured it’s time to revisit this possibility.  Although the SolarWinds Orion SDK has been around for a few years, documentation is limited and content is heavily reliant on the THWACK community.  However, dig deep enough, and you’ll find a wealth of useful information!  I learned that “easy” is relative, and given the number of examples SolarWinds provides in their SDK, it’s really not all that bad. (more…)

Simple Yes No Function in Python

Preface

I’m a Network Engineer learning Python, and these are purely my notes. I’m not an expert by any means. Feel free to use any of these examples and improve upon them. Feel free to call me out where things can be done better.

Onward

I regularly need a simple yes/no function in Python when interacting with users. This function uses sets of data to represent “yes” and “no”. Sets are unordered collections of elements, and can be used similarly to lists (e.g. x in set). The function will take in an answer (yes/no). This will be converted to lowercase and then checked against each set. Result is returned. (more…)

Replace Words in Files or Strings using Python

Preface

I’m a Network Engineer learning Python, and these are purely my notes. I’m not an expert by any means. Feel free to use any of these examples and improve upon them. Feel free to call me out where things can be done better.

Onward

A common task I need to do is replace words in a file with something else. For example:

hostname $hostname
interface Gig0/1
 ip address $ip 255.255.255.252

Where $hostname and $ip should be variables that needs replacing. This post looks at how to accomplish this on the Python interpretor, and via a script file using a Python function.

To keep things relatively simple, I’m only going to perform the replacement on a single file, using a single set of attributes. (more…)

Search a List of Dictionaries in Python

Preface

I’m a Network Engineer learning Python, and these are purely my notes. I’m not an expert by any means. Feel free to use any of these examples and improve upon them. Feel free to call me out where things can be done better.

Onward

This post is sort of a follow-up to my last one regarding CSVs converted to dictionaries. So, I have this big list of dictionaries, these key/value pairs, and I want to do things with them. In this case, I’d like to be able to search this list and return just the key/values for a specific device.  This will later be used when building network device configuration files. (more…)

Convert a CSV to a Dictionary in Python

Preface

I’m a Network Engineer learning Python, and these are purely my notes. I’m not an expert by any means. Feel free to use any of these examples and improve upon them. Feel free to call me out where things can be done better.

Onward

I have a CSV full of device-specific variables that I need to use in a script built for generating network device configurations. For example:

devicess (more…)