Example #1
0
def _main():    
    argc = len(sys.argv)
    argv = sys.argv
    if argc >= 3:
        user = argv[1]
        search = argv[2]
        insertpos = None
        if argc > 3:
            insertpos = int(argv[3])
        help = help(utils.TEST_SESSION(), utils.TEST_NAMESPACE(), user, search, insertpos, None, None, 10, None, None, 
                    useTypeahead=True, showCommandHelp=True, showCommandHistory=True, showFieldInfo=True)
        
        for attr,val in help.items():
            print "%s%s = %s\n" %(attr," "*abs(40-len(attr)),val)
    elif argc > 1 and argv[1] == 'testtypeahead':
        testtypeahead()        
    elif argc > 1 and argv[1] == 'multitest':
        # monster = "index=_internal  (( (source=\"*/httpd/access_log*\" OR source=\"*\\httpd\\access_log*\" ) status=200 file=splunk-* NOT ( ( useragent=\"Acoon-*\" ) OR ( useragent=\"AdsBot-Google *\" ) OR ( useragent=\"AISearchBot *\" ) OR ( useragent=\"Baiduspider*\" ) OR ( useragent=\"* BecomeBot/*\" ) OR ( useragent=\"Biz360 spider *\" ) OR ( useragent=\"BlogBridge *\" ) OR ( useragent=\"Bloglines-Images/*\" ) OR ( useragent=\"BlogPulseLive *\" ) OR ( useragent=\"BoardReader/*\" ) OR ( useragent=\"bot/*\" ) OR ( useragent=\"* Charlotte*\" OR useragent=\"*(Charlotte/*)\" ) OR ( useragent=\"ConveraCrawler/*\" ) OR ( useragent=\"* DAUMOA-web\" ) OR ( useragent=\"* discobot*\" ) OR ( useragent=\"* DoubleVerify *\" ) OR ( useragent=\"Eurobot/*\" ) OR ( useragent=\"* Exabot/*\" ) OR ( useragent=\"FeedHub *\" ) OR ( useragent=\"Gigabot*\" ) OR ( useragent=\"* Googlebot/*\" OR useragent=\"Googlebot-*\" ) OR ( useragent=\"Grub*\" ) OR ( useragent=\"gsa-crawler *\" ) OR ( useragent=\"* heritrix/*\" ) OR ( useragent=\"ia_archiver*\" ) OR ( useragent=\"BlogSearch/*\" ) OR ( useragent=\"ichiro/*\" ) OR ( useragent=\"Yeti/*\" ) OR ( useragent=\"Inar_spider *\" ) OR ( useragent=\"kalooga/*\" ) OR ( useragent=KeepAliveClient ) OR ( useragent=\"larbin*\" ) OR ( useragent=\"LinkAider\" ) OR ( useragent=\"McBot/*\" ) OR ( useragent=\"MLBot *\" ) OR ( useragent=\"Morfeus F*****g Scanner\" ) OR ( useragent=\"msnbot*\" ) OR ( useragent=\"MSRBOT *\" ) OR ( useragent=*nagios-plugins* ) OR ( useragent=\"* Netcraft *\" ) OR ( useragent=\"*/Nutch-*\" ) OR ( useragent=\"panscient.com\" ) OR ( useragent=\"Pingdom.com_*\" ) OR ( useragent=\"PrivacyFinder/*\" ) OR ( useragent=\"Snapbot/*\" ) OR ( useragent=\"Sogou *\" ) OR ( useragent=\"Speedy Spider *\" ) OR ( useragent=\"Sphere Scout*\" ) OR ( useragent=\"*(Spinn3r *\" ) OR ( useragent=\"Technoratibot/*\" ) OR ( useragent=\"*/Teoma*\" ) OR ( useragent=\"TurnitinBot/*\" ) OR ( useragent=\"*(Twiceler*\" ) OR ( useragent=\"UtilMind *\" ) OR ( useragent=\"* voilabot *\" ) OR ( useragent=\"WebAlta*\" ) OR ( useragent=\"Splunk webping bundle\" ) OR ( useragent=\"* Yahoo! Slurp*\" OR useragent=\"* Yahoo! * Slurp*\" ) OR ( useragent=\"Yanga *\" ) OR ( useragent=\"YebolBot *\" ) ) NOT ( ( clientip=10.0.0.0/8 OR clientip=172.16.0.0/12 OR clientip=192.168.0.0/16 ) ) NOT ( ( clientip=64.127.105.34 OR clientip=64.127.105.60 OR clientip=206.80.3.67 ) ) ) ) _time<1199000000 _time>1198950000"
        lilmonster = "error"        
        total = 0.0
        for i in xrange(1,1000):
            spent = multiuserSimulation(19, 'search %s' % lilmonster)
            total += spent
            print "Time: %ss Avg: %ss" % (spent, total / i)
    else:        
        print 'Usage:'
        print argv[0], '<user> <search> [<insertpos>]'
        print argv[0], 'testtypeahead'
        print argv[0], 'multitest'
