如何使用 Python 在 Splunk API 中为 oneshot 搜索设置 TTL?

问题描述

我间歇性地从 Splunk API 返回以下错误(大约 40% 的时间搜索按预期工作):

HTTP 503 服务不可用 -- 未执行搜索:此搜索可能 由于搜索的基于角色的磁盘使用配额而不会被调度 已达到用户“[REDACTED]”的工件(使用量=1067MB, 配额=1000MB)。使用 [[/app/search/job_manager|Job Manager]] 来 删除您的一些搜索工件,或询问您的 Splunk 管理员 为您的角色增加搜索工件的磁盘配额 授权.conf.,使用率=1067MB,配额=1000MB,用户=[已编辑], concurrency_category="历史",concurrency_context="user_instance-wide"

在 splunk api 中搜索的默认 ttl 是 10 分钟(至少对于我的公司而言)。有人告诉我,我需要降低搜索的 TTL(大量搜索),并且我将停止空间不足。我没有管理员访问权限,因此无法即时增加我的空间或清理空间(据我所知)。我可以找到有关如何使用保存的搜索降低 TTL 的代码,但我使用的是 oneshot 搜索。换我不合理。

如何降低 oneshot 搜索的 ttl? 这是我现在拥有的似乎不会降低 TTL 的内容:

#setup splunk connection
service = client.connect(
    host=HOST,port=PORT,username=suser,password=spass,autologin=True,)
#setup arguments
kwargs_oneshot = {"count" :  "0","earliest_time": begin,"latest_time": end,"set_ttl":60
                 }
#setup search job    
oneshotsearch_results = service.jobs.oneshot(query,**kwargs_oneshot)
# Get the results and display them using the ResultsReader
reader = results.ResultsReader(oneshotsearch_results)

解决方法

我相信您需要set_ttlttl 而不是timeout。见https://docs.splunk.com/Documentation/Splunk/latest/RESTREF/RESTsearch#search.2Fjobs

另外,考虑减少搜索量或减少搜索频率。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...