def send_alert(self, alert_key, statusobj): """ An alert_key is a quasi-unique key. A listener to the alert can determine whether to pass the alert on to a higher level based upon the frequency of this alert. :param alert_key: :param context: :return: """ if not isinstance(statusobj, Status): raise ValueError('statusobj must be a Status object.') agent_class = self._owner.__class__.__name__ fq_identity = get_fq_identity(self._core().identity) # RMQ and other message buses can't handle '.' because it's used as the separator. This # causes us to change the alert topic's agent_identity to have '_' rather than '.'. topic = topics.ALERTS(agent_class=agent_class, agent_identity=fq_identity.replace('.', '_')) headers = dict(alert_key=alert_key) self._owner.vip.pubsub.publish( "pubsub", topic=topic.format(), headers=headers, message=statusobj.as_json()).get(timeout=10)
def send_alert(self, alert_key, statusobj): """ An alert_key is a quasi-unique key. A listener to the alert can determine whether to pass the alert on to a higher level based upon the frequency of this alert. :param alert_key: :param context: :return: """ if not isinstance(statusobj, Status): raise ValueError('statusobj must be a Status object.') agent_class = self._owner.__class__.__name__ agent_uuid = os.environ.get('AGENT_UUID', '') topic = topics.ALERTS(agent_class=agent_class, agent_uuid=agent_uuid) headers = dict(alert_key=alert_key) self._owner.vip.pubsub.publish("pubsub", topic=topic.format(), headers=headers, message=statusobj.as_json())