Filtering event api calls

Trying to use filtering in compiled code ( rather then using curl, I have no problem pulling events in a json array and converting it to a dataset, here’s my problem, if there are 175000 events in there I only want to get the ones failing, right now I pull them all

So I have tried adding a filter to the url based on what i see in the doc’s but it appears to ignore it and pulls all events…

Any ideas or suggestions would be quite welcome

    filter = HttpUtility.UrlEncode("fieldselector=event.check.status == 2")
    Dim url = baseurl & ":8080/api/core/v2/events?limit=2500&" & filter

Thank you

earth to sensu, come in please over, krsshhht! count = 1

calling url :

our returned response headers :

Transfer-Encoding: chunked
Content-Type: application/json
Date: Fri, 30 Jul 2021 15:17:50 GMT

Just for clarity when you add the filter using an api endpoint call with curl, does it work as you expect?

Maybe the problem is you need to explicitly use "2" in your filter string to indicate that the value is the string interpreation of the number 2.

For example this works for me with curl:

curl -H "Authorization: Key $SENSU_API_KEY" ' == "2"'
1 Like

Suspecting your right Jef, I jumped into powershell to see if I could get better results and have succeeded with the following

$blaa = ‘fieldSelector=event.check.status == “2”’
#$blaa = [System.Web.HTTPUtility]::UrlEncode(‘fieldselector=event.check.status == “2”’)

$URI = $baseurl + ":8080/api/core/v2/events?limit=500&$blaa"
write-host $uri

try {

$it = Invoke-RestMethod -Uri $uri -headers $headers 

} catch {
# Dig into the exception to get the Response details.
# Note that value__ is not a typo.
write-host “”
Write-Host “StatusCode:” $.Exception.Response.StatusCode.value__
Write-Host “StatusDescription:” $
write-host event count: $it.Count
write-host done

PS C:\repo\scripts\sensu> c:\repo\scripts\sensu\keepalive.ps1
https://api.lab.sensu.xxxxx:8080/api/core/v2/events?limit=500&fieldSelector=event.check.status == “2”
event count: 7

Thank you so far, back into visual studio now to investigate how to craft that string


I did manage to work around this by hard coding the filter into my URL rather then string addition, thanks for your help on this, still struggling with the in and matches filter will let ya know how I make out