SolarWinds & Python – Extracting Custom Data from the Orion.Nodes and Orion.NodesCustomProperties tables via the SolarWinds Information Service (SWIS) API

By 22nd May 2019Uncategorised

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 – http://solarwinds.github.io/OrionSDK/schema/index.html


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

# Disable Insecure HTTPS Certificate Warnings
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

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

# Build our SWQl Query
cisco_nodes_query = """
SELECT
n.Vendor,n.MachineType, n.NodeDescription,
n.IPAddress, n.Caption, n.Status,
c.Building, c.City, c.Call_network_support_on_call
FROM Orion.Nodes n
JOIN Orion.NodesCustomProperties c ON n.NodeID = c.NodeID
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
    writer.writeheader()

    # Write the results to the csv file
    writer.writerows(node_results)

    # 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: http://www.cisco.com/techsupport
Copyright (c) 1986-2015 by Cisco Systems, Inc.
Compiled Mon 05-Oct-15 11:24 by mcpre
IPAddress == 10.10.10.1
Caption == dr-ir4431.net
Status == 1
Building == 1201 State Street, Richardson, TX 75082
City == Richardson
Call_network_support_on_call == True
Mitch

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 ucdevops.com 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