How to check the result of a script with monit?

Program status testing does exactly what you want. Use it to check the status command of a script.

For example:

check program hwtest with path /usr/local/bin/hwtest.sh
with timeout 500 seconds
if status = 1 then alert
if status = 3 for 5 cycles then exec "/usr/local/bin/emergency.sh"