Skip to content

Instantly share code, notes, and snippets.

@Hitokun
Last active September 20, 2018 11:05
Show Gist options
  • Save Hitokun/f3a68ee8a950699d8b4ff1d1c6a85f0b to your computer and use it in GitHub Desktop.
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
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
@razvaniacob8778
Copy link

Hello, is any specific python version required, as i tried it with python 2.7.7 and it failed.

root@Graphite-test1:/home# python sevone_alarms2.py
Traceback (most recent call last):
File "sevone_alarms2.py", line 10, in
headers = { 'content-type': 'application/json' })
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 88, in post
return request('post', url, data=data, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 455, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 558, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 378, in send
raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='ca1-sevone01', port=80): Max retries exceeded with url: /api/v1/authentication/signin (Caused by <class 'socket.gaierror'>: [Errno -2] Name or service not known)

Where: modules json, request and time are installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment