Security

Query formatting error.

jerinvarghese
Communicator

Need help in filtering words from the RAW output.
Below is a sample message that am getting from my index.

2020-01-24T18:48:03.593Z USDALPOD03-DCNPL2023 <29> ifIndex 515, ifAdminStatus up(1), ifOperStatus up(1), ifName et-0/0/50
2020-01-24T18:48:01.793Z USDALPOD03-DCNPL2023 <28> ifIndex 515, ifAdminStatus up(1), ifOperStatus down(2), ifName et-0/0/50

Below is the code that am using.

index=nw_syslog  "et-*" "ifoper*"
| rex field=_raw "ifName (?<Interface>.*)"
| rex field=_raw "ifOperStatus (?<Status>.*)"
| table hostname, Status, Interface

Below is the output that am getting.

hostname    Status  Interface
USDALPOD03-DCNPL2023    up(1), ifName et-0/0/50 et-0/0/50
USDALPOD03-DCNPL2023    down(2), ifName et-0/0/50   et-0/0/50

Expected output

hostname    Status  Interface    Time
USDALPOD03-DCNPL2023    up  et-0/0/50  XX:XX:XX
USDALPOD03-DCNPL2023    down    et-0/0/50  XX:XX:XX

While am giving | rex field=_raw "ifOperStatus (?.*)(" this qurry, its giving me error. please help in formatting.

0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @jerinvarghese,
at first use this regex

ifIndex\s+(?<ifIndex>[^,]*),\sifAdminStatus\s+(?<ifAdminStatus>[^,]*),\s+ifOperStatus\s+(?<Status>[^\(]*)\(\d+\),\s+ifName\s+(?<Interface>.*)

that you can test at https://regex101.com/r/KRBboF/2

So you can modify your output having a search like this:

 index=nw_syslog  "et-*" "ifoper*"
 | rex "ifIndex\s+(?<ifIndex>[^,]*),\sifAdminStatus\s+(?<ifAdminStatus>[^,]*),\s+ifOperStatus\s+(?<Status>[^\(]*)\(\d+\),\s+ifName\s+(?<Interface>.*)"
| table hostname, Status, Interface

Ciao.
Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @jerinvarghese,
at first use this regex

ifIndex\s+(?<ifIndex>[^,]*),\sifAdminStatus\s+(?<ifAdminStatus>[^,]*),\s+ifOperStatus\s+(?<Status>[^\(]*)\(\d+\),\s+ifName\s+(?<Interface>.*)

that you can test at https://regex101.com/r/KRBboF/2

So you can modify your output having a search like this:

 index=nw_syslog  "et-*" "ifoper*"
 | rex "ifIndex\s+(?<ifIndex>[^,]*),\sifAdminStatus\s+(?<ifAdminStatus>[^,]*),\s+ifOperStatus\s+(?<Status>[^\(]*)\(\d+\),\s+ifName\s+(?<Interface>.*)"
| table hostname, Status, Interface

Ciao.
Giuseppe

0 Karma

jerinvarghese
Communicator

Thanks so much for the regex command.

I edited little more in that

index=nw_syslog  "et-*" "ifoper*"
  | rex "ifIndex\s+(?<ifIndex>[^,]*),\sifAdminStatus\s+(?<ifAdminStatus>[^,]*),\s+ifOperStatus\s+(?<Status>[^\(]*)\(\d+\),\s+ifName\s+(?<Interface>.*)"
  | stats  latest(_time) as Time_CST count by hostname, Status, Interface
  | sort - Time_CST
 | fieldformat Time_CST=strftime(Time_CST,"%x %X")
 | table hostname, Status, Interface, Time_CST, count

Output came as

hostname    Status  Interface   Time_CST    count
USDALPOD03-DCNPL2023    up  et-0/0/50   01/24/20 12:48:03   2
USDALPOD03-DCNPL2023    down    et-0/0/50   01/24/20 12:48:01   1
USDALPOD03-DCNPL2023    up  et-0/0/48   01/24/20 12:33:27   2
USDALPOD03-DCNPL2023    down    et-0/0/48   01/24/20 12:33:26   1
USDALPOD03-DCNPL2021    down    et-0/0/48   01/24/20 10:26:53   1
USDALPOD03-DCNPL2021    up  et-0/0/48   01/24/20 10:26:52   1

Is it possible to dedup the Interface w.r.t to the hostname and display the latest one Status based.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @jerinvarghese,
if you want to list all the Statuses, you can modify your stats command in

| stats  latest(_time) as Time_CST values(Status) AS Status count by hostname Interface

if instead you want only the last one:

| stats  latest(_time) as Time_CST max(Status) AS Status count by hostname Interface

Ciao.
Giuseppe

0 Karma

to4kawa
Ultra Champion
your search
| dedup hostname,  Interface
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Where Innovation Takes Flight: The Splunk4Aviation Flight Sim Lands at .conf26

If you hear someone at .conf26 shouting "gear down, GEAR DOWN" across the show floor, you have found us.  The ...

Turn Cisco Telemetry Into Action with Cisco Data Fabric, powered by the Splunk ...

The surge in machine data is already hitting enterprise budgets, and the agentic era will only intensify it. ...

Persistent Queue at TcpOut — One of Splunk's Most Practical Features

Splunk introduced persistent queueing at the tcpout layer as one of the most practical resilience features in ...