StateCount for sending an OK alert


I want to write a tick script for sending critical and okay alerts when a particular lambda is hit 5 times. For example, if cpu>90 for 5 counts, then send a critical alert. Once the critical alert is sent, OK alert would be sent only when the cpu<90 for 5 counts.

How do i incorporate this.?

I have the following tick script to send critical alert, when the lambda is hit 5 times-

// Select just the cpu measurement from our example database.
|stateCount(lambda: “value” >90)
// Whenever we get an alert write it to a file.

How do I add the part to send OK.?