def testtypeahead():
    qs = [
        'search index',
        'search index=',
        'search index="',
        'search index="_i',
        'search index=_i',
        'search index =',
        'search index ="',
        'search index ="_i',
        'search index =_i',
        'search index= ',
        'search index= "',
        'search index= "_i',
        'search index= _i',
        'search index = ',
        'search index = "',
        'search index = "_i',
        'search index = _i',
        'search * sourcetype=sta',
        'search * sourcetype = sta',
        'search * sourcetype = "sta',
        'search * sourcetype="sta',
        'search * sourcetype::sta',
        'search index=',
        'search index=_internal index=_',
        'search tag::',
    ]

    bads = ['index=index', 'ii', 'tag::tag', 'indexindex']

    user = '******'
    for q in qs:
        out = help(utils.TEST_SESSION(),
                   utils.TEST_NAMESPACE(),
                   user,
                   q,
                   None,
                   None,
                   None,
                   10,
                   None,
                   None,
                   useTypeahead=True,
                   showCommandHelp=True,
                   showCommandHistory=True,
                   showFieldInfo=True)
        ta = out['typeahead']
        print q
        print "-" * 80
        for v in ta:
            print "USERTYPED: '%s' \tSUGGESTION: '%s'" % (q, v)
            v = str(v).replace('"', '').replace(' ', '')
            for bad in bads:
                if bad in v:
                    print "FAILED IN TYPEAHEAD FOR '%s' WITH '%s'" % (q, v)
                    return
    print "passed."
Example #3
0
 def run(self):
     try:
         search = self.search + " " + str(random.randint(0,20)) + " | stats count"
         #print "username: %s sk: %s running search: %s" % (self.username, self.sessionKey, search)
         #print "username: %s sk: %s" % (self.username, self.sessionKey)
         help = searchhelper.help(self.sessionKey, utils.TEST_NAMESPACE(), self.username, search, None, None, None, 10, None, None, 
                                  useTypeahead=True, showCommandHelp=True, showCommandHistory=True, showFieldInfo=True)
         ta = help['typeahead']
         #print ta
     except Exception, e:
         print e
def _main():
    if len(sys.argv) > 1:
        search = sys.argv[1]
        cmds = utils.getCommands(search, None)
        comms = [c.strip() for search in cmds for c,a in search ]
        args = [a.strip() for search in cmds for c,a in search ]
        print "Commands:", cmds
        print "Commands: %s  Args: %s" % (comms, args)
    else:
        user = "******"
        sessionKey = utils.TEST_SESSION()
        namespace = utils.TEST_NAMESPACE()
        #print getPastSearches(user, None, sessionKey, namespace)
        bnf = utils.getStanzas("searchbnf", sessionKey, user, namespace)
        data, searches = getNextData(user, bnf, sessionKey, namespace)
        for cmd in data:
            print "\t%s" % cmd
def _main():
    argc = len(sys.argv)
    argv = sys.argv
    sessionKey = utils.TEST_SESSION()
    namespace = utils.TEST_NAMESPACE()
    username = '******'
    if len(argv) < 2:
        usage()
    cmd = argv[1]
    if argc == 3 and cmd != "parse":
        inputtxt = argv[2]
        bnf = getBNF(cmd, sessionKey, username, namespace)
        exp = getExp(bnf)
        next = getNext(exp, inputtxt)
        #regex = getRegex(cmd, sessionKey)

        datatypes = utils.getStanzas("datatypesbnf", sessionKey, username,
                                     namespace)

        print "bnf:\t", bnf
        print "exp:\t", exp
        print "next:\t", next
        print "regex:\t", exp.toRegex(datatypes)
        print "Simpleregex:\t", exp.toSimpleRegex(True)

    elif argc >= 3:
        bnf = argv[2]
        inputtxt = ""
        if argc == 4:
            inputtxt = argv[3]
        exp = getExp(bnf)
        next = getNext(exp, inputtxt)
        #print "exp:", exp
        #print "minMatchLen:", exp.minMatchLen()
        #print "next:", next
        print "%s\t%s" % (exp.minMatchLen(), bnf)
    else:
        usage()