0

如果我们通过访问令牌访问它,那么从 Splunk 获取保存的搜索数据的正确 HTTP 获取请求调用语法是什么?

我的 curl 命令有效,但 http.get 无效。

卷曲命令:

#os.system('curl -H "Authorization: Bearer <token>" 
 <baseurl>:8089/services/search/jobs/export --data search="savedsearch abc_backup_status" -d output_mode=csv')

请求调用 ::::

BASE_URL = '<baseurl>:8089/services/search/jobs/export'
data = {"search":"savedsearch abc_backup_status"}
headers = {'Authorization': "Bearer <token>"}
auth_response = requests.get(BASE_URL, headers=headers, data = data, verify=False)

这给出了 400 个错误。

4

1 回答 1

1

curl 选项-d或默认情况下--data暗示一种POST方法。

来自:https ://man7.org/linux/man-pages/man1/curl.1.html

  -d, --data <data>
        (HTTP MQTT) Sends the specified data in a POST request to
        the HTTP server, in the same way that a browser does when
        a user has filled in an HTML form and presses the submit
        button. This will cause curl to pass the data to the
        server using the content-type application/x-www-form-
        urlencoded.  Compare to -F, --form.

有趣的是,Splunk Docs 声称需要search/jobs/exportGET,但您正在创建一个立即导出的作业,这感觉就像是 POST 类型的操作。

我还注意到您的搜索从 savedsearch 命令开始,如果这是定期安排的 savesearch,您可能希望 GETsaved/searches/{name}/history获取最后一个执行 SID,然后是该已执行作业的结果或事件端点,而不是新搜索....但这是一个用例问题

于 2022-01-04T01:27:41.220 回答