Processes this event.

def ProcessMessages(self, msgs=None, token=None):
    """Processes this event."""
    nanny_msg = ""

    for crash_details in msgs:
      client_urn = crash_details.client_id
      client_id = client_urn.Basename()

      # The session id of the flow that crashed.
      session_id = crash_details.session_id

      # Log.
      logging.info("Client crash reported, client %s.", client_urn)

      # Export.
      stats_collector_instance.Get().IncrementCounter("grr_client_crashes")

      # Write crash data.
      if data_store.RelationalDBEnabled():
        client = data_store.REL_DB.ReadClientSnapshot(client_id)
        if client:
          crash_details.client_info = client.startup_info.client_info
          hostname = client.knowledge_base.fqdn
        else:
          hostname = ""

      if data_store.AFF4Enabled():
        client = aff4.FACTORY.Open(client_urn, token=token)
        client_info = client.Get(client.Schema.CLIENT_INFO)
        hostname = client.Get(client.Schema.FQDN)
        if client_info:
          crash_details.client_info = client_info

      crash_details.crash_type = "Client Crash"

      if nanny_msg:
        termination_msg = "Client crashed, " + nanny_msg
      else:
        termination_msg = "Client crashed."

      # Terminate the flow.
      if data_store.RelationalDBEnabled():
        flow_id = session_id.Basename()
        flow_base.TerminateFlow(
            client_id,
            flow_id,
            reason=termination_msg,
            flow_state=rdf_flow_objects.Flow.FlowState.CRASHED)
      else:
        flow.GRRFlow.TerminateAFF4Flow(
            session_id, reason=termination_msg, token=token)

      WriteAllCrashDetails(
          client_id, crash_details, flow_session_id=session_id, token=token)

      # Also send email.
      to_send = []

      try:
        hunt_session_id = ExtractHuntId(session_id)
        if hunt_session_id and hunt_session_id != session_id:

          # TODO(amoser): Enable this for the relational db once we have hunt
          # metadata.
          if data_store.AFF4Enabled():
            hunt_obj = aff4.FACTORY.Open(
                hunt_session_id, aff4_type=implementation.GRRHunt, token=token)
            email = hunt_obj.runner_args.crash_alert_email

          if email:
            to_send.append(email)
      except aff4.InstantiationError:
        logging.error("Failed to open hunt %s.", hunt_session_id)

      email = config.CONFIG["Monitoring.alert_email"]
      if email:
        to_send.append(email)

      for email_address in to_send:
        if crash_details.nanny_status:
          nanny_msg = "Nanny status: %s" % crash_details.nanny_status

        body = self.__class__.mail_template.render(
            client_id=client_id,
            admin_ui=config.CONFIG["AdminUI.url"],
            hostname=utils.SmartUnicode(hostname),
            url="/clients/%s" % client_id,
            nanny_msg=utils.SmartUnicode(nanny_msg),
            signature=config.CONFIG["Email.signature"])

        email_alerts.EMAIL_ALERTER.SendEmail(
            email_address,
            "GRR server",
            "Client %s reported a crash." % client_id,
            utils.SmartStr(body),
            is_html=True)