Traccar/Nagios Positions Help

Albertus7 years ago

Good Day Anton

Thank You for formating code.
I believe you understand where i am going with this and providing code to community as well, but i really do not understand. Would it be possible to see if you could provide part code to see if i can get Long and Lat i need?

Thank You

Albertus Geyser

Anton Tananaev7 years ago

There is a paid support option if you need help with coding.

Albertus7 years ago

Good Day Anton

Found what you mean . . . herewith coding for help to others:

#!/usr/bin/env python

import json
import sys
import requests 

uid = (sys.argv[1])
url = 'http://myurl.co.za'
user = 'admin'
password = 'password'


# get positionId from deviceId
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] 

position = data['positionId']

# get latitude + longitude . . .
payload = {'id': position}
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 "Latitude: " + str(data['latitude'])
print "Longitude: " + str(data['longitude'])
print "Address: " + str(data['address'])
print "Speed: " + str(data['speed'])

Thank You
Albertus Geyser