Getting Data In

Need seperate count for UP and DOWN Peer

jerinvarghese
Communicator

Hi All,

I have a query to display some BGP neighbour UP or DOWN.

Output looks like
nodelabel Status PEER_IP Time_CST
Device1 UP 10.253.226.10 01/08/20 02:03:53
Device2 DOWN 10.253.140.89 01/08/20 00:26:54

Query is :

index=opennms eventuei="uei.opennms.org/thresholds/bgpPeerState/XOM*" "WANRT*" "10.253*"
| rex field=eventuei "uei.opennms.org/thresholds/bgpPeerState/(?.+)"
| rex "peer: (?.*), eventseverity"
| eval Status=case(bgpPeerState=="XOM-rearm", "UP", bgpPeerState=="XOM-falling", "DOWN", 1=1, "Other")
| rename _time as Time_CST
| fieldformat Time_CST=strftime(Time_CST,"%x %X")
| dedup nodelabel sortby - Time_CST
| table nodelabel Status PEER_IP Time_CST

I need a help, want to display how many UP and DOWN peers there.

0 Karma
1 Solution

TISKAR
Builder

Hello,

First method:

index=opennms eventuei="uei.opennms.org/thresholds/bgpPeerState/XOM*" "WANRT*" "10.253*"
| rex field=eventuei "uei.opennms.org/thresholds/bgpPeerState/(?.+)"
| rex "peer: (?.*), eventseverity"
| eval Status=case(bgpPeerState=="XOM-rearm", "UP", bgpPeerState=="XOM-falling", "DOWN", 1=1, "Other")
| rename _time as Time_CST
| fieldformat Time_CST=strftime(Time_CST,"%x %X")
| dedup nodelabel sortby - Time_CST
| table nodelabel Status PEER_IP Time_CST
| eval number_Up=if(Status="UP",1,0), number_Down=if(Status="DOWN",1,0)
| stats sum(number_Up) as UP, sum(number_Down) as DOWN

Second method:

index=opennms eventuei="uei.opennms.org/thresholds/bgpPeerState/XOM*" "WANRT*" "10.253*"
    | rex field=eventuei "uei.opennms.org/thresholds/bgpPeerState/(?.+)"
    | rex "peer: (?.*), eventseverity"
    | eval Status=case(bgpPeerState=="XOM-rearm", "UP", bgpPeerState=="XOM-falling", "DOWN", 1=1, "Other")
    | rename _time as Time_CST
    | fieldformat Time_CST=strftime(Time_CST,"%x %X")
    | dedup nodelabel sortby - Time_CST
    | table nodelabel Status PEER_IP Time_CST
    | stats count(eval(Status="UP")) as UP, count(eval(Status="DOWN")) as DOWN

View solution in original post

0 Karma

to4kawa
Ultra Champion
index=opennms eventuei="uei.opennms.org/thresholds/bgpPeerState/XOM*" "WANRT*" "10.253.*"
| rex "peer: (?<PEER_IP>.*), eventseverity"
| stats count(eval(searchmatch("XOM-rearm"))) AS UP count(eval(searchmatch("XOM-falling"))) AS DOWN values(PEER_IP) AS PEER_IP by nodelabel

hi, only count up & down by nodelabel.

0 Karma

TISKAR
Builder

Hello,

First method:

index=opennms eventuei="uei.opennms.org/thresholds/bgpPeerState/XOM*" "WANRT*" "10.253*"
| rex field=eventuei "uei.opennms.org/thresholds/bgpPeerState/(?.+)"
| rex "peer: (?.*), eventseverity"
| eval Status=case(bgpPeerState=="XOM-rearm", "UP", bgpPeerState=="XOM-falling", "DOWN", 1=1, "Other")
| rename _time as Time_CST
| fieldformat Time_CST=strftime(Time_CST,"%x %X")
| dedup nodelabel sortby - Time_CST
| table nodelabel Status PEER_IP Time_CST
| eval number_Up=if(Status="UP",1,0), number_Down=if(Status="DOWN",1,0)
| stats sum(number_Up) as UP, sum(number_Down) as DOWN

Second method:

index=opennms eventuei="uei.opennms.org/thresholds/bgpPeerState/XOM*" "WANRT*" "10.253*"
    | rex field=eventuei "uei.opennms.org/thresholds/bgpPeerState/(?.+)"
    | rex "peer: (?.*), eventseverity"
    | eval Status=case(bgpPeerState=="XOM-rearm", "UP", bgpPeerState=="XOM-falling", "DOWN", 1=1, "Other")
    | rename _time as Time_CST
    | fieldformat Time_CST=strftime(Time_CST,"%x %X")
    | dedup nodelabel sortby - Time_CST
    | table nodelabel Status PEER_IP Time_CST
    | stats count(eval(Status="UP")) as UP, count(eval(Status="DOWN")) as DOWN
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@jerinvarghese
Try

YOUR_SEARCH | stats count(eval(Status="UP")) as UP_Count count(eval(Status="DOWN")) as DOWN_Count
0 Karma

jerinvarghese
Communicator

thanks for the query it helped.

0 Karma

WalshyB
Path Finder

use something like this on the end?

| stats count as Total count(eval(Status=="UP")) as "up_count" count(eval(Status=="DOWN")) as "down_count"

Or

index=opennms eventuei="uei.opennms.org/thresholds/bgpPeerState/XOM*" "WANRT*" "10.253*"
| rex field=eventuei "uei.opennms.org/thresholds/bgpPeerState/(?.+)"
| rex "peer: (?.*), eventseverity"
| eval Status=case(bgpPeerState=="XOM-rearm", "UP", bgpPeerState=="XOM-falling", "DOWN", 1=1, "Other")
| dedup nodelabel
| stats dc(PEER_IP) as Total by Status

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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...