zoukankan      html  css  js  c++  java
  • get data from splunk

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

  • 相关阅读:
    并发编程-process对象的其他属性方法
    Python json格式处理
    msf制作反弹shell
    Windows渗透备忘录
    WPF listbox实现多列显示数据
    Postgresql插入或更新操作upsert
    Windows 10 IoT Core Samples
    物联网平台开源
    实现领域驱动设计
    wpf Visibility 动画
  • 原文地址:https://www.cnblogs.com/vickey-wu/p/7150017.html
Copyright © 2011-2022 走看看