Get GPS Location of Windows Host
Video Lecture
Description
Create a new file using the script below and save it into the C:\temp\
folder.
getGPSLocation.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Execute the Script from a Command Prompt
To execute the script from a command line, open a PowerShell prompt and type,
powershell -NoProfile -ExecutionPolicy bypass -File C:\temp\getGPSLocation.ps1
If you get the error Access Denied for Location Information
then,
-
Start → Settings → Privacy & Security → Location
-
Enable Location Services
-
Enable Let apps access your location
-
Enable Let desktop app access your location
-
Try running the script again.
Execute the Script as a Zabbix Item
To execute the script as a Zabbix item, add a new UserParameter to the Zabbix agents configuration file,
UserParameter=getGPSLocation,powershell.exe -NoProfile -ExecutionPolicy bypass -File "C:\temp\getGPSLocation.ps1"
Test the new UserParameter from the command line first,
CD into the folder where Zabbix agent was installed.
cd C:\Program Files\Zabbix Agent
# or if using Zabbix agent 2
cd C:\Program Files\Zabbix Agent 2
Next, execute,
zabbix_agentd.exe -t getGPSLocation
# or if using Zabbix agent 2
zabbix_agent2.exe -t getGPSLocation
Create the Item on your Windows Host in Zabbix
Restart your Zabbix agent on your Windows host so the user parameter is registered.
Now create a new item on your windows host using the Zabbix UI.
Key | Value |
---|---|
Name | Get GPS Location |
Type | Zabbix agent (active or default passive) |
Key | getGPSLocation |
Type of information | Text |
Update interval | 10m |
If after a while, you get the error Timeout occured while gathering data
, then ensure that you have restarted your Zabbix agent.
If the error still occurs, try enabling the permission to allow the shell to access location data.
-
Start → Settings → Privacy & Security → Location
-
Enable Location Services
-
Enable Let apps access your location
-
Enable Windows Shell Experience Host
And also experiment with the Zabbix agent timeout setting,
Administration → Timeouts → Zabbix agent
Default is 3s
. Try 10s
up to 30s
Also, don't query the location too often. In my item settings above, I query once every 10 minutes.
Querying once every minute is likely to cause timeouts.
In fact, I often get timeouts regardless, I am unable to eradicate them completely.
View the GPS Location on the Map
See the video for further instructions on how to populate the latitude
and longitude
inventory fields from the response so that we can see the location on the map.
The regex used in the video was,
(-*[0-9]*\.[0-9]*) (-*[0-9]*\.[0-9]*)