我可以從one_shot查詢中獲得結果,但是我無法獲取_raw字段的完整內容。如何在使用Python SDK時獲取Splunk搜索結果的完整內容?
import splunklib.client as client
import splunklib.results as results
def splunk_oneshot(search_string, **CARGS):
# Run a oneshot search and display the results using the results reader
service = client.connect(**CARGS)
oneshotsearch_results = service.jobs.oneshot(search_string)
# Get the results and display them using the ResultsReader
reader = results.ResultsReader(oneshotsearch_results)
for item in reader:
for key in item.keys():
print(key, len(item[key]), item[key])
這讓我對_raw如下:
('_raw', 120, '2013-05-03 22:17:18,497+0000 [SWF Activity attNsgActivitiesTaskList1 19] INFO c.s.r.h.s.a.n.AttNsgSmsRequestAdapter - ')
所以這個內容是在120個字符被截斷。我需要搜索結果的全部值,因爲我需要在其上執行一些字符串比較。我還沒有找到有關ResultsReader字段或其大小限制的任何文檔。
解決了這個問題,謝謝hexx!這些結果字段中是否有任何文檔? – sophe 2013-05-07 15:46:08
關於'jobs.oneshot()'方法[在dev.splunk.com上](http://docs.splunk.com/DocumentationStatic/PythonSDK/1.0/client.html#splunklib。)的參數有一些很好的信息。 client.Jobs.oneshot),儘管我可以看到「分段」參數沒有在那裏列出!我會解決這個問題。這些信息確實存在於'/ services/search/jobs/{SID}/events'端點的Splunk REST API參考中,'jobs.oneshot()'調用'job.results()'方法,最終命中。 – hexx 2013-05-07 19:48:03
沒有,這是再次打破,截斷119個字符即使分段='無': ('_raw',119,'2013-05-08 16:09:11,040 + 0000 [SWF活動attNsgActivitiesTaskList1 1]信息csrhsanAttNsgSmsRequestAdapter - ') 我做了一個pip安裝-U,以防sdk改變 – sophe 2013-05-08 18:51:32