Skip to content

Instantly share code, notes, and snippets.

@hynek2001
Created August 27, 2016 16:16
Show Gist options
  • Save hynek2001/6ee54e77fb6b97a2ee13bfb162752e1f to your computer and use it in GitHub Desktop.
Save hynek2001/6ee54e77fb6b97a2ee13bfb162752e1f to your computer and use it in GitHub Desktop.
solarwinds get elements info
import requests
import json
def main():
ele=getNeDataFromSolarwinds(ip="1.1.1.1", username="x", password="x")
with open('elements.json', 'w') as outfile:
json.dump(ele, outfile)
def getNeDataFromSolarwinds(username="",password="",ip=""):
"""
will fetch data from solarwinds about elements
:param username:
:param password:
:param ip:
:return:
"""
swis = SwisClient(ip, username, password)
query="""
select DisplayName,IP,vendor from Orion.Nodes
"""
results = swis.query(query)
# print(results)
res = []
ele=[]
for ll in results['results']:
ele.append(ll)
return ele
class SwisClient:
"""
zakladni knihozn pro pristup do solarwinds
"""
def __init__(self, hostname, username, password):
self.url = "https://%s:17778/SolarWinds/InformationService/v3/Json/" % (hostname)
self.credentials = (username, password)
def query(self, query, **params):
return self._req("POST", "Query", {'query': query, 'parameters': params}).json()
def invoke(self, entity, verb, *args):
return self._req("POST", "Invoke/%s/%s" % (entity, verb), args).json()
def create(self, entity, **properties):
return self._req("POST", "Create/" + entity, properties).json()
def read(self, uri):
return self._req("GET", uri).json()
def update(self, uri, **properties):
self._req("POST", uri, properties)
def delete(self, uri):
self._req("DELETE", uri)
def _req(self, method, frag, data=None):
return requests.request(method, self.url + frag,
data=json.dumps(data),
verify=False,
auth=self.credentials,
headers={'Content-Type': 'application/json'})
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment