Hito_kun Hito_kun - 1 year ago 131
reST (reStructuredText) Question

Use SevOne API to retrieve metrics

I don't see many folks talking about SevOne around here, but it's worth the shot. Im Working with SevOne NMS 5.6 and looking for a way to export the data collected for the devices via it's API (Rest or Soap). So far I havenĀ“t found anything useful regarding this (there is the Data Miner, but an API approach is preferred by us).
Does anyone knows if this is possible? If so, how?


Answer Source

For anyone out there, digging in the docs of the REST API under Indicators, I found this endpont:


So with that, you can create a handy solution to retrieve information from any/all devices, like this (some Python follows):

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

You'll get something like this as a response:


Hope it help out.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download