码迷,mamicode.com
首页 > 其他好文 > 详细

get data from splunk

时间:2017-07-11 13:25:16      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:app   net   bsp   lock   result   star   com   pytho   down   

 

link:

http://dev.splunk.com/view/python-sdk/SP-CAAAER5

download SDK & setup with python

 

code:

import splunklib.client as client import splunklib.results as results import time

start = time.time()

HOST = "hostname"

PORT = 8089

USERNAME = "username"

PASSWORD = "password"

service = client.connect(

    host=HOST,

    port=PORT,

    username=USERNAME,

    password=PASSWORD)

 

kwargs_oneshot = {"earliest_time": "2017-07-01T12:00:00.000",

                  "latest_time": "2017-07-09T12:00:00.000",

                  "exec_mode": "blocking"}      # ,‘search_mode‘: ‘normal‘

searchquery_oneshot = "search index=networkname netlinename|table rowname"

 

search_results = service.jobs.create(searchquery_oneshot, **kwargs_oneshot)

 

# Get the results and display them using the ResultsReader

rr = search_results.results(**{‘count‘: 0})

reader = results.ResultsReader(rr)

inbound = []

outbound = []

for item in reader:

    _raw_list = str(item[‘_raw‘])

    # print _raw_list    

  inbound.append(_raw_list.split(",")[3])

     outbound.append(_raw_list.split(",")[4])

# print inbound

# print outbound

print "inLen", len(inbound)

print "outLen", len(outbound)

print str(int(time.time() - start))

 

get data from splunk

标签:app   net   bsp   lock   result   star   com   pytho   down   

原文地址:http://www.cnblogs.com/vickey-wu/p/7150017.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!