code: def correlate_alert(self, alert, history):
          
          query = {
              'environment': alert.environment,
              'resource': alert.resource,
              '$or': [
                  {
                      'event': alert.event,
                      'severity': {'$ne': alert.severity}
                  },
                  {
                      'event': {'$ne': alert.event},
                      'correlate': alert.event
                  }],
              'customer': alert.customer
          }
  
          update = {
              '$set': {
                  'event': alert.event,
                  'severity': alert.severity,
                  'status': alert.status,
                  'service': alert.service,
                  'value': alert.value,
                  'text': alert.text,
                  'createTime': alert.create_time,
                  'timeout': alert.timeout,
                  'rawData': alert.raw_data,
                  'duplicateCount': alert.duplicate_count,
                  'repeat': alert.repeat,
                  'previousSeverity': alert.previous_severity,
                  'trendIndication': alert.trend_indication,
                  'receiveTime': alert.receive_time,
                  'lastReceiveId': alert.last_receive_id,
                  'lastReceiveTime': alert.last_receive_time
              },
              '$addToSet': {'tags': {'$each': alert.tags}},
              '$push': {
                  'history': {
                      '$each': [h.serialize for h in history],
                      '$slice': -abs(current_app.config['HISTORY_LIMIT'])
                  }
              }
          }
  
          # only update those attributes that are specifically defined
          attributes = {'attributes.' + k: v for k, v in alert.attributes.items()}
          update['$set'].update(attributes)
  
          if alert.update_time:
              update['$set']['updateTime'] = alert.update_time
  
          return self.get_db().alerts.find_one_and_update(
              query,
              update=update,
              return_document=ReturnDocument.AFTER
          )
docs: Update alert key attributes, reset duplicate count and set repeat=False, keep track of last
          receive id and time, appending all to history. Append to history again if status changes.