Created
August 29, 2016 13:45
-
-
Save hynek2001/7fdcb6760c31da3b64a2311320dc160a to your computer and use it in GitHub Desktop.
solarwinds example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
from requests.packages.urllib3.exceptions import InsecureRequestWarning | |
def main(): | |
ele=getNeDataFromSolarwinds(ip="11.1", username="asdada", password="sdsdf") | |
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: | |
""" | |
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) | |
swis = SwisClient(ip, username, password) | |
query=""" | |
select DisplayName,IP,vendor from Orion.Nodes where vendor like '%huawei%' | |
""" | |
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