~ubuntu-branches/ubuntu/trusty/ceilometer/trusty-proposed

« back to all changes in this revision

Viewing changes to bin/ceilometer-test-event.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Chuck Short
  • Date: 2014-01-23 15:08:11 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20140123150811-1zaismsuyh1hcl8y
Tags: 2014.1~b2-0ubuntu1
[ James Page ]
* d/control: Add python-jsonpath-rw to BD's.
* d/p/fix-setup-requirements.patch: Bump WebOb to support < 1.4.
 (LP: #1261101)

[ Chuck Short ]
* New upstream version.
* debian/control, debian/ceilometer-common.install: Split out
  ceilometer-alarm-evaluator and ceilometer-alarm-notifier into their
  own packages. (LP: #1250002)
* debian/ceilometer-agent-central.logrotate,
  debian/ceilometer-agent-compute.logrotate,
  debian/ceilometer-api.logrotate,
  debian/ceilometer-collector.logrotate: Add logrotate files, 
  thanks to Ahmed Rahal. (LP: #1224223)
* Fix typos in upstart files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- encoding: utf-8 -*-
 
3
#
 
4
# Copyright © 2013 Rackspace Hosting.
 
5
#
 
6
# Author: Monsyne Dragon <mdragon@rackspace.com>
 
7
#
 
8
# Licensed under the Apache License, Version 2.0 (the "License"); you may
 
9
# not use this file except in compliance with the License. You may obtain
 
10
# a copy of the License at
 
11
#
 
12
#      http://www.apache.org/licenses/LICENSE-2.0
 
13
#
 
14
# Unless required by applicable law or agreed to in writing, software
 
15
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
16
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
17
# License for the specific language governing permissions and limitations
 
18
# under the License.
 
19
 
 
20
"""Command line tool help you debug your event definitions.
 
21
 
 
22
Feed it a list of test notifications in json format, and it will show
 
23
you what events will be generated.
 
24
"""
 
25
 
 
26
import json
 
27
import sys
 
28
 
 
29
from oslo.config import cfg
 
30
from stevedore import extension
 
31
 
 
32
from ceilometer.event import converter
 
33
from ceilometer import service
 
34
 
 
35
 
 
36
cfg.CONF.register_cli_opts([
 
37
    cfg.StrOpt('input-file',
 
38
               short='i',
 
39
               help='File to read test notifications from.'
 
40
               ' (Containing a json list of notifications.)'
 
41
               ' defaults to stdin.'),
 
42
    cfg.StrOpt('output-file',
 
43
               short='o',
 
44
               help='File to write results to. Defaults to stdout'),
 
45
])
 
46
 
 
47
TYPES = {1: 'text',
 
48
         2: 'int',
 
49
         3: 'float',
 
50
         4: 'datetime'}
 
51
 
 
52
 
 
53
service.prepare_service()
 
54
 
 
55
config_file = converter.get_config_file()
 
56
output_file = cfg.CONF.output_file
 
57
input_file = cfg.CONF.input_file
 
58
 
 
59
if output_file is None:
 
60
    out = sys.stdout
 
61
else:
 
62
    out = open(output_file, 'w')
 
63
 
 
64
if input_file is None:
 
65
    notifications = json.load(sys.stdin)
 
66
else:
 
67
    with open(input_file, 'r') as f:
 
68
        notifications = json.load(f)
 
69
 
 
70
out.write("Definitions file: %s\n" % config_file)
 
71
out.write("Notifications tested: %s\n" % len(notifications))
 
72
 
 
73
event_converter = converter.setup_events(
 
74
    extension.ExtensionManager(
 
75
        namespace='ceilometer.event.trait_plugin'))
 
76
 
 
77
for notification in notifications:
 
78
    event = event_converter.to_event(notification)
 
79
    if event is None:
 
80
        out.write("Dropped notification: %s\n" %
 
81
                  notification['message_id'])
 
82
        continue
 
83
    out.write("Event: %s at %s\n" % (event.event_name, event.generated))
 
84
    for trait in event.traits:
 
85
        dtype = TYPES[trait.dtype]
 
86
        out.write("    Trait: name: %s, type: %s, value: %s\n" % (
 
87
            trait.name, dtype, trait.value))