Splunk Search

how to edit my search

sonila
Path Finder

earliest=-48h@h latest=-24h@h index="my-live-srv" sourcetype="Perfmon:sqlserver:sql_errors" counter="Errors/sec"| where instance="User Errors" | stats avg(Value) as PrevErrors | appendcols [ search earliest="-24h@h" latest="@h" index="my-live-srv" sourcetype="Perfmon:sqlserver:sql_errors" counter="Errors/sec" instance="User Errors" | stats avg(Value) as CurrErrors ]| eval PrevErrors=if(isnull(PrevErrors), 0, PrevErrors) | eval CurrErrors=if(isnull(CurrErrors), 0, CurrErrors) | eval CurrErrors=round(CurrErrors,3) |eval PrevErrors=round(PrevErrors,3) |eval CurrErrors=(CurrErrors + " Errors/sec") | eval PrevErrors=(PrevErrors + " Errors/sec") | appendcols [search earliest="-48h" latest="@h" index="my-live-srv" sourcetype="sql-trace" |where Date!="*$" | eval time_marker = if (_time < relative_time(now(), "-24h"), "yesterday", "today")| eval _time = if (time_marker=="yesterday", _time + 24*60*60, _time) ]| streamstats current=f window=1 global=f last(PrevErrors) as PrevErrors | streamstats current=f window=1 global=f last(CurrErrors) as CurrErrors|table CurrErrors,PrevErrors,time_marker,Date,Time, ID, HostName, ClientProcessID, ApplicationName, LoginName, SPID, Severity, EventClass, State, Error, DatabaseName, EventSequence

I want to save this as an alert but I want the alert to trigger only when CurrErrors >1. How can I do this ? I have tried with where condition but I dont have the expected result

0 Karma
1 Solution

somesoni2
Revered Legend

Got the issue. You're adding string text to CurrErrors making it a string and your where clause fails. Try adding this to your original search

...| where tonumber(replace(CurrErrors,"^(\d+)\s.+","\1"))>1

View solution in original post

somesoni2
Revered Legend

Got the issue. You're adding string text to CurrErrors making it a string and your where clause fails. Try adding this to your original search

...| where tonumber(replace(CurrErrors,"^(\d+)\s.+","\1"))>1

woodcock
Esteemed Legend

Now you can Accept!

0 Karma

sonila
Path Finder

I tried now but no result again

0 Karma

sonila
Path Finder

| where CurrErrors < "1"
I needed to enter this in the end of the search
I found the solution, thank you for the help that CurrErrors was a string. This helped me a lot

0 Karma

woodcock
Esteemed Legend

Be sure to click Accept to close the question.

0 Karma

sonila
Path Finder

cant accept, the answer is as a comment

0 Karma

somesoni2
Revered Legend

How about you add | where CurrErrors>1 in your search (at the end) itself and set the alert condition to where number of results is greater than 0?

0 Karma

sonila
Path Finder

nope that doesn't work. I have tried

0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...