{"id":6165,"date":"2017-03-20T09:42:16","date_gmt":"2017-03-20T14:42:16","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=6165"},"modified":"2017-03-20T09:42:16","modified_gmt":"2017-03-20T14:42:16","slug":"searching-splunk-and-analyzing-results-with-pydblite","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2017\/03\/20\/searching-splunk-and-analyzing-results-with-pydblite\/","title":{"rendered":"Searching splunk and analyzing results with PyDbLite"},"content":{"rendered":"<p>We had a need to analyze how often a web shopper used more than one device to manage her shopping cart within a given time tolerance.  We store our Apache access logs in Splunk, so this post is simply a pointer to how you can query Splunk, and take the results and analyze them with an in-memory database in python.<\/p>\n<pre>\r\nfrom pydblite.sqlite import Database, Table\r\nimport splunklib.client as client\r\nimport splunklib.results as results\r\n\r\nservice = client.connect(host=\"cmhlpsplksea01\",port=\"8089\",username=\"showard\",password=\"**********\")\r\nrr = results.ResultsReader(service.jobs.oneshot(\"search host=\\\"cmhlpecomweb*\\\" sourcetype=access_combined 104.137.126.226 | fields _raw\", \r\n                                               **{\"earliest_time\":\"2017-01-12T15:30:00.000-05:00\",\r\n                                                  \"latest_time\":\"2017-01-12T17:30:00.000-05:00\",\r\n                                                  \"count\": 0}))\r\n\r\ndb = Database(\":memory:\")\r\ntable = Table(\"sessions\", db)\r\ntable.create(('ts', 'TEXT'), ('ip_address', 'TEXT'), ('session_id', 'TEXT'))\r\ntable.open()\r\n\r\norders = dict()\r\nfor result in rr:\r\n  agents = result['_raw'].split('\\t')\r\n  table.insert(ts=agents[0],ip_address=agents[13], session_id=agents[14])\r\n\r\nassert rr.is_preview == False\r\n\r\nfor r in (r for r in table if r['ts'].find('2017:17:2') > -1):\r\n  print \"found\", r\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We had a need to analyze how often a web shopper used more than one device to manage her shopping cart within a given time tolerance. We store our Apache access logs in Splunk, so this post is simply a&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2017\/03\/20\/searching-splunk-and-analyzing-results-with-pydblite\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[8,81],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6165"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=6165"}],"version-history":[{"count":3,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6165\/revisions"}],"predecessor-version":[{"id":6169,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6165\/revisions\/6169"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=6165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=6165"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=6165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}