Hi All,
Try to create a script in a template to get latitude coordinates from the location of the host and populate it on the host. I have the below code but it seems to be failing to run, can someone point me to the right way? Below is exerpt of the script:
Try to create a script in a template to get latitude coordinates from the location of the host and populate it on the host. I have the below code but it seems to be failing to run, can someone point me to the right way? Below is exerpt of the script:
Code:
var address = obj.location
var apiKey = obj.apiKey
// Construct the URL for the geocoding API request
const geocodingUrl = `https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURIComponent(address)}&key=${apiKey}`;
// Make an HTTP GET request to the geocoding API
fetch(geocodingUrl)
.then((response) => response.json())
.then((data) => {
if (data.status === 'OK' && data.results.length > 0) {
const location = data.results[0].geometry.location;
const latitude = location.lat;
obj.latitude(${latitude});
} else {
zabbix.log('Geocoding failed for the provided address.');
}
})
.catch((error) => {
zabbix.log('An error occurred:', error);
});
Comment