StateCount for sending an OK alert

Hi

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-

stream
// Select just the cpu measurement from our example database.
|from()
.measurement(‘cpu0’)
|stateCount(lambda: “value” >90)
|alert()
.crit(lambda:“state_count”>=5)
.stateChangesOnly()
// Whenever we get an alert write it to a file.
.log(’/var/log/kapacitor/crit_count_try.log’)

How do I add the part to send OK.?

Arushi