I’m currently processing a list of systems processed in a vulnerability scan. Each host has a list of tags associated with it. I’ve created a function that will turn the tags into a comma-separated list to be pushed to a reporting database (PostgreSQL), but I can’t figure out how to add a new key to each host entry to store it. The closest I can get is a running list of all tags from all systems in the source data concatenated together. Function code below (with commented out attempt to insert is as a new key for each host):
item.tagList = "";
for(const hostitem of $json["host_list_output"]["response"]["host_list"]["host"])
{
for(const tagname of hostitem["tags"]["tag"])
{
item.tagList += tagname["name"] + ", ";
}
if(item.tagList.length > 0)
{
item.tagList = item.tagList.slice(0, -2);
}
//item.host_list_output.response.host_list.host.tagList = item.tagList;
//item.tagList = "";
}
return item;
This is a sample of the source data I’m working from (Qualys, for the curious):
{
"host_list_output": {
"response": {
"datetime": "2021-06-17T17:18:02Z",
"host_list": {
"host": [
{
"id": "<masked id>",
"ip": "<masked ip>",
"tracking_method": "IP",
"dns": "<masked FQDN>",
"dns_data": {
"hostname": "<masked hostname>",
"domain": "<masked domain>",
"fqdn": "<masked FQDN>"
},
"tags": {
"tag": [
{
"tag_id": "37724688",
"name": "Not scanned in 90 days"
},
{
"tag_id": "46439938",
"name": "Internet Facing Assets"
},
{
"tag_id": "63812476",
"name": "OS: Linux x.x"
},
{
"tag_id": "78797433",
"name": "Not scanned in 30 days"
},
{
"tag_id": "78797434",
"name": "Not scanned 120 days"
},
{
"tag_id": "78966920",
"name": "OS: Ubuntu xx"
},
{
"tag_id": "78966927",
"name": "OS: Linux 2.x"
}
]
},
"last_vuln_scan_datetime": "2020-03-04T12:40:17Z",
"last_vm_scanned_date": "2020-03-04T12:40:17Z",
"last_vm_scanned_duration": "564"
},
Any ideas on where I’m going wrong?