Skip to content

Commit 0309d49

Browse files
Merge pull request #22 from jerewill-cisco/tag_documentation
added array2object alternative
2 parents 5e33d8c + 23c9f3e commit 0309d49

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,21 @@ Becomes...
155155

156156
So it seems very easy to search for Tags{}.Value=Premier if you wanted to find all of the things with a Premier Intersight.LicenseTier tag, but this is not safe. The problem is that if there is also a tag named, for example, SLA that also has a value of Premier you'd match it. In this default model, the Key and the Value have no relationship so using these fields is desceptively dangerous from a data integrity standpoint.
157157

158-
The solution that I've come up with so far is pretty complex but appears to be safe to use. Here is an example...
158+
The solution that I've come up with using only native Splunk SPL is pretty complex but appears to be safe to use. Here is an example...
159159

160-
`index=* sourcetype="cisco:intersight:*" | dedup Moid | rename Tags{}.Key as Key, Tags{}.Value as Value | eval zip=mvzip(Key,Value, ":") | mvexpand zip |rex field=zip mode=sed "s/$/\"}/g" |rex field=zip mode=sed "s/^/{\"tag./g"| rex field=zip mode=sed "s/:/\": \"/g" | spath input=zip | transaction Moid | search tag.Intersight.LicenseTier=Premier`
160+
`index=* sourcetype="cisco:intersight:*" | dedup Moid | rename Tags{}.Key as Key, Tags{}.Value as Value | eval zip=mvzip(Key,Value, ":") | mvexpand zip |rex field=zip mode=sed "s/$/\"}/g" |rex field=zip mode=sed "s/^/{\"Tags./g"| rex field=zip mode=sed "s/:/\": \"/g" | spath input=zip | transaction Moid | search Tags.Intersight.LicenseTier=Premier`
161161

162-
This approach returns all of the available tags as separate fields named `tag.<Key>`. This certainly seems much more convenient to use as we can now search the value of specific tags.
162+
This approach returns all of the available tags as separate fields named `Tags.<Key>`. This certainly seems much more convenient to use as we can now search the value of specific tags.
163163

164-
![Improved Tag Decoding Example](images/improved_spath.png)
164+
![Improved Tag Decoding Example](images/improved_tag.png)
165165

166-
You could also use this approach to create a report of the tags in use.
166+
An alternate (and perhaps better) approach is using the [array2object](https://splunkbase.splunk.com/app/6161/) application that is available from Splunkbase.
167167

168-
`index=* sourcetype="cisco:intersight:*" | dedup Moid | rename Tags{}.Key as Key, Tags{}.Value as Value | search Key=* | eval zip=mvzip(Key,Value, ":") | mvexpand zip |rex field=zip mode=sed "s/$/\"}/g" |rex field=zip mode=sed "s/^/{\"tag./g"| rex field=zip mode=sed "s/:/\": \"/g" | spath input=zip | transaction Moid | table sourcetype, Moid, tag.*`
168+
`index=* sourcetype="cisco:intersight:*" | dedup Moid | array2object path="Tags" key=Key value=Value | search Tags.Intersight.LicenseTier=Premier`
169+
170+
This approach provides the same end result to the search above with a much cleaner query syntax.
171+
172+
Read more about [array2object at SplunkBase](https://splunkbase.splunk.com/app/6161/).
169173

170174
## aaaAuditRecords
171175

images/improved_spath.png

-16.7 KB
Binary file not shown.

images/improved_tag.png

11 KB
Loading

0 commit comments

Comments
 (0)