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