在使用pythonsdk时,如何获得Splunk搜索结果的完整内容?

2024-07-05 08:58:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我可以从one-shot查询得到结果,但我无法获得_raw字段的完整内容。在

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

这给了我以下关于“原始”的信息:

^{pr2}$

所以这个内容被截断为120个字符。我需要搜索结果的全部值,因为我需要在此基础上运行一些字符串比较。我没有找到任何关于ResultsReader字段或其大小限制的文档。在


Tags: thekeyimportclient内容searchstringas
1条回答
网友
1楼 · 发布于 2024-07-05 08:58:37

我最好的猜测是,这是由于在事件原始数据中插入特殊标记来突出显示splunkui前端中匹配的搜索词造成的。很可能,您的搜索字符串指定在截断点出现在原始数据中的匹配文本项。对于SDK结果获取方法来说,这不是一个合适的默认行为,目前已经打开了一个bug来解决这个问题(内部参考DVPL-1519)。在

幸运的是,避免这个问题非常简单:只需将segmentation='none'作为参数传递给作业.结果()方法:

(…)
oneshotsearch_results = service.jobs.oneshot(search_string,segmentation='none')
(…)

请注意服务.工作()方法仅适用于Splunk 5.0及更高版本。在

相关问题 更多 >