Splunk Search

Multiple "latest' statements on one table

tmarlette
Motivator

I am attempting to get the latest status of a port scan for 5 different ports per host into a table.

I am trying to format it as follows:

time,host,hostname,port1,port2,port3,port4,port5

Currently, my search string looks like this:
(sourcetype=port_scan dst_port=443 | stats latest(dst_port_state) AS "port 443 state") OR (sourcetype=port_scan dst_port=80 | stats latest(dst_port_state) AS "port 80 state") and so on, but I am getting errors when running this search.

Any assistance would be greatly appreciated!

Tags (3)
0 Karma
1 Solution

yannK
Splunk Employee
Splunk Employee

once you added your first "|" you cannot add further conditions. the parenthesis can only be used to group conditions not part of the search.
What you are trying to do is building subsearches ( using square brackets)

But in your case, it seems that the best solution is to use grouping per stats.

sourcetype=port_scan (dst_port=443 OR dst_port=80 ) | stats last(dst_port_state) AS "state" by dst_port

and remember that "last" means the oldest events. and "first" means the most recent events.
see http://answers.splunk.com/answers/42570/why-stats-last-and-first-are-inverted
To avoid confusion, you may want to use "earliest".
see http://docs.splunk.com/Documentation/Splunk/6.0.1/SearchReference/CommonStatsFunctions

View solution in original post

0 Karma

yannK
Splunk Employee
Splunk Employee

once you added your first "|" you cannot add further conditions. the parenthesis can only be used to group conditions not part of the search.
What you are trying to do is building subsearches ( using square brackets)

But in your case, it seems that the best solution is to use grouping per stats.

sourcetype=port_scan (dst_port=443 OR dst_port=80 ) | stats last(dst_port_state) AS "state" by dst_port

and remember that "last" means the oldest events. and "first" means the most recent events.
see http://answers.splunk.com/answers/42570/why-stats-last-and-first-are-inverted
To avoid confusion, you may want to use "earliest".
see http://docs.splunk.com/Documentation/Splunk/6.0.1/SearchReference/CommonStatsFunctions

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...