Splunk Search

How to do show only count result that is not equal base on two fields

hitman88
Loves-to-Learn Lots
Here is my query for checking BGP routing that goes UP and DOWN. (I only want to see when the amount of UP and DOWN are not equal for the same Neighbor on a router)
In my case i want to show only line #5 and #6.
How do i do that ? 
 
My query:
...... | rex field=_raw "(?<BGP_NEIGHBOR>neighbor\s\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"  |  rex field=_raw "(?<BGP_STATUS>(Up|Down))"  |  stats count by HOST, BGP_NEIGHBOR, BGP_STATUS
 
 
#     HOST               BGP_NEIGHBOR       BGP_STATUS       count
 
1     Router A          neighbor 10.1.1.1          Down                    1
2     Router A          neighbor 10.1.1.1          Up                          1
 
3     Router B          neighbor 10.2.2.2          Down                   1
4     Router B          neighbor 10.2.2.2          Up                         1
 
5     Router C          neighbor 10.3.3.3         Down                    2
6     Router C          neighbor 10.3.3.3         Up                          1
 
7     Router D          neighbor 10.4.4.4         Down                   2
8     Router D          neighbor 10.4.4.4         Up                         2
 
 
Labels (1)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

Something like this?

 

| eventstats range(count) as varies by HOST
| where varies > 0

 

Here is an emulation you can play with and compare with real data. (I know that # is not a real field.  It doesn't affect calculation here.)

 

| makeresults format=csv data="#,HOST,BGP_NEIGHBOR,BGP_STATUS,count
1,Router A,neighbor 10.1.1.1,Down,1
2,Router A,neighbor 10.1.1.1,Up,1
3,Router B,neighbor 10.2.2.2,Down,1
4,Router B,neighbor 10.2.2.2,Up,1
5,Router C,neighbor 10.3.3.3,Down,2
6,Router C,neighbor 10.3.3.3,Up,1
7,Router D,neighbor 10.4.4.4,Down,2
8,Router D,neighbor 10.4.4.4,Up,2"
``` the above emulates
.....
| rex field=_raw "(?<BGP_NEIGHBOR>neighbor\s\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
| rex field=_raw "(?<BGP_STATUS>(Up|Down))"
| stats count by HOST, BGP_NEIGHBOR, BGP_STATUS
```

 

Combining this with the above search gives

#BGP_NEIGHBORBGP_STATUSHOSTcountvaries
5neighbor 10.3.3.3DownRouter C21
6neighbor 10.3.3.3UpRouter C11
Tags (1)
0 Karma

hitman88
Loves-to-Learn Lots

Thank you  yuanliu 
It is working   😊

0 Karma
Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...