You should send Accept header, not Content Type.
Good Day Anton
Like this:
headers = {'content-type': 'application/json', 'Accept': 'application/json'}
OR could you help :)
Thank You
Albertus Geyser
Why are you asking? Have you tried it?
Yes, it give me same result as before, but i want to get last position of each tracker id i request:
payload = {'all': 'true', 'deviceId': uid}
headers = {'Accept': 'application/json'}
response = requests.get(url + ':8082/api/positions', auth=(user, password), params=payload, headers=headers, timeout=5.000)
data = json.loads(response.content)[0]
print data
Is it possible?
Why are you using all
and deviceId
parameters?
I want to search all trackers as admin for last position for tracker id i supply.
Possible?
No, it's not possible. You can only get all positions for devices that are linked to you. Please next time read official API documentation instead of trying random things.
Good day Anton
Thank you for reply. Was limitation implemented deliberately for a reason or could it be changed to allow admin to see all trackers position details?
It was on purpose. I don't see why admin would need to see potentially thousands of devices at the same time.
For monitoring purposes to see live position of all trackers on request for a control room? Could it be changed?
If you want to see all devices, you can link them to admin user. I don't see any good reason for expanding API. It's already possible to implement what you want.
Just as clue...
There must be something similar to https://www.zabbix.com/documentation/3.4/manual/discovery/low_level_discovery in nagios.
You can use it to discover all devices by api/devices?all=true
.
Then you can retrieve last positions per device by deviceId
Good Day Anton
Already did a addon for Nagios for devices:
#!/usr/bin/env python
import json
import sys
import requests
# Nagios Exit statuses
UNKNOWN = -1
OK = 0
WARNING = 1
CRITICAL = 2
uid = (sys.argv[1])
url = 'http://myurl.co.za'
user = 'admin'
password = 'password'
payload = {'all': 'true', 'id': uid}
headers = {'content-type': 'application/json'}
response = requests.get(url + ':8082/api/devices', auth=(user, password), params=payload, headers=headers, timeout=5.000)
data = json.loads(response.content)[0]
if response.status_code != 200:
exitmessage = "UNKNOWN - "
state = UNKNOWN
value = "Unknown"
else:
if data['status'] == 'online':
exitmessage = "OK - "
state = OK
value = "Online"
elif data['status'] == 'offline':
exitmessage = "CRITICAL - "
state = CRITICAL
value = "Offline"
elif data['status'] == 'unknown':
exitmessage = "WARNING - "
state = WARNING
value = "Unknown"
print exitmessage, value, ' |'
raise SystemExit, state
My problem is that devices according to my results does not provide Lat + Long as needed for my control room.
I only get the following from devices:
Hope you can help . . .
Please read comments more carefully. The suggestion was to request position for each device. Alternatively you can link all devices to admin account and get all latest positions in a single request.
P.S. please format any code fragments properly
Good Day
I am busy with last positions of all tracker addon for nagios, could you see where i am wrong with api call?
#!/usr/bin/env python import json import sys import requests uid = (sys.argv[1]) url = 'http://myurl.co.za' user = 'admin' password = 'password' payload = {'all': 'true', 'id': uid} headers = {'content-type': 'application/json'} response = requests.get(url + ':8082/api/positions', auth=(user, password), params=payload, headers=headers, timeout=5.000) data = json.loads(response.content)[0] print data
Thank You
Albertus Geyser