I have json file with below data, I would like to get name and status and display it in table. Help here is much appreciated. I'm new to splunk
Name Status
assetPortfolio_ValidateAddAssetForOthers passed
assetPortfolio_ValidatePLaceHolderText failure
assetPortfolio_ValidateIfFieldUpdated passed
{
"name": "behaviors",
"children": [
{
"name": "assetPortfolio_ValidateAddAssetForOthers",
"status": "passed"
},
{
"name": "assetPortfolio_ValidatePlaceHolderText",
"status": "failure"
},
{
"name": "assetPortfolio_ValidateIfFieldUpdated",
"status": "passed"
}
]
}
It looks like spath has a character limit spath - Splunk Documentation
Try using rex to extract key/value pairs
| rex max_match=0 "(?<keyvalue>\"[^\"]+\":\"[^\"]+\")"
| mvexpand keyvalue
| rex field=keyvalue "\"(?<key>[^\"]+)\":\"(?<value>[^\"]+)\""
| eval {key}=value
| fields - keyvalue key value _raw
| eval date=strftime(_time,"%F")
| untable date name state
```| stats count by name
| where count > 1```
| xyseries name date state
Btw, you do have a duplicate, assetPortfolio_VerifyAPMPropertyDropdown, uncomment the commented lines and comment out the last line to show it.
| spath children{} output=children
| mvexpand children
| spath input=children
| table name status
Thank you for your inquiry. This is useful for isolated json files. However, this file is generated every day, and I'd like to display the latest 7 days' numbers in a table by date.
Splunk, in particular SPL, works on a pipeline of events. Each event in the pipeline is processed. If you have a number of events over a number of days, how do you distinguish them from each other as your event example doesn't appear to have a timestamp?
That being said, if you do have a way to identify the original events, before the mvexpand, you can use stats by to gather the separate parts together again.
Perhaps if you provided more representative examples of the events you are dealing with, an explanation of exactly what you are trying to achieve and a representation of your expected / desired output, we might be able to assist you further.
Thanks again!
Yes! Below json files are generated every day and I would like to show them in table format as below
Source: Group01/1318/test.json
Generated timestamp: 11/12 12:00 AM
{
"Portfolio_Validate1":"skipped",
"Portfolio_Validate2":"passed",
"Portfolio_Validate3":"passed",
"Portfolio_Validate4":"broken"
}
Source: Group01/1319/test.json
Generated timestamp: 11/13 12:00 AM
{
"Portfolio_Validate1":"passed",
"Portfolio_Validate2":"passed",
"Portfolio_Validate3":"passed",
"Portfolio_Validate4":"broken"
}
Source: Group01/1320/test.json
Generated timestamp: 11/14 12:00 AM
{
"Portfolio_Validate1":"passed",
"Portfolio_Validate2":"failed",
"Portfolio_Validate3":"passed",
"Portfolio_Validate4":"passed"
}
| 11/14 12:00 AM | 11/14 12:00 AM | 11/12 12:00 AM |
Portfolio_Validate1 | passed | passed | skipped |
Portfolio_Validate1 | failed | passed | passed |
Portfolio_Validate1 | passed | passed | passed |
Portfolio_Validate1 | passed | broken | broken |
Assuming your timestamp is in _time and your events (as shown) are in _raw, try this
| spath
| untable _time name state
| eval date=strftime(_time,"%F")
| xyseries name date state
Thanks Again! You're my saver
Your query works. However, For some reason I see state twice. Also, i see source, host etc... being listed in the table
Try removing the other fields
| table _time _raw
| spath
| untable _time name state
| eval date=strftime(_time,"%F")
| xyseries name date state
Thanks one more time.
Interestingly, your recent query is fetching only 77 values where as i have 182 values in json file. Is this splunk limitation?
You possibly have duplicates/triplicates in your events.
I checked complete json, don't see any duplicates. I see some solutions in the blog asking to switch from "INDEXED_EXTRACTIONS = JSON" to "KV_MODE = json". I'm not sure that will work in my case.
https://community.splunk.com/t5/Splunk-Search/INDEXED-EXTRACTIONS-JSON-limiting-multivalued-fields-t...
The table _time _raw and spath effectively reparse the JSON otherwise you have the extracted files from the ingest as well as the fields from the spath.
Without seeing the actual events, I can't tell what might be causing the disparity between the counts and number of lines. Perhaps there are extra blank lines, or new line characters.
I don't see any new line character. I have attached a snippet of the event. Please let me know how can I send event file (.json file). json is not supported attachment here.
Copy the raw event and paste into a code block </>
Due to character limitation in the blog i removed assetPortfolio_Verify prefix in the name
example: "AssetDetailsPage":"passed", should be "assetPortfolio_VerifyAssetDetailsPage":"passed",
<
/>
It looks like spath has a character limit spath - Splunk Documentation
Try using rex to extract key/value pairs
| rex max_match=0 "(?<keyvalue>\"[^\"]+\":\"[^\"]+\")"
| mvexpand keyvalue
| rex field=keyvalue "\"(?<key>[^\"]+)\":\"(?<value>[^\"]+)\""
| eval {key}=value
| fields - keyvalue key value _raw
| eval date=strftime(_time,"%F")
| untable date name state
```| stats count by name
| where count > 1```
| xyseries name date state
Btw, you do have a duplicate, assetPortfolio_VerifyAPMPropertyDropdown, uncomment the commented lines and comment out the last line to show it.
Which fields are missing?