Knowledge Management

How could I check for optional keywords and options in custom command?

grimlock
Path Finder

In building a custom command I am trying to validated the presence/absence of an option:

Sample code doing the assignment can be found below


results,dummyresults,settings = splunk.Intersplunk.getOrganizedResults()
field = options.get('field', None)

charsense = options.get('detect', None)

Very simply I want to assign none to charsense if the option is not present.
Conversely, I would like to NOT perform character detection if the value is not present.

Additionally, any way to present a usage to the user in the event they do not give either option would be beneficial.

Thank you very much, you guys and gals are always a huge help

Tags (1)
0 Karma
1 Solution

grimlock
Path Finder

Below is the code I ended up using:

For optional keywords:
detect = None
if 'detection' in keywords:
detect = True

For required keywords missing options:
if not options.has_key('field'):
output_result = splunk.Intersplunk.generateErrorResults("Error Message placed here")

View solution in original post

0 Karma

grimlock
Path Finder

Below is the code I ended up using:

For optional keywords:
detect = None
if 'detection' in keywords:
detect = True

For required keywords missing options:
if not options.has_key('field'):
output_result = splunk.Intersplunk.generateErrorResults("Error Message placed here")

0 Karma

DalJeanis
SplunkTrust
SplunkTrust

@grimlock - Thanks for posting your solution! Please accept your answer so the question will show as closed.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

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 ...