Splunk Search

tstats via REST API

ryanstaats
New Member

Greetings folks, and thanks in advance for a little brainpower here.  I'm definitely a splunk novice.

I'm trying to pull some tstats values via a REST call via powershell, and I can't seem to return any data.  I can perform a basic search "search hostname=servername.corp" via this method and it will return the results I expect.

The search term that gets me the data I want via the web interface is "|tstats values(host) where index=*" however, performing this search (with various options for " or ' substitution) via a rest call yields nothing.

Thanks in advance for your help.  If you're powershell fluent, I've included my script chunk below, but this shouldn't be just a powershell thing... I'm pretty sure I'm just calling this search the wrong way since, again, I've verified this with a more simple search term.  And yes, the credential is valid.

 

 

Spoiler

$SplunkAPI = "https://<MySplunkServer>/services/search/jobs/export"
$Search = 'search "|tstats values(host) where index=* by index"'
$Body = @{
  search = $search
  output_mode = "json"
  earliest_time = "-24h"
  latest_time = "now"
}

Invoke-RestMethod -Method Post -Uri $SplunkAPI -Credential $Cred -Body $Body

 

Labels (1)
Tags (3)
0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

this seems to works:

curl -ku user:pass https://localhost:8089/services/search/jobs/export -d search="|tstats values(host) where index=*" -d output_mode=json

 r. Ismo

splunkreal
Motivator

Hello @isoutamo  does this | tstats command requires to have data access or just internal logs?

Thanks.

 

* If this helps, please upvote or accept solution if it solved *
0 Karma

isoutamo
SplunkTrust
SplunkTrust

It needs equal access as you have in GUI. If you need to access data then you need access to those indexes and same for internal indexes. 
The only exception is that there are some scheduled reports which have run as owner. Those should work when you have access to those reports. But if those aren’t scheduled then that’s not working.

0 Karma
Get Updates on the Splunk Community!

Buttercup Games: Further Dashboarding Techniques (Part 5)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...

Customers Increasingly Choose Splunk for Observability

For the second year in a row, Splunk was recognized as a Leader in the 2024 Gartner® Magic Quadrant™ for ...

Bridging the Gap: Splunk Helps Students Move from Classroom to Career

The Splunk Community is a powerful network of users, educators, and organizations working together to tackle ...