Reorganize alerting logic for testability.  Create alerting tests.