Reporting

Retrieve comments from savedsearches.conf via Splunk GUI

ramgnisiv
Path Finder

We are adding comments to each search in our apps savedsearches.conf to keep our technical documentation for all saved searches as in-line as possible.

We are using Splunk native comment macro for adding comments in-line.

Inside the 'comment' tag this is done using JSON format:

`comment("{"type":"xxx","title":"yyy","id":"123","dataSource":"zzz","dataSourceTechName":"sss","dataSourceGuiName":"ttt","scheduleFrequency":"1d"}")`

All saved searches are in the savedsearches.conf file inside the app folder.

The question is: How can we extract the comments for all saved searches with a single search in Splunk GUI and table the data in the 'comment' tag?

With this search, i can get the 'search' from the savedsearches.conf, but i only want the 'comment' part of the search that gives me the field that are in the JSON, like title, type, id etc and the corresponding values:

| rest /servicesNS/-/-/saved/searches splunk_server=local | table title  search

I need to be able to split the comment field into separate fields that display the field name and the corresponding value.

Edit:

Final version with correct way of working is as follows:

| rest /servicesNS/-/-/saved/searches splunk_server=local 
 | where search like "%`comment(%" 
 | rex field=search "\`comment\(\"(?<comment>.*)\)\`" 
 | fields  search comment
 | spath input=comment
 | fields  - search comment
0 Karma
1 Solution

ramgnisiv
Path Finder

The final version i needed is based on Kamlesh's answer with the addition of the spath command

| rest /servicesNS/-/-/saved/searches splunk_server=local 
 | where search like "%`comment(%" 
 | rex field=search "\`comment\(\"(?<comment>.*)\)\`" 
 | fields  search comment
 | spath input=comment
 | fields  - search comment

View solution in original post

0 Karma

ramgnisiv
Path Finder

The final version i needed is based on Kamlesh's answer with the addition of the spath command

| rest /servicesNS/-/-/saved/searches splunk_server=local 
 | where search like "%`comment(%" 
 | rex field=search "\`comment\(\"(?<comment>.*)\)\`" 
 | fields  search comment
 | spath input=comment
 | fields  - search comment
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@ramgnisiv

Gald to help you

Happy Splunking

0 Karma

woodcock
Esteemed Legend

Like this:

| rest /servicesNS/-/-/saved/searches splunk_server=local | table title  search
| makemv tokenizer="\s*\|\s*([^\|]+)" search
| eval search = mvfilter(match(search, "\s*`comment"))
| rename search AS comments
0 Karma

ramgnisiv
Path Finder

I get an empty comments field when i apply this search

0 Karma

woodcock
Esteemed Legend

I made a slight adjustment. Try it now.

0 Karma

ramgnisiv
Path Finder

I still get empty comment fields for all saved searches with the adjustment you did.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@ramgnisiv
Can you please try this?

| rest /servicesNS/-/-/saved/searches splunk_server=local 
| where search like "%`comment(%" 
| rex field=search "\`comment\(\"(?<comment>.*)\)\`" | table title search comment

Thanks

ramgnisiv
Path Finder

I get the following error when i apply this search:

Error in 'SearchParser': Missing a closing tick mark for macro expansion.

0 Karma

ramgnisiv
Path Finder

This works, now i need to split the comment field into separate fields, called type, title, id, dataSource, dataSourceTechName, dataSourceGuiName, scheduleFrequency

These fields must display the values that correspond to the fields.

Any thoughts on how to do that also?

0 Karma

ramgnisiv
Path Finder

i did it with spath, i will share it in the question

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@@ramgnisiv

I have updated my answer.

Can you try it?

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...