Last active
December 30, 2024 23:04
-
-
Save Hitokun/f3a68ee8a950699d8b4ff1d1c6a85f0b to your computer and use it in GitHub Desktop.
Use the SevOne REST API (available for SevOne NMS 5.6+) to gather all the metrics (Indicators) from all devices. This is a starting point to develop more robust SevOne export solutions via REST
This file contains hidden or 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 | |
import time | |
# Log into SevOne API. | |
address = 'http://sevone.com/api/v1/' | |
creds = {'name': 'user', 'password':'pass'} | |
r = requests.post( address + "authentication/signin", | |
data=json.dumps( creds ), | |
headers = { 'content-type': 'application/json' }) | |
response = json.loads( r.text ) | |
# Open a session for credential handling. | |
session = requests.Session() | |
session.headers.update({ 'content-type': 'application/json', | |
'X-AUTH-TOKEN': response[ 'token' ]}) | |
# Time interval in linux epoch (up to miliseconds). | |
endTime = int( time.time() * 1000 ) | |
startTime = endTime - 1800000 | |
# Let's get the devices, objects and indicators to collect metrics from them. | |
# By default, you'll get the first twenty devices. | |
r = session.get(address + 'devices') | |
devices = json.loads(r.text) | |
for device in devices['content']: | |
print "Device: {} id: {}".format( device[ 'name' ], device[ 'id' ]) | |
r = session.get( address | |
+ 'devices/{}?includeIndicators=true'.format( device[ 'id' ])) | |
response = json.loads(r.text) | |
for object in response[ 'objects' ]: | |
print "* Object: {} id: {}".format( object[ 'name' ], object[ 'id' ]) | |
for indicator in object[ 'indicators' ]: | |
print "** indictorId: {}".format( | |
indicator[ 'id' ]) | |
indicatorDataUrl = address + "devices/{}/objects/{}/indicators/{}/data".format( | |
indicator[ 'deviceId' ], indicator[ 'objectId' ], indicator[ 'id' ]) | |
params = { 'startTime': startTime, 'endTime': endTime } | |
r = session.get( indicatorDataUrl, params=params ) | |
print r.url | |
print r.text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was for py27.
Error seems to indicate ca-sevone01 cannot be resolved? I don't know where did that came from.