Splunk Search

Help with Search string count

D01033778
New Member

I am trying to extract a string, count how many times it appears and group it by host.

RAW LOG:

[2013-01-31T03:55:06.739-06:00] [soa_server2] [ERROR] [] [oracle.soa.bpel.engine.dispatch] [tid: orabpel.invoke.pool-4.thread-16] [userId: ] [ecid: b5e97102d2ab8130:-37493125:13c69c08931:-8000-00000000003946d4,0] [APP: soa-infra] failed to handle message[[ORABPEL-09705 Could not initialize variable.An error occurs while initializing BPEL variable inputVariable; the schema processor cannot find the element


Search Expression:

host="stiint2app2" OR host="stiint2app1" | chart count(ORABPEL-05002) AS ERROR:ORABPEL-05002,
count(ORABPEL-09705) AS ERROR:ORABPEL-09705,
count(ORABPEL-35009) AS ERROR:ORABPEL-35009,
count(ORABPEL-9732) AS ERROR:ORABPEL-9732 by host


Results:

host ERROR:ORABPEL-05002 ERROR:ORABPEL-09705 ERROR:ORABPEL-35009 ERROR:ORABPEL-9732



1 stiint2app1 0 0 0 0

2 stiint2app2 0 0 0 0

Currently I am not getting the exact results that I am looking for. Example I have actual count of 37 occurences for ORABPEL-09705, today but my results show 0.

Tags (1)
0 Karma
1 Solution

Ayn
Legend

Your syntax seems to a bit off. By the looks of it, it seems that you're assuming that count(blah) will match the raw log for "blah" and return the count of events where a match was found. This is not the case. count(blah) will count how many events the FIELD "blah" exists in. If you want to match something against the raw event, you'll want to do count(eval(searchmatch("blah"))).

So, with the query rewritten with those changes, it'll look something like

host="stiint2app2" OR host="stiint2app1" | chart count(eval(searchmatch("ORABPEL-05002"))) AS ERROR:ORABPEL-05002, count(eval(searchmatch("ORABPEL-09705"))) AS ERROR:ORABPEL-09705, count(eval(searchmatch("ORABPEL-35009"))) AS ERROR:ORABPEL-35009, count(eval(searchmatch("ORABPEL-9732"))) AS ERROR:ORABPEL-9732 by host

Personally I would go for a somewhat different approach - create a field extraction that matches the individual error ID's after the "ORABPEL-" string, so a field would be created (calling it ORABPEL seems appropriate) holding the various error ID's. Having done that, just doing

host="stiint2app2" OR host="stiint2app1" | chart count by ORABPEL,host

would suffice.

View solution in original post

stefandagerman
Path Finder

Are the arguments to the count() function field names or strings?

0 Karma

Ayn
Legend

Your syntax seems to a bit off. By the looks of it, it seems that you're assuming that count(blah) will match the raw log for "blah" and return the count of events where a match was found. This is not the case. count(blah) will count how many events the FIELD "blah" exists in. If you want to match something against the raw event, you'll want to do count(eval(searchmatch("blah"))).

So, with the query rewritten with those changes, it'll look something like

host="stiint2app2" OR host="stiint2app1" | chart count(eval(searchmatch("ORABPEL-05002"))) AS ERROR:ORABPEL-05002, count(eval(searchmatch("ORABPEL-09705"))) AS ERROR:ORABPEL-09705, count(eval(searchmatch("ORABPEL-35009"))) AS ERROR:ORABPEL-35009, count(eval(searchmatch("ORABPEL-9732"))) AS ERROR:ORABPEL-9732 by host

Personally I would go for a somewhat different approach - create a field extraction that matches the individual error ID's after the "ORABPEL-" string, so a field would be created (calling it ORABPEL seems appropriate) holding the various error ID's. Having done that, just doing

host="stiint2app2" OR host="stiint2app1" | chart count by ORABPEL,host

would suffice.

D01033778
New Member

Thanks for much. The first example works like a charm. I will look into creating the field extraction as well.

Thanks Again.

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 ...