Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 06-05-2017 12:31 PM
The system produced in the 1 line the keys und in the next lines the values:
[
[
"host_state",
"host",
"host_icons",
"num_services_ok",
"num_services_warn",
"num_services_unknown",
"num_services_crit",
"num_services_pending"
],
[
"UP",
"DUSTSADMIN.ads.xyz.de",
"menu",
"28",
"0",
"0",
"0",
"0"
],
[
"UP",
"DUSTSVMDC01.ads.xyz.de",
"menu",
"34",
"0",
"0",
"0",
"0"
],
[
"UP",
"DUSTSVMDC02.ads.xyz.de",
"menu",
"34",
"0",
"0",
"0",
"0"
]
How to convert to key=value structure ?:
{
"host_state":"UP",
"host":"DUSTSVMDC01.ads.xyz.de",
"host_icons":"menu",
"num_services_ok":"28",
"num_services_warn":"0",
"num_services_unknown":"0",
"num_services_crit":"0",
"num_services_pending":"0",
}
Created 06-05-2017 01:58 PM
You can use the JoltTransformJSON processor for this. Here is a Chain spec that should get you what you want:
[
{
"operation": "shift",
"spec": {
"0": {
"*": "header"
},
"*": "data[]"
}
},
{
"operation": "shift",
"spec": {
"data": {
"*": {
"*": {
"@0": "[&2].@(4,header[&])"
}
}
}
}
}
]The first operation splits the top array into "header" (containing the first element) and "data" (containing the rest). The second operation creates an array of objects, each object having the keys from the header associated with the values from each element in the "data" array. With your input above, I get the following output:
[ {
"host" : "DUSTSADMIN.ads.xyz.de",
"host_icons" : "menu",
"host_state" : "UP",
"num_services_crit" : "0",
"num_services_ok" : "28",
"num_services_pending" : "0",
"num_services_unknown" : "0",
"num_services_warn" : "0"
}, {
"host" : "DUSTSVMDC01.ads.xyz.de",
"host_icons" : "menu",
"host_state" : "UP",
"num_services_crit" : "0",
"num_services_ok" : "34",
"num_services_pending" : "0",
"num_services_unknown" : "0",
"num_services_warn" : "0"
}, {
"host" : "DUSTSVMDC02.ads.xyz.de",
"host_icons" : "menu",
"host_state" : "UP",
"num_services_crit" : "0",
"num_services_ok" : "34",
"num_services_pending" : "0",
"num_services_unknown" : "0",
"num_services_warn" : "0"
} ]
Created 06-05-2017 01:58 PM
You can use the JoltTransformJSON processor for this. Here is a Chain spec that should get you what you want:
[
{
"operation": "shift",
"spec": {
"0": {
"*": "header"
},
"*": "data[]"
}
},
{
"operation": "shift",
"spec": {
"data": {
"*": {
"*": {
"@0": "[&2].@(4,header[&])"
}
}
}
}
}
]The first operation splits the top array into "header" (containing the first element) and "data" (containing the rest). The second operation creates an array of objects, each object having the keys from the header associated with the values from each element in the "data" array. With your input above, I get the following output:
[ {
"host" : "DUSTSADMIN.ads.xyz.de",
"host_icons" : "menu",
"host_state" : "UP",
"num_services_crit" : "0",
"num_services_ok" : "28",
"num_services_pending" : "0",
"num_services_unknown" : "0",
"num_services_warn" : "0"
}, {
"host" : "DUSTSVMDC01.ads.xyz.de",
"host_icons" : "menu",
"host_state" : "UP",
"num_services_crit" : "0",
"num_services_ok" : "34",
"num_services_pending" : "0",
"num_services_unknown" : "0",
"num_services_warn" : "0"
}, {
"host" : "DUSTSVMDC02.ads.xyz.de",
"host_icons" : "menu",
"host_state" : "UP",
"num_services_crit" : "0",
"num_services_ok" : "34",
"num_services_pending" : "0",
"num_services_unknown" : "0",
"num_services_warn" : "0"
} ]
Created 06-06-2017 08:58 AM
Hi Matt, great solution!!!
Thanks Timo