notify: add a CLI tool to manually send notifications
Change-Id: I01ebd8402e322c5c27dc2fc4c61fb5beb2dddae8
This commit is contained in:
parent
cf7961ddac
commit
ff9b4bb938
@ -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"""
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user