Splunk Search

Two syslogs usually together but need to report when only one is seen

rish_raw
New Member

I have two log messages "%ROUTING-LDP-5-NSR_SYNC_START" and "%ROUTING-LDP-5-NBR_CHANGE" which usually accompany each other whenever there is a peer flapping. So "%ROUTING-LDP-5-NBR_CHANGE" is followed by "%ROUTING-LDP-5-NSR_SYNC_START" almost every time.

I am trying to find the output where a device only produces "%ROUTING-LDP-5-NSR_SYNC_START" without "%ROUTING-LDP-5-NBR_CHANGE" and I am using transaction but not been able to figure it out. 

index = test ("%ROUTING-LDP-5-NSR_SYNC_START" OR "%ROUTING-LDP-5-NBR_CHANGE")

| transaction maxspan=5m startswith="%ROUTING-LDP-5-NSR_SYNC_START" endswith="%ROUTING-LDP-5-NBR_CHANGE"

| search eventcount=1 startswith="%ROUTING-LDP-5-NSR_SYNC_START"

| stats count by host
Labels (3)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

Actually, I think transaction should work in this case.  @bowesmana is correct that your command is missing host as parameter.  But more than that, it is also missing option keeporphans.  Also the determinant is not eventcount but closed_txn.

 

| transaction host maxspan=5m keeporphans=true startswith="%ROUTING-LDP-5-NSR_SYNC_START" endswith="%ROUTING-LDP-5-NBR_CHANGE"
| where closed_txn != 1

| stats count by host

 

Apply the above to this mock dataset:

_raw_timehost
1 %ROUTING-LDP-5-NBR_CHANGE2025-01-11 19:02:45host1
2 %ROUTING-LDP-5-NBR_CHANGE2025-01-11 19:02:39host2
3 %ROUTING-LDP-5-NBR_CHANGE2025-01-11 19:02:33host3
5 %ROUTING-LDP-5-NBR_CHANGE2025-01-11 19:02:21host0
6 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 19:02:15host1
7 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 19:02:09host2
8 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 19:02:03host3
9 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 19:01:57host4
10 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 19:01:51host0
11 %ROUTING-LDP-5-NBR_CHANGE2025-01-11 19:01:45host1
13 %ROUTING-LDP-5-NBR_CHANGE2025-01-11 19:01:33host3
14 %ROUTING-LDP-5-NBR_CHANGE2025-01-11 19:01:27host4
15 %ROUTING-LDP-5-NBR_CHANGE2025-01-11 19:01:21host0
16 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 19:01:15host1
17 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 19:01:09host2
18 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 19:01:03host3
19 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 19:00:57host4
20 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 19:00:51host0
21 %ROUTING-LDP-5-NBR_CHANGE2025-01-11 19:00:45host1
22 %ROUTING-LDP-5-NBR_CHANGE2025-01-11 19:00:39host2
23 %ROUTING-LDP-5-NBR_CHANGE2025-01-11 19:00:33host3
25 %ROUTING-LDP-5-NBR_CHANGE2025-01-11 19:00:21host0
26 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 19:00:15host1
27 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 19:00:09host2
28 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 19:00:03host3
29 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 18:59:57host4
30 %ROUTING-LDP-5-NSR_SYNC_START2025-01-11 18:59:51host0

You get

hostcount
host21
host42

Here is an emulation that produces the above mock data

 

| makeresults count=30
| streamstats count as _count
| eval _time = _time - _count * 6
| eval host = "host" . _count % 5
| eval _raw = _count . " " . mvindex(mvappend("%ROUTING-LDP-5-NSR_SYNC_START", "%ROUTING-LDP-5-NBR_CHANGE"), -ceil(_count / 5) %2)
| search NOT (_count IN (4, 12, 24) %ROUTING-LDP-5-NBR_CHANGE)
``` the above emulates
index = test ("%ROUTING-LDP-5-NSR_SYNC_START" OR "%ROUTING-LDP-5-NBR_CHANGE")
```

 

Play with it and compare with real data.

0 Karma

bowesmana
SplunkTrust
SplunkTrust

transaction is not a safe command to use if you have large data volumes, as it will silently ignore data when it hits limits. You are using a long span of 5m, so it will potentially have to hold lots of data in memory.

Secondly, if you do use transaction and are wanting to group by host, you need to supply host as a field in the transaction command.

With all search debugging tasks, first find a small dataset that contains the condition you are trying to catch and then just use the transaction command to see what transactions you get - if you can post some comments or anonymised data that demonstrates what you are having trouble with, that would help.

Note that it is generally possible to use stats as a replacement for transaction, but in this case, may not be applicable.

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

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...