# Filter on previous event.check.status?

**URL:** <https://discourse.sensu.io/t/filter-on-previous-event-check-status/1620>\
**Category:** Sensu Go\
**Created:** [February 1, 2020, 8:14pm UTC](https://discourse.sensu.io/t/filter-on-previous-event-check-status/1620 "2020-02-01T20:14:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![billm](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@billm](https://discourse.sensu.io/u/billm)\
**Post date:** [February 1, 2020, 8:14pm UTC](https://discourse.sensu.io/t/filter-on-previous-event-check-status/1620/1 "2020-02-01T20:14:06Z")

</div>

Hi Guys-

Is there a way to compare the previous check status in a filter?

I’d like to filter one handler if the event.check.status changes from 1 to 0 and another if it changes from 2 to 0. I don’t see any way to distinguish between the two cases though.

Thx

---

<div class="post-metadata">

**Author:** ![palourde](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/palourde/32/60_2.png) [@palourde](https://discourse.sensu.io/u/palourde)\
**Post date:** [February 7, 2020, 2:20pm UTC](https://discourse.sensu.io/t/filter-on-previous-event-check-status/1620/2 "2020-02-07T14:20:30Z")

</div>

Hi @billm

The event history is accessible to filters using the `event.check.history` attribute, as documented [here](https://docs.sensu.io/sensu-go/latest/reference/filters/#check-attributes-available-to-filters), which will return an array of hashes, each representing a previous status as documented [here](https://docs.sensu.io/sensu-go/latest/reference/events/#history-attributes).

Cheers

---

<div class="post-metadata">

**Author:** ![billm](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@billm](https://discourse.sensu.io/u/billm)\
**Post date:** [February 7, 2020, 5:24pm UTC](https://discourse.sensu.io/t/filter-on-previous-event-check-status/1620/3 "2020-02-07T17:24:38Z")

</div>

so like this?

event.check.history[1].status == x

---

<div class="post-metadata">

**Author:** ![mylesw42](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/mylesw42/32/253_2.png) [@mylesw42](https://discourse.sensu.io/u/mylesw42)\
**Post date:** [February 17, 2020, 6:12pm UTC](https://discourse.sensu.io/t/filter-on-previous-event-check-status/1620/4 "2020-02-17T18:12:24Z")

</div>

Hey, not sure if you figured this out, but the Array index will start at [0], and I believe that first element will be the oldest check execution. Given its Javascript expression compatible, you’d want to grab the second last element in the array using the “length” method on check.history because the last element is also the most recent.

Maybe try the following as your filter expression:

```auto
event.check.history[event.check.history.length - 2].status == x

```

---

<div class="post-metadata">

**Author:** ![billm](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@billm](https://discourse.sensu.io/u/billm)\
**Post date:** [February 20, 2020, 8:14pm UTC](https://discourse.sensu.io/t/filter-on-previous-event-check-status/1620/5 "2020-02-20T20:14:09Z")

</div>

Thanks for this. I was unsure which “direction” the array went in terms of oldest/newest.
