Giter Site home page Giter Site logo

ryancurrah / searchsplunk Goto Github PK

View Code? Open in Web Editor NEW
14.0 1.0 5.0 19 KB

Easily create Splunk searches from Python and get the result as a Python object.

License: GNU General Public License v2.0

Python 93.86% Shell 6.14%
splunk-searches python splunk search

searchsplunk's Introduction

Build Status Coverage Status

Search Splunk

Easily create Splunk searches from Python and get the result as a Python object

Requires

Installation instructions

Searchsplunk can be installed from PyPi.

pip install searchsplunk

Usage instructions

from searchsplunk.searchsplunk import SearchSplunk
s = SearchSplunk('https://splunk.acme.com:8089', 'MYUSER', 'MYPASS', ssl_verify=True)
result = s.search('sourcetype=salt:grains openstack_uid=e0303456c-d5a3-789f-ab68-8f27561ffa0f | dedup openstack_uid')

import json
print json.dumps(result, sort_keys=True, indent=2)
{
  "fields": [
    {
      "name": "_bkt"
    },
    {
      "name": "_cd"
    },
    {
      "name": "_indextime"
    },
    {
      "name": "_kv"
    },
    {
      "name": "_raw"
    },
    {
      "name": "_serial"
    },
    {
      "name": "_si"
    },
    {
      "name": "_sourcetype"
    },
    {
      "name": "_subsecond"
    },
    {
      "name": "_time"
    },
    {
      "name": "host"
    },
    {
      "name": "index"
    },
    {
      "name": "linecount"
    },
    {
      "name": "openstack_uid"
    },
    {
      "name": "source"
    },
    {
      "name": "sourcetype"
    },
    {
      "name": "splunk_server"
    }
  ],
  "init_offset": 0,
  "messages": [],
  "preview": false,
  "results": [
    {
      "_bkt": "main~1122~25B521A6-9612-407D-A1BA-F8KJSEBB7628",
      "_cd": "1122:290410720",
      "_indextime": "1435071966",
      "_kv": "1",
      "_raw": "somefile contents",
      "_serial": "0",
      "_si": [
        "splunkserv",
        "main"
      ],
      "_sourcetype": "salt:grains",
      "_time": "2015-06-23T11:06:05.000-04:00",
      "host": "server-7654.acme.com",
      "index": "main",
      "linecount": "17",
      "openstack_uid": "e0303456c-d5a3-789f-ab68-8f27561ffa0f",
      "source": "/etc/salt/grains",
      "sourcetype": "salt:grains",
      "splunk_server": "splunkmaster"
    }
  ]
}

Contributors

Author

Ryan Currah

License

GPL v2

searchsplunk's People

Contributors

lowell80 avatar pkeeper avatar ryancurrah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

searchsplunk's Issues

can you help me how to specify time search?

def connectSplunk(host=_splunkhost, user=_splunkuser, passwd=_splunkpass, ssl_verify = _splunk_sslverify):
    try:
        splunkObj = SearchSplunk(host, user, passwd, ssl_verify=ssl_verify)
        return splunkObj
    except Exception as e:
        error(e.Message)
        return None
    

def searchSplunk(query, host=_splunkhost, user=_splunkuser, passwd=_splunkpass, ssl_verify = _splunk_sslverify):
    s = connectSplunk(host, user, passwd, ssl_verify)
    res = s.search(query)
    
    return res
query = '''
search index=xxxx
| table a,b,c
'''

query = query + '&earliest_time=%s&latest_time=%s'
search = 'blahblah'
start_time = '2018-03-17T00:00:00'
end_time = '2018-03-18T00:00:00'
query = query%(search,start_time,end_time)
print "Executing Query : \n"+query
res = searchSplunk(query)

the above code returns error
can you help me how to specify time specification?

u'messages': [{u'text': u"Error in 'table' command: Invalid argument: '&earliest_time=2018-03-17T00:00:00&latest_time=2018-03-18T00:00:00'", u'type': u'FATAL'}]}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.