I have this little code that is giving me a little doubt. Despite entering the IF, when trying to call a variable totalOnline or TotalOffline, it always appears as 0, as if it is not incrementing, but when I put or console.log inside the map function, I see that it is actually incrementing. How can I solve this simply and correctly?
const Zabbix = require('zabbix-promise')
const zabbix = new Zabbix({
url: 'URL',
user: 'USER',
password: 'PASSWORD'
});
(async () => {
await zabbix.login()
let totalOffline = 0
let totalOnline = 0
var statusValue = null
const host = await zabbix.request('host.get', {
selectInterfaces: 'extend',
})
host.map(async (e, i) => {
statusValue = await zabbix.request('item.get', {
"output": "extend",
"hostids": e.hostid,
"search": {
"key_": "icmpping",
"name": "ICMP Ping"
},
"sortfield": "name"
})
statusValue ? await totalOnline++ : await totalOffline++
})
console.log(totalOnline)
})()