1
+ import sys
2
+ import os
3
+ # import from utils/__init__.py
4
+ sys .path .insert (0 , os .path .join (os .path .dirname (__file__ ), ".." ))
5
+ from utils import *
6
+ import time
7
+ from splunklib .client import connect
8
+ from splunklib import results
9
+ from splunklib import six
10
+
11
+ def cmdline (argv , flags , ** kwargs ):
12
+ """A cmdopts wrapper that takes a list of flags and builds the
13
+ corresponding cmdopts rules to match those flags."""
14
+ rules = dict ([(flag , {'flags' : ["--%s" % flag ]}) for flag in flags ])
15
+ return parse (argv , rules , ".splunkrc" , ** kwargs )
16
+
17
+ def modes (argv ):
18
+ opts = cmdline (argv , [])
19
+ kwargs_splunk = dslice (opts .kwargs , FLAGS_SPLUNK )
20
+ service = connect (** kwargs_splunk )
21
+
22
+ # By default the job will run in 'smart' mode which will omit events for transforming commands
23
+ job = service .jobs .create ('search index=_internal | head 10 | top host' )
24
+ while not job .is_ready ():
25
+ time .sleep (0.5 )
26
+ pass
27
+ reader = results .ResultsReader (job .events ())
28
+ # Events found: 0
29
+ print ('Events found with adhoc_search_level="smart": %s' % len ([e for e in reader ]))
30
+
31
+ # Now set the adhoc_search_level to 'verbose' to see the events
32
+ job = service .jobs .create ('search index=_internal | head 10 | top host' , adhoc_search_level = 'verbose' )
33
+ while not job .is_ready ():
34
+ time .sleep (0.5 )
35
+ pass
36
+ reader = results .ResultsReader (job .events ())
37
+ # Events found: 10
38
+ print ('Events found with adhoc_search_level="verbose": %s' % len ([e for e in reader ]))
39
+
40
+ if __name__ == "__main__" :
41
+ modes (sys .argv [1 :])
0 commit comments