3
# Copyright 2013 Rackspace Hosting.
5
# Author: Monsyne Dragon <mdragon@rackspace.com>
7
# Licensed under the Apache License, Version 2.0 (the "License"); you may
8
# not use this file except in compliance with the License. You may obtain
9
# a copy of the License at
11
# http://www.apache.org/licenses/LICENSE-2.0
13
# Unless required by applicable law or agreed to in writing, software
14
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
# License for the specific language governing permissions and limitations
19
"""Command line tool help you debug your event definitions.
21
Feed it a list of test notifications in json format, and it will show
22
you what events will be generated.
28
from oslo.config import cfg
29
from stevedore import extension
31
from ceilometer.event import converter
32
from ceilometer import service
35
cfg.CONF.register_cli_opts([
36
cfg.StrOpt('input-file',
38
help='File to read test notifications from.'
39
' (Containing a json list of notifications.)'
40
' defaults to stdin.'),
41
cfg.StrOpt('output-file',
43
help='File to write results to. Defaults to stdout.'),
52
service.prepare_service()
54
config_file = converter.get_config_file()
55
output_file = cfg.CONF.output_file
56
input_file = cfg.CONF.input_file
58
if output_file is None:
61
out = open(output_file, 'w')
63
if input_file is None:
64
notifications = json.load(sys.stdin)
66
with open(input_file, 'r') as f:
67
notifications = json.load(f)
69
out.write("Definitions file: %s\n" % config_file)
70
out.write("Notifications tested: %s\n" % len(notifications))
72
event_converter = converter.setup_events(
73
extension.ExtensionManager(
74
namespace='ceilometer.event.trait_plugin'))
76
for notification in notifications:
77
event = event_converter.to_event(notification)
79
out.write("Dropped notification: %s\n" %
80
notification['message_id'])
82
out.write("Event: %s at %s\n" % (event.event_name, event.generated))
83
for trait in event.traits:
84
dtype = TYPES[trait.dtype]
85
out.write(" Trait: name: %s, type: %s, value: %s\n" % (
86
trait.name, dtype, trait.value))