3 deleted 61 characters in body
source | link

sorry for the long title.

I need to take some JSON, slice it using JQ so New Relic can parse it properly as it only takes a specific format when pushing JSON to their dashboards.

Thanks in advance for any tips. I think jq is my answer for manipulating the JSON to be formatted but I am hitting some walls.

sorry for the long title.

I need to take some JSON, slice it using JQ so New Relic can parse it properly as it only takes a specific format when pushing JSON to their dashboards.

Thanks in advance for any tips. I think jq is my answer for manipulating the JSON to be formatted but I am hitting some walls.

I need to take some JSON, slice it using JQ so New Relic can parse it properly as it only takes a specific format when pushing JSON to their dashboards.

I think jq is my answer for manipulating the JSON to be formatted but I am hitting some walls.

2 edited tags
| link
1
source | link

Slicing JSON with JQ to Create Arrays for New Relic Ingestion

sorry for the long title.

I need to take some JSON, slice it using JQ so New Relic can parse it properly as it only takes a specific format when pushing JSON to their dashboards.

I am using a bash script and WPCLI and then formatting the JSONs output using JQ.

Below is my script.

#!/bin/bash

#for d in /var/www/* ; do
#   echo "$d"
#done

for f in /var/www/*/public_html/; do
    if [[ -d $f ]]; then
                #echo "$f"

                cd $f;
                SITEURL="$(wp option get siteurl)"
                USERS="$(wp user list --fields=display_name,user_email,user_registered,roles --format=json | jq .[])"
                PLUGINS="$(wp plugin list --format=json | jq .[])"

                echo "${SITEURL}" "${USERS}" "${PLUGINS}"
                cd ../.. ;
    fi
done

Below is the output I am getting...

cat wp-info-output 
http://mytest1.com {
  "display_name": "testuser1",
  "user_email": "test.user@testing.com",
  "user_registered": "2018-11-26 17:44:09",
  "roles": "administrator"
} {
  "name": "akismet",
  "status": "inactive",
  "update": "available",
  "version": "4.0.8"
}
{
  "name": "hello",
  "status": "inactive",
  "update": "none",
  "version": "1.7"
}

I need it to look like this...

[
  {
    "eventType":"WordpressSite",
    "siteurl":"http://mytest1.com"
  },
  {
    "eventType":"WordpressPlugins",
    "pluginName": "akismet",
    "status": "inactive",
    "update": "available",
    "version": "4.0.8"
  },
    {
    "eventType":"WordpressPlugins",
    "pluginName": "hello",
    "status": "inactive",
    "update": "none",
    "version": "1.7"
  }
  {
    "eventType":"Users",
    "display_name": "testuser2",
    "user_email": "test.user@testing.com",
    "user_registered": "2018-11-26 17:44:04",
    "roles": "administrator"
  }
]

Thanks in advance for any tips. I think jq is my answer for manipulating the JSON to be formatted but I am hitting some walls.