Hito_kun Hito_kun - 1 month ago 13
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?

Thanks!

Answer

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

/api/v1/devices/{deviceId}/objects/{objectId}/indicators/{indicatorId}/data

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:

<list>
  <dataPoint>
    <value>30.0</value>
    <time>1476300851000</time>
    <focus>1</focus>
  </dataPoint>
  <dataPoint>
    <value>30.0</value>
    <time>1476301151000</time>
    <focus>1</focus>
  </dataPoint>
  <dataPoint>
    <value>30.0</value>
    <time>1476301451000</time>
    <focus>1</focus>
  </dataPoint>
  <dataPoint>
    <value>30.0</value>
    <time>1476301751000</time>
    <focus>1</focus>
  </datapoint>
</list>

Hope it help out.

Comments