Splunk Dev

Splunk REST API | Validate SPL

kirchoff
Engager

Hi all,

I am working on a project that take SPL input from user. So, i need to be sure that SPL has a correct syntax without making a search with the SPL. I could not see but is there a validator for SPLs?

Labels (1)
Tags (1)
0 Karma
1 Solution

mcmaster
Communicator

You can use /services/search/parser to validate SPL:

 

smcmaster@splunk ~ % curl -s -k -u admin:***** -d output_mode=json -d q="search index=foo sourcetype=bar" https://localhost:8089/services/search/parser | jq .
{
  "remoteSearch": "litsearch (index=foo sourcetype=bar) | fields  keepcolorder=t \"_bkt\" \"_cd\" \"_si\" \"host\" \"index\" \"linecount\" \"source\" \"sourcetype\" \"splunk_server\"",
  "normalizedSearch": "litsearch (index=foo sourcetype=bar) | fields keepcolorder=t \"_bkt\" \"_cd\" \"_si\" \"host\" \"index\" \"linecount\" \"source\" \"sourcetype\" \"splunk_server\"",
  "remoteTimeOrdered": true,
  "eventsSearch": "search index=foo sourcetype=bar",
  "eventsTimeOrdered": true,
  "eventsStreaming": true,
  "reportsSearch": "",
  "isStreamingSearch": true,
  "canSummarize": false,
  "commands": [
    {
      "command": "search",
      "rawargs": "index=foo sourcetype=bar",
      "pipeline": "streaming",
      "args": {
        "search": [
          "(index=foo sourcetype=bar)"
        ]
      },
      "isGenerating": true,
      "streamType": "SP_STREAM"
    }
  ]
}
smcmaster@splunk ~ % curl -s -k -u admin:***** -d output_mode=json -d q="search index=foo sourcetype=bar | bizzbuzz" https://localhost:8089/services/search/parser | jq .
{
  "messages": [
    {
      "type": "FATAL",
      "text": "Unknown search command 'bizzbuzz'."
    }
  ]
}
smcmaster@splunk ~ %

 

Successful parsing (such as the first example) results in 200, failure (such as the second example) results in a 400.

View solution in original post

mcmaster
Communicator

You can use /services/search/parser to validate SPL:

 

smcmaster@splunk ~ % curl -s -k -u admin:***** -d output_mode=json -d q="search index=foo sourcetype=bar" https://localhost:8089/services/search/parser | jq .
{
  "remoteSearch": "litsearch (index=foo sourcetype=bar) | fields  keepcolorder=t \"_bkt\" \"_cd\" \"_si\" \"host\" \"index\" \"linecount\" \"source\" \"sourcetype\" \"splunk_server\"",
  "normalizedSearch": "litsearch (index=foo sourcetype=bar) | fields keepcolorder=t \"_bkt\" \"_cd\" \"_si\" \"host\" \"index\" \"linecount\" \"source\" \"sourcetype\" \"splunk_server\"",
  "remoteTimeOrdered": true,
  "eventsSearch": "search index=foo sourcetype=bar",
  "eventsTimeOrdered": true,
  "eventsStreaming": true,
  "reportsSearch": "",
  "isStreamingSearch": true,
  "canSummarize": false,
  "commands": [
    {
      "command": "search",
      "rawargs": "index=foo sourcetype=bar",
      "pipeline": "streaming",
      "args": {
        "search": [
          "(index=foo sourcetype=bar)"
        ]
      },
      "isGenerating": true,
      "streamType": "SP_STREAM"
    }
  ]
}
smcmaster@splunk ~ % curl -s -k -u admin:***** -d output_mode=json -d q="search index=foo sourcetype=bar | bizzbuzz" https://localhost:8089/services/search/parser | jq .
{
  "messages": [
    {
      "type": "FATAL",
      "text": "Unknown search command 'bizzbuzz'."
    }
  ]
}
smcmaster@splunk ~ %

 

Successful parsing (such as the first example) results in 200, failure (such as the second example) results in a 400.

Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...