Skip to content

Commit d36f7c4

Browse files
committed
Install influxclient and clean the callback plugin
Fix BeyondTheClouds#298
1 parent 8879d47 commit d36f7c4

File tree

2 files changed

+63
-69
lines changed

2 files changed

+63
-69
lines changed

enos/ansible/plugins/callback/influxdb_events.py

+57-68
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,17 @@ def report_event(self, fields):
5151
self.events.append(event)
5252

5353

54-
def add_extra_tags(self, fields):
55-
"""Add extra tags to the event"""
56-
57-
# Add Kolla-related information in tags
58-
fields['tags'] = '%s %s %s %s' % (fields['tags'],
59-
self.host_vars.get('kolla_ref'),
60-
self.host_vars.get('kolla_base_distro') or \
61-
self.host_vars['kolla']['kolla_base_distro'],
62-
self.host_vars.get('kolla_install_type') or \
63-
self.host_vars['kolla']['kolla_install_type']
64-
)
65-
66-
# Set the variables only available during the `os_install` phase
67-
if self.host_vars.get('openstack_release', 'auto') != 'auto':
68-
fields['tags'] = '%s %s' % (fields['tags'],
69-
self.host_vars.get('openstack_release'))
70-
71-
if 'openstack_region_name' in self.host_vars:
72-
fields['tags'] = '%s %s' % (fields['tags'],
73-
self.host_vars.get('openstack_region_name'))
74-
7554

7655
def v2_playbook_on_start(self, playbook):
7756
"""Log each starting playbook"""
7857

79-
playbook_name = os.path.basename(playbook._file_name)
58+
self.playbook_name = os.path.basename(playbook._file_name)
8059

8160
fields = {
8261
'tags': 'playbook %s' % self.username,
83-
'text': playbook_name,
62+
'text': self.playbook_name,
8463
'type': 'playbook',
85-
'title': 'Playbook Started'
64+
'title': self.playbook_name
8665
}
8766

8867
self.report_event(fields)
@@ -91,72 +70,82 @@ def v2_playbook_on_start(self, playbook):
9170
def v2_playbook_on_play_start(self, play):
9271
"""Log each starting play"""
9372

94-
host = play._variable_manager._hostvars.keys()[0]
95-
self.host_vars = play._variable_manager._hostvars[str(host)]
96-
97-
if not self.host_vars.get('enable_monitoring', True):
98-
# Disable the plugin if InfluxDB is unreachable
99-
self.disabled = True
100-
self._display.warning("The plugin %s is disabled since "
101-
"monitoring is disabled in the config file." %
102-
self._original_path)
73+
self.vm = play.get_variable_manager()
74+
# record the current play
75+
self.play = play
10376

10477
fields = {
105-
'tags': 'play %s' % self.username,
106-
'text': play.name,
78+
'tags': 'play {} {}'.format(
79+
self.playbook_name,
80+
self.play.name),
81+
'title': play.name,
10782
'type': 'play',
108-
'title': 'Play Started'
83+
'text': play.name
10984
}
11085

111-
self.add_extra_tags(fields)
11286
self.report_event(fields)
11387

11488

11589
def v2_playbook_on_task_start(self, task, is_conditional):
11690
"""Restart the timer when a task starts"""
117-
11891
self.timer = datetime.now()
11992

120-
121-
def v2_runner_on_ok(self, result):
122-
"""Log each finished task marked as 'changed'"""
123-
124-
# Log only "changed" tasks
125-
if not result.is_changed():
126-
return
127-
128-
# Record the time at the end of a task
129-
end_timer = datetime.now()
130-
m, s = divmod((end_timer - self.timer).seconds, 60)
131-
h, m = divmod(m, 60)
132-
133-
taskname = result._task.get_name()
134-
hostname = result._host
135-
13693
fields = {
137-
'tags': 'task %s %s %02d:%02d:%02d' % (
138-
self.username,
139-
hostname,
140-
h, m, s),
141-
'text': taskname,
94+
'tags': 'task {} {} {}'.format(
95+
self.playbook_name,
96+
self.play.name,
97+
task.get_name),
98+
'text': task.get_name(),
14299
'type': 'task',
143-
'title': 'Task Succeeded'
100+
'title': task.get_name()
144101
}
145102

146-
# Add the event tag if it is not the default value
147-
event_tag = result._task.tags[0]
148-
if event_tag != 'always':
149-
fields['tags'] = '%s %s' % (fields['tags'], event_tag)
150-
151-
self.add_extra_tags(fields)
152103
self.report_event(fields)
153104

105+
def v2_runner_on_ok(self, result):
106+
"""Log each finished task marked as 'changed'"""
107+
pass
108+
# Keeping the following for the record
109+
# Log only "changed" tasks
110+
# if not result.is_changed():
111+
# return
112+
#
113+
# # Record the time at the end of a task
114+
# end_timer = datetime.now()
115+
# m, s = divmod((end_timer - self.timer).seconds, 60)
116+
# h, m = divmod(m, 60)
117+
#
118+
# taskname = result._task.get_name()
119+
# hostname = result._host
120+
#
121+
# fields = {
122+
# 'tags': 'task %s %s %02d:%02d:%02d' % (
123+
# self.username,
124+
# hostname,
125+
# h, m, s),
126+
# 'text': taskname,
127+
# 'type': 'task',
128+
# 'title': 'Task Succeeded'
129+
# }
130+
#
131+
# self.report_event(fields)
132+
#
154133

155134
def v2_playbook_on_stats(self, stats):
156135
"""Connect to InfluxDB and commit events"""
157-
158136
# Set InfluxDB host from an environment variable if provided
159-
_host = os.getenv('influx_vip') or self.host_vars['influx_vip']
137+
fields = {
138+
'tags': 'playbook {}'.format(
139+
self.playbook_name),
140+
'text': 'playbook finished',
141+
'type': 'playbook',
142+
'title': self.playbook_name
143+
}
144+
self.report_event(fields)
145+
146+
_host = os.getenv('INFLUX_VIP') or self.vm.get_vars().get('influx_vip')
147+
if not _host:
148+
return
160149
_port = "8086"
161150
_user = "None"
162151
_pass = "None"

enos/task.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ def get_and_bootstrap_kolla(env, force=False):
5656
# Kolla recommends installing ansible manually.
5757
# Currently anything over 2.3.0 is supported, not sure about the future
5858
# So we hardcode the version to something reasonnable for now
59-
in_kolla('cd %s && pip install ansible==2.5.7' % kolla_path)
59+
in_kolla('pip install ansible==2.5.7')
60+
61+
# Installation influxdb client, used by the annotations
62+
enable_monitoring = env['config'].get('enable_monitoring')
63+
if enable_monitoring:
64+
in_kolla('pip install influxdb')
6065

6166
return kolla_path
6267

0 commit comments

Comments
 (0)