SolarWinds & Python – Extracting Custom Data from the Orion.Nodes and Orion.NodesCustomProperties tables 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 – http://solarwinds.github.io/OrionSDK/schema/index.html

Full Code
 
  1. import requests
  2. from orionsdk import SwisClient
  3. from requests.packages.urllib3.exceptions import InsecureRequestWarning
  4. import csv
  5. # Disable Insecure HTTPS Certificate Warnings
  6. requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
  7. server = "solarwindsHost"
  8. user = "apiuser"
  9. pwd = "apipassword"
  10. # Build our SWQl Query
  11. cisco_nodes_query = """
  12. SELECT
  13. n.Vendor,n.MachineType, n.NodeDescription,
  14. n.IPAddress, n.Caption, n.Status,
  15. c.Building, c.City, c.Call_network_support_on_call
  16. FROM Orion.Nodes n
  17. JOIN Orion.NodesCustomProperties c ON n.NodeID = c.NodeID
  18. WHERE n.Vendor = 'Cisco'
  19. ORDER BY n.IPAddress
  20. """
  21. def query_nodes(query, file_name):
  22.     # Create our SwisClient Object
  23.     swis = SwisClient(server, user, pwd)
  24.     # Initiate our Query and store the results
  25.     node_results = swis.query(query)["results"]
  26.     # Create a file object
  27.     file = open(file_name + ".csv", "w", newline='')
  28.     # Create our CSV Fields
  29.     fields = node_results[0].keys()
  30.     # Create our CSV.Dictwriter Object
  31.     writer = csv.DictWriter(file, fieldnames=fields)
  32.     # Write the headers to the csv file
  33.     writer.writeheader()
  34.     # Write the results to the csv file
  35.     writer.writerows(node_results)
  36.     # Optionally Print out the results to the terminal.
  37.     for node in node_results:
  38.         print("*" * 100)
  39.         for k, v in node.items():
  40.             print(k, "==", v)
  41. query_nodes(cisco_nodes_query, "cisco_nodes")
  42.  



Example Output

Output
 
  1. ****************************************************************************************************
  2. Vendor == Cisco
  3. MachineType == Cisco 4431 ISR
  4. NodeDescription == Cisco IOS Software, ISR Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 15.4(3)S4, RELEASE SOFTWARE (fc3)
  5. Technical Support: http://www.cisco.com/techsupport
  6. Copyright (c) 1986-2015 by Cisco Systems, Inc.
  7. Compiled Mon 05-Oct-15 11:24 by mcpre
  8. IPAddress == 10.10.10.1
  9. Caption == dr-ir4431.net
  10. Status == 1
  11. Building == 1201 State Street, Richardson, TX 75082
  12. City == Richardson
  13. Call_network_support_on_call == True
  14.  
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
"