SolarWinds & Python – Extracting Standard Data from the Orion.Nodes table via the SolarWinds Information Service (SWIS) API

By 22nd May 2019SolarWinds, SWIS, SWQL, Uncategorised

The SolarWinds Information Service (SWIS) is a data access layer for the Orion product family that provides a hybrid of object-oriented and relational features. It has its own SQL-like language called SolarWinds Query Language (SWQL).

The purpose of this post if demonstrate the data that can be extracted using SWIS and SWQL with the orionsdk for Python, as a quick and easy way to obtain granular data on your estate.

Solarwinds Orion SDK Schema –

import requests
from orionsdk import SwisClient
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import csv

# Disable Insecure HTTPS Certificate Warnings

server = "solarwindsHost"
user = "apiuser"
pwd = "apipassword"

# Build our SWQl Query
cisco_nodes_query = """
n.Vendor,n.MachineType, n.NodeDescription,
n.IPAddress, n.Caption, n.Status
FROM Orion.Nodes n
WHERE n.Vendor = 'Cisco'
ORDER BY n.IPAddress

def query_nodes(query, file_name):

    # Create our SwisClient Object
    swis = SwisClient(server, user, pwd)

    # Initiate our Query and store the results
    node_results = swis.query(query)["results"]

    # Create a file object
    file = open(file_name + ".csv", "w", newline='')

    # Create our CSV Fields
    fields = node_results[0].keys()

    # Create our CSV.Dictwriter Object
    writer = csv.DictWriter(file, fieldnames=fields)

    # Write the headers to the csv file

    # Write the results to the csv file

    # Optionally Print out the results to the terminal.
    for node in node_results:
        print("*" * 100)
        for k, v in node.items():
            print(k, "==", v)

query_nodes(cisco_nodes_query, "cisco_nodes")

Example Output

Vendor == Cisco
MachineType == Cisco 4431 ISR
NodeDescription == Cisco IOS Software, ISR Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 15.4(3)S4, RELEASE SOFTWARE (fc3)
Technical Support:
Copyright (c) 1986-2015 by Cisco Systems, Inc.
Compiled Mon 05-Oct-15 11:24 by mcpre
IPAddress ==
Caption ==
Status == 1

Author Mitch

I am an independent IT Consultant with specialities in Software Development, Enterprise Unified Communication, Network and Security platforms. In addition to my day to day work, I develop bespoke applications and I hope that through I can build relationships with clients, business partners and fellow engineers by providing solutions to complex problems through the use of programming.

More posts by Mitch