使用 SevOne API 检索指标

Use SevOne API to retrieve metrics

我没看到很多人在这里谈论 SevOne,但值得一试。我正在使用 SevOne NMS 5.6 并寻找一种方法来导出通过它的 API(Rest 或 Soap)为设备收集的数据。到目前为止,我还没有发现任何有用的东西(有 Data Miner,但我们更喜欢 API 方法)。 有谁知道这是否可能?如果可以,怎么做?

谢谢!

对于在那里的任何人,在指标下挖掘 REST API 的文档,我发现了这个端点:

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

因此,您可以创建一个方便的解决方案来从 any/all 设备检索信息,如下所示(一些 Python 如下):

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

你会得到这样的回复:

<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>

希望对您有所帮助。