def handle_status_result(self, cluster):
    # last_status store cluster_name->(status, status_times)
    (cluster_status, status_times) = self.last_status.setdefault(str(cluster), (Status.OK, 0))
    need_send_alert = False

    if cluster.last_status != cluster_status:
      self.last_status[str(cluster)] = (cluster.last_status, 1)
      if cluster.last_status == Status.OK and status_times >= ERROR_TIMES_FOR_ALERT:
        # send alert when cluster changed to from PROBLEM(alerted) to OK
        need_send_alert = True
    else:
      self.last_status[str(cluster)] = (cluster.last_status, status_times+1)
      # send alert when cluster in PROBLEM stutus reached ERROR_TIMES_FOR_ALERT times
      if cluster.last_status != Status.OK and status_times + 1 == ERROR_TIMES_FOR_ALERT:
        need_send_alert = True

    if need_send_alert:
      self.alert_msg += '[%s]Cluster[%s]\n' \
          % ('OK' if cluster.last_status == Status.OK else 'PROBLEM',
             cluster)
      for job in cluster.jobs.itervalues():
        if job.last_status != Status.OK:
          self.alert_msg += 'Job[%s] not healthy: %s\n' % (job.name, job.last_message)
      self.alert_msg += '******\n'
dataset/ETHPy150Open XiaoMi/minos/owl/alert/management/commands/alert.py/StatusChecker.handle_status_result/original