python - splunklib.binding.HTTPError:HTTP 400 错误请求 - 未知搜索命令“索引”
问题描述
运行搜索命令时出错
在使用 splunk 企业时,我想从后端运行搜索命令,关键字是“index =”。当我运行这个命令时,我得到了结果,但是当我在我的代码中添加这个命令时,我得到“splunklib.binding.HTTPError: HTTP 400 Bad Request -- Unknown search command 'index'”。我能够登录 splunk 企业并运行基本搜索命令“search * | head 100”
def normal_search():
#searchquery_normal = "search * | head 10"
searchquery_normal = "index = some_tool_name"
kwargs_normalsearch = {"exec_mode": "normal"}
job = service.jobs.create(searchquery_normal, **kwargs_normalsearch)
# A normal search returns the job's SID right away, so we need to poll for completion
while True:
while not job.is_ready():
pass
stats = {"isDone": job["isDone"],
"doneProgress": float(job["doneProgress"])*100,
"scanCount": int(job["scanCount"]),
"eventCount": int(job["eventCount"]),
"resultCount": int(job["resultCount"])}
status = ("\r%(doneProgress)03.1f%% %(scanCount)d scanned "
"%(eventCount)d matched %(resultCount)d results") % stats
sys.stdout.write(status)
sys.stdout.flush()
if stats["isDone"] == "1":
sys.stdout.write("\n\nDone!\n\n")
break
sleep(2)
# Get the results and display them
for result in results.ResultsReader(job.results()):
print result
job.cancel()
sys.stdout.write('\n')
预期:没有错误实际:splunklib.binding.HTTPError:HTTP 400 错误请求 - 未知搜索命令“索引”
.
解决方案
@PyPy2304
搜索查询中应该有一个search
命令。像这样
searchquery_normal = " search index = some_tool_name"
以供参考:
推荐阅读
- javascript - 工具提示在带有 svg 的 bootstrap 5 beta1 中不起作用?
- python - 带有交互式外壳的 Jupyter 中缺少 Conda 环境包
- python - 将日期时间从 pandas 导出到 sqlite 会导致浮点格式
- google-cloud-run - 在 Google Cloud Run (gRPC/Python) 上连接两个服务
- c# - 如何在 xaml.cs 按钮事件中访问视图/元素
- jquery - 使用延迟加载和带有 JPG 后备的 webp 图像
- iso - 如何将 ISO 8601 中的 totalTime 参数用于 Google 结构化数据?
- haskell - 方法重载有多少字典/参数?
- visual-studio - CMAKE Cuda/ptx 项目上的重复代码生成标志
- java - 不同大小列表的交集