Answer the question
In order to leave comments, you need to log in
How to properly populate an array?
Good day!
The question is more about the syntax and correctness of writing the code.
So there is zabbix to check the VPN status
On the WIN client via SNMP we get the name and status, a script was written for this
<#
{"data":[{"{#VPN.NAME}":"vpn_roes","{#VPN.NAME.STATUS}":1}]
#>
function Make-LLD () {
For ($i=1; $i -le 99; $i++){
$VPNName = Get-SnmpData -IP 192.168.103.1 -Community public -OID 1.3.6.1.4.1.890.1.6.22.2.4.1.2.+$i | select -Expand Data
$VPNStatus = Get-SnmpData -IP 192.168.103.1 -Community public -OID 1.3.6.1.4.1.890.1.6.22.2.4.1.5.+$i | select -Expand Data
if ($VPNName -eq 'NoSuchInstance'){Break}
$vpns += @{Name = "{#VPN.NAME}"; e={$VPNName}},
@{Name = "{#VPN.NAME.STATUS}"; e={$VPNStatus}}
}
return ConvertTo-Json @{"data" = [array]$vpns} -Compress
}
Write-Host $(Make-LLD)
{"data":[{"{#VPN.NAME}":"vpn_roes","{#VPN.NAME.STATUS}":1}]
Answer the question
In order to leave comments, you need to log in
You're missing the initial [email protected]() assignment,
but the true powershell way is something like this:
function Make-LLD () {
For ($i=1; $i -le 3; $i++){
$VPNName = ...
$VPNStatus =
if ($VPNName -eq 'NoSuchInstance'){Break}
@{'#VPN.NAME' = $VPNName; '#VPN.NAME.STATUS' = $VPNStatus}
}
}
$vpns = Make-LLD
$result = ConvertTo-Json @{"data" = [array]$vpns} -Compress
Write-Host $result
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question