Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Python Test
- ---
- ```py
- # python C:\Users\204097\PycharmProjects\NetMonkey\test.py
- import orionsdk
- import requests.packages.urllib3
- import getpass
- from pprint import pprint
- from datetime import datetime, timedelta
- import pandas as pd
- # begin script timer
- start_time = datetime.now()
- print("\nScript has begun at: \n" + str(start_time))
- def read_file(filename):
- with open(filename) as f:
- return f.readlines()
- def init_orion():
- """ Prompts for Orion credentials and returns a SwisClient object.
- TODO: Need a better/more resilient way of referencing server cert.
- """
- requests.packages.urllib3.disable_warnings()
- orion_server = "Solarwinds-Orion"
- orion_username = "eehealth\\204097"
- orion_password = "Blazeblue666"
- if not orion_username:
- default_username = getpass.getuser()
- print(default_username)
- orion_username = "eehealth\\" + default_username
- if not orion_password:
- print("pass required\n")
- orion_password = getpass.getpass("Orion password: ")
- return orionsdk.SwisClient(orion_server, orion_username, orion_password, verify='Solarwinds-Orion.der')
- def unmanage(node, hours):
- """ unmanage solarwinds node by user defined hours based on DisplayName
- USAGE: python
- """
- swis = init_orion()
- print("\nUnmanage Test for hostname " + node + "\n")
- results = swis.query("SELECT NodeID, DisplayName, IPAddress FROM Orion.Nodes WHERE NodeName='" + str(node) + "'")
- print(results)
- for row in results['results']:
- print("{NodeID}, {DisplayName}, {IPAddress}".format(**row))
- interface_id = results["results"][0]["NodeID"]
- print(interface_id)
- netobject_id = "N:{}".format(interface_id)
- print(netobject_id)
- now = datetime.utcnow()
- print(now)
- duration = now + timedelta(hours=hours)
- print(duration)
- swis.invoke("Orion.Nodes", "Unmanage", netobject_id, now, duration, False)
- print("\n\n" + node + "is now unmanaged for " + str(duration) + "hours")
- def query_test_file(node):
- """ query all nodes in
- USAGE: python
- """
- swis = init_orion()
- print("Query Test:")
- #results = swis.query("SELECT Uri FROM Orion.Nodes WHERE NodeName='" + str(node) + "'", id=1) # set valid NodeID!
- results = swis.query("SELECT Uri FROM Orion.Nodes")
- uri = results['results'][0]['Uri']
- print(uri)
- obj = swis.read(uri)
- cust_obj = swis.read(uri + '/CustomProperties')
- obj.update(cust_obj)
- pprint(obj)
- logs_df = pd.DataFrame(obj)
- df_list.append(logs_df)
- #logs_df.to_csv("{node}_RAW.csv".format(node=node), index_label = "Property", header=[node])
- def query_test():
- """ query single node
- USAGE: python
- """
- swis = init_orion()
- print("Query Test:")
- results = swis.query("SELECT Uri FROM Orion.Nodes")
- print(type(results))
- print(len(results))
- print(len(results['results']))
- for row in range(len(results['results'])):
- uri = results['results'][row]['Uri']
- print(uri)
- obj = swis.read(uri)
- cust_obj = swis.read(uri + '/CustomProperties')
- obj.update(cust_obj)
- pprint(obj)
- logs_df = pd.DataFrame(obj)
- df_list.append(logs_df)
- # def add_node():
- unmanage("RMELROSE", 1)
- unmanage("WMELROSE", 1)
- unmanage("RMELROSEPARK", 1)
- unmanage("RMELROSEPARK", 1)
- # query_test("WJEWEL34WASH")
- df_list = []
- query_test()
- final_df = pd.concat(df_list)
- final_df.to_csv("solar_RAW.csv", index_label="Property")
- # End Clock and print time
- end_time = datetime.now()
- total_time = end_time - start_time
- print("\nTotal time for script: \n" + str(total_time))
- ```
Add Comment
Please, Sign In to add comment