Splunk Search

How to use eval to find percentage and combine with a stats search to set up an alert?

akelly4
Path Finder

I'm trying to setup an alert where if x/y <=x% then it sends an alert out.

To do this i'm trying to pull numbers from two separate searches to divide them to get the percentage. But i'm having trouble figuring out what commands to use to do this.

1st search - This is the total number of machine that exist
index=totalmachines sourcetype=Machines earliest=-48h@d |stats sum(linecount) AS Number_Of__Machines

2nd search - This is the limit of machines we can reach. I want to use the EVAL command to be able to see when I come close to this limit.
index=licenselimit sourcetype=LicenseLimitforMachines earliest=-48h@d | rename LIC_SOFT_LIMIT AS License_Limit | table License_Limit

I have the numbers I just need to figure out how to combine those searches and run the eval command to get a percentage.

0 Karma

somesoni2
Revered Legend

If you're just getting one row from licenselimit search as well (you're getting one row from totalmachines search) then try this

index=licenselimit sourcetype=LicenseLimitforMachines earliest=-48h@d | rename LIC_SOFT_LIMIT AS License_Limit | table License_Limit | appendcols [search index=totalmachines sourcetype=Machines earliest=-48h@d |stats sum(linecount) AS Number_Of__Machines] | eval percentage=(Number_Of_Encrypted_Machines/LIC_SOFT_LIMIT)*100
0 Karma

akelly4
Path Finder

I tried this but it still returns 2 rows with each of those fields. From what I can tell it's not doing that calculation.

0 Karma

akelly4
Path Finder

I believe i'm a bit closer here

index=licenselimit earliest=-48h@d | where LIC_SOFT_LIMIT != "" | table LIC_SOFT_LIMIT | append [search index=licenselimit sourcetype=MachineTotals earliest=-48h@d |stats sum(linecount) AS Number_Of_Encrypted_Machines] | eval percentage=(Number_Of_Encrypted_Machines/LIC_SOFT_LIMIT)*100

When I run this command it just shows the two fields Number_Of_Encrypted_Machines and LIC_SOFT_LIMIT in a table. Can anyone else how I can make my eval work so I can divide Number Of Encrypted Machines by LIC_SFOT_LIMIT?

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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...