1 ##############################################################################
2 # Copyright (c) 2017 ZTE Corporation and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 ep_file = '/etc/ceilometer/event_pipeline.yaml'
14 ep_file_bak = '/etc/ceilometer/event_pipeline.yaml.bak'
15 event_notifier_topic = 'notifier://?topic=alarm.all'
18 def set_notifier_topic():
19 config_modified = False
21 if not os.path.isfile(ep_file):
22 raise Exception("File doesn't exist: %s." % ep_file)
24 with open(ep_file, 'r') as file:
25 config = yaml.safe_load(file)
27 sinks = config['sinks']
29 if sink['name'] == 'event_sink':
30 publishers = sink['publishers']
31 if event_notifier_topic not in publishers:
32 print('Add event notifier in ceilometer')
33 publishers.append(event_notifier_topic)
34 config_modified = True
36 print('NOTE: event notifier is configured in ceilometer as we needed')
39 shutil.copyfile(ep_file, ep_file_bak)
40 with open(ep_file, 'w+') as file:
41 file.write(yaml.safe_dump(config))