diff options
author | Lianhao Lu <lianhao.lu@intel.com> | 2014-12-18 13:52:52 +0800 |
---|---|---|
committer | Lianhao Lu <lianhao.lu@intel.com> | 2014-12-18 15:00:12 +0800 |
commit | b1b6c17516def8d583a523b3ece9b98d388bddb6 (patch) | |
tree | eec4dacfd16f82aed4b4ae4fb4d0471e6575ac2a /tools | |
parent | c290ed8f371d9aaeeef54abb3bf503f8f0526284 (diff) | |
download | ceilometer-b1b6c17516def8d583a523b3ece9b98d388bddb6.tar.gz |
Clean up bin directory
Move ceilometer-test-event.py from directory bin to directory tools,
since it's for test purpose.
Change-Id: I3485a27ae66e255fbc460d0548be9dbb5700fa42
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/ceilometer-test-event.py | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/tools/ceilometer-test-event.py b/tools/ceilometer-test-event.py new file mode 100755 index 00000000..b5c32627 --- /dev/null +++ b/tools/ceilometer-test-event.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +# +# Copyright 2013 Rackspace Hosting. +# +# Author: Monsyne Dragon <mdragon@rackspace.com> +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Command line tool help you debug your event definitions. + +Feed it a list of test notifications in json format, and it will show +you what events will be generated. +""" + +import json +import sys + +from oslo.config import cfg +from stevedore import extension + +from ceilometer.event import converter +from ceilometer import service + + +cfg.CONF.register_cli_opts([ + cfg.StrOpt('input-file', + short='i', + help='File to read test notifications from.' + ' (Containing a json list of notifications.)' + ' defaults to stdin.'), + cfg.StrOpt('output-file', + short='o', + help='File to write results to. Defaults to stdout.'), +]) + +TYPES = {1: 'text', + 2: 'int', + 3: 'float', + 4: 'datetime'} + + +service.prepare_service() + +config_file = converter.get_config_file() +output_file = cfg.CONF.output_file +input_file = cfg.CONF.input_file + +if output_file is None: + out = sys.stdout +else: + out = open(output_file, 'w') + +if input_file is None: + notifications = json.load(sys.stdin) +else: + with open(input_file, 'r') as f: + notifications = json.load(f) + +out.write("Definitions file: %s\n" % config_file) +out.write("Notifications tested: %s\n" % len(notifications)) + +event_converter = converter.setup_events( + extension.ExtensionManager( + namespace='ceilometer.event.trait_plugin')) + +for notification in notifications: + event = event_converter.to_event(notification) + if event is None: + out.write("Dropped notification: %s\n" % + notification['message_id']) + continue + out.write("Event: %s at %s\n" % (event.event_name, event.generated)) + for trait in event.traits: + dtype = TYPES[trait.dtype] + out.write(" Trait: name: %s, type: %s, value: %s\n" % ( + trait.name, dtype, trait.value)) |