How to convert splunk curl query into Rcurl [closed]

拟墨画扇 提交于 2019-12-08 14:17:53

问题


I want to convert this particular splunk curl request into Rcurl:

curl -k -u admin:pass https://localhost:8089/services/search/jobs --get -d search="eventCount>100"


回答1:


This provides an idiom via httr you can extrapolate from for other Splunk calls:

#' @param search_terms
#' @param other parameters passed to httr GET/POST request
#' @return data.frame of results
search_now <- function(search_terms, ...) {

  require(httr)

  # i.e. "https://localhost:8089"
  splunk_server <- Sys.getenv("SPLUNK_API_SERVER")
  username <- Sys.getenv("SPLUNK_USERNAME")
  password <- Sys.getenv("SPLUNK_PASSWORD")

  search_job_export_endpoint <- "servicesNS/admin/search/search/jobs/export"

  response <- GET(splunk_server,
                   path=search_job_export_endpoint,
                   encode="form",
                   config(ssl_verifyhost=FALSE, ssl_verifypeer=0),
                   authenticate(username, password),
                   query=list(search=paste0("search ", search_terms, collapse="", sep=""),
                              output_mode="csv"),
                   verbose(), ...)

  result <- read.table(text=content(response, as="text"), sep=",", header=TRUE,
                       stringsAsFactors=FALSE)

  result

}

It expects the server base URL to be in SPLUNK_API_SERVER environment variable (stick them in .Renvion) and the username and password to be in those other two really obvious variables in the code.

I had that lying around in a gist for someone else so glad it gets some more mileage. A full splunkr package is in the works.



来源:https://stackoverflow.com/questions/32276780/how-to-convert-splunk-curl-query-into-rcurl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!