Hello all,
i’am trying get data from console program using PS convert it to a json format, and then push it to a zabbix.
Here is an example of raw output
---------------------------------------------------------------------- Physical Device information ---------------------------------------------------------------------- Device #0 Device is a Hard drive State : Online Block Size : 512 Bytes Supported : Yes Transfer Speed : SAS 3.0 Gb/s Reported Channel,Device(T:L) : 0,0(0:0) Reported Location : Connector 0, Device 0 Vendor : HITACHI Model : HUS156030VLS600 Firmware : A5D0 Serial number : JTWYYAAJ World-wide name : 5000CCA00F6ED187
Here is my “code” )
$f=get-content "D:\arcconf_pd.txt" $Content=$f -replace "\s+|(-)|(Physical Device information)|(Device is a Hard drive)".split("`n") -match '\S' $array = @() $Content -split "`r`n" | % { $Delimited = $_ -split "`:" $object = New-Object -TypeName PSObject $object | Add-Member -MemberType NoteProperty -Name $Delimited[0] -Value $Delimited[1] $array += $object } $array | ConvertTo-Json
Here what i’am getting
[ { "Device#0": null }, { "State": "Online" }, { "BlockSize": "512Bytes" }, { "Supported": "Yes" }, { "TransferSpeed": "SAS3.0Gb/s" }, ]
But Zabbbix need anothe structure of json
Here is example
{ "data":[ { "{#VMNAME}":"cp01" , "{#VMSTATE}":"Off" }, { "{#VMNAME}":"dc01" , "{#VMSTATE}":"Running" }, { "{#VMNAME}":"ex01" , "{#VMSTATE}":"Off" }, { "{#VMNAME}":"fc01" , "{#VMSTATE}":"Running" }, { "{#VMNAME}":"rdg01" , "{#VMSTATE}":"Running" }, { "{#VMNAME}":"Windows 2012R2 G2 Template" , "{#VMSTATE}":"Off" }, <--- THIS I WANT TO REMOVE ] }
Question is, how can i modify my code to get a Zabbix style json?