From ff9b4bb938dcc7cdd8c7fa4d2fe716f4c33a9ca6 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 1 Jul 2016 17:06:09 +0200 Subject: [PATCH] notify: add a CLI tool to manually send notifications Change-Id: I01ebd8402e322c5c27dc2fc4c61fb5beb2dddae8 --- oslo_messaging/notify/notifier.py | 45 +++++++++++++++++++++++++++++++ setup.cfg | 1 + 2 files changed, 46 insertions(+) diff --git a/oslo_messaging/notify/notifier.py b/oslo_messaging/notify/notifier.py index 2d58a9adf..af42569d8 100644 --- a/oslo_messaging/notify/notifier.py +++ b/oslo_messaging/notify/notifier.py @@ -16,6 +16,7 @@ # under the License. import abc +import argparse import logging import uuid @@ -23,6 +24,7 @@ from debtcollector import renames from oslo_config import cfg from oslo_utils import timeutils import six +from stevedore import extension from stevedore import named from oslo_messaging._i18n import _LE @@ -58,6 +60,49 @@ _notifier_opts = [ _LOG = logging.getLogger(__name__) +def _send_notification(): + """Command line tool to send notifications manually.""" + parser = argparse.ArgumentParser( + description='Oslo.messaging notification sending', + ) + parser.add_argument('--config-file', + help='Path to configuration file') + parser.add_argument('--transport-url', + help='Transport URL') + parser.add_argument('--publisher-id', + help='Publisher ID') + parser.add_argument('--event-type', + default="test", + help="Event type") + parser.add_argument('--topic', + nargs='*', + help="Topic to send to") + parser.add_argument('--priority', + default="info", + choices=("info", + "audit", + "warn", + "error", + "critical", + "sample"), + help='Event type') + parser.add_argument('--driver', + default="messagingv2", + choices=extension.ExtensionManager( + 'oslo.messaging.notify.drivers' + ).names(), + help='Notification driver') + parser.add_argument('payload') + args = parser.parse_args() + conf = cfg.ConfigOpts() + conf([], + default_config_files=[args.config_file] if args.config_file else None) + transport = get_notification_transport(conf, url=args.transport_url) + notifier = Notifier(transport, args.publisher_id, topics=args.topic, + driver=args.driver) + notifier._notify({}, args.event_type, args.payload, args.priority) + + @six.add_metaclass(abc.ABCMeta) class Driver(object): """Base driver for Notifications""" diff --git a/setup.cfg b/setup.cfg index c5c83b466..9a3665e83 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,6 +27,7 @@ packages = console_scripts = oslo-messaging-zmq-proxy = oslo_messaging._cmd.zmq_proxy:main oslo-messaging-zmq-broker = oslo_messaging._cmd.zmq_proxy:main + oslo-messaging-send-notification = oslo_messaging.notify.notifier:_send_notification oslo.messaging.drivers = rabbit = oslo_messaging._drivers.impl_rabbit:RabbitDriver