Ejemplo n.º 1
0
    def notify_zaqar(self, action, message, headers=None):
        queue_info = urlparse.parse_qs(action.query)
        try:
            # NOTE(flwang): Try to get build a pre-signed client if user has
            # provide enough information about that. Otherwise, go to build
            # a client with service account and queue name for this alarm.
            conf, queue_name = self._get_presigned_client_conf(queue_info)
            if conf is not None:
                zaqar_client = self.get_zaqar_client(conf)

            if conf is None or queue_name is None or zaqar_client is None:
                zaqar_client = self.client
                # queue_name is a combination of <alarm-id>-<topic>
                queue_name = "%s-%s" % (message['body']['alarm_id'],
                                        queue_info.get('topic')[-1])

            # create a queue in zaqar
            queue = zaqar_client.queue(queue_name)

            subscriber_list = queue_info.get('subscriber', [])
            ttl = int(queue_info.get('ttl', ['3600'])[-1])
            for subscriber in subscriber_list:
                # add subscriber to the zaqar queue
                subscription_data = dict(subscriber=subscriber, ttl=ttl)
                zaqar_client.subscription(queue_name, **subscription_data)
            # post the message to the queue
            queue.post(message)
        except IndexError:
            LOG.error("Required query option missing in action %s", action)
        except Exception:
            LOG.error(
                "Unknown error occurred; Failed to post message to"
                " Zaqar queue",
                exc_info=True)
Ejemplo n.º 2
0
    def notify_zaqar(self, action, message, headers=None):
        queue_info = urlparse.parse_qs(action.query)
        try:
            # NOTE(flwang): Try to get build a pre-signed client if user has
            # provide enough information about that. Otherwise, go to build
            # a client with service account and queue name for this alarm.
            conf, queue_name = self._get_presigned_client_conf(queue_info)
            if conf is not None:
                zaqar_client = self.get_zaqar_client(conf)

            if conf is None or queue_name is None or zaqar_client is None:
                zaqar_client = self.client
                # queue_name is a combination of <alarm-id>-<topic>
                queue_name = "%s-%s" % (message['body']['alarm_id'],
                                        queue_info.get('topic')[-1])

            # create a queue in zaqar
            queue = zaqar_client.queue(queue_name)

            subscriber_list = queue_info.get('subscriber', [])
            ttl = int(queue_info.get('ttl', ['3600'])[-1])
            for subscriber in subscriber_list:
                # add subscriber to the zaqar queue
                subscription_data = dict(subscriber=subscriber, ttl=ttl)
                zaqar_client.subscription(queue_name, **subscription_data)
            # post the message to the queue
            queue.post(message)
        except IndexError:
            LOG.error(
                _LE("Required query option missing in action %s"), action)
        except Exception:
            LOG.error(
                _LE("Unknown error occurred; Failed to post message to"
                    " Zaqar queue"),
                exc_info=True)