diff --git a/plugins/fluentd_telemetry_plugin/build/Dockerfile b/plugins/fluentd_telemetry_plugin/build/Dockerfile index 9045285fe..1590fa183 100644 --- a/plugins/fluentd_telemetry_plugin/build/Dockerfile +++ b/plugins/fluentd_telemetry_plugin/build/Dockerfile @@ -11,7 +11,7 @@ COPY utils/ ${BASE_PATH}/utils/ COPY ufm_sdk_tools/ ${BASE_PATH}/ufm_sdk_tools/ COPY ${SRC_BASE_DIR}/conf/supervisord.conf /etc/supervisor/conf.d/ -COPY ${SRC_BASE_DIR}/scripts/init.sh ${SRC_BASE_DIR}/scripts/deinit.sh / +COPY ${SRC_BASE_DIR}/scripts/init.sh ${SRC_BASE_DIR}/scripts/deinit.sh ${SRC_BASE_DIR}/scripts/upgrade.sh / COPY ${SRC_BASE_DIR}/conf/tfs_httpd_proxy.conf ${SRC_BASE_DIR}/conf/fluentd_telemetry_plugin.cfg ${SRC_BASE_DIR}/conf/fluentd.conf ${BASE_PATH}/ COPY ${SRC_BASE_DIR}/lib/libfluent-bit.so ${SRC_BASE_DIR}/lib/libraw_msgpack_api.so ${TELEMETRY_BASE_PATH}/collectx/lib/ diff --git a/plugins/fluentd_telemetry_plugin/scripts/upgrade.sh b/plugins/fluentd_telemetry_plugin/scripts/upgrade.sh new file mode 100755 index 000000000..30feb3263 --- /dev/null +++ b/plugins/fluentd_telemetry_plugin/scripts/upgrade.sh @@ -0,0 +1,2 @@ +#!bin/bash +/bin/usr/python merge_configuration_files.py /config/fluentd_telemetry_conf.cfg /opt/ufm/ufm_plugin_tfs/fluentd_telemetry_plugin/conf/fluentd_telemetry_conf.cfg \ No newline at end of file diff --git a/plugins/fluentd_telemetry_plugin/src/merge_configuration_files.py b/plugins/fluentd_telemetry_plugin/src/merge_configuration_files.py new file mode 100644 index 000000000..a696d0afb --- /dev/null +++ b/plugins/fluentd_telemetry_plugin/src/merge_configuration_files.py @@ -0,0 +1,53 @@ +import configparser +import logging +import sys +import os + +def merge_ini_files(old_file_path, new_file_path): + # Check if files exist + if not os.path.isfile(old_file_path): + logging.error(f"file '{old_file_path}' does not exist.") + sys.exit(1) + if not os.path.isfile(new_file_path): + logging.error(f"file '{new_file_path}' does not exist.") + sys.exit(1) + + # Create a configparser object + config_old = configparser.ConfigParser() + config_new = configparser.ConfigParser() + + # Read the old and new files + try: + config_old.read(old_file_path) + config_new.read(new_file_path) + + except configparser.Error as e: + logging.error(f"Failed to parse configurations files: {e}") + sys.exit(1) + + # Merge configurations + for section in config_new.sections(): + if not config_old.has_section(section): + config_old.add_section(section) + for option in config_new.options(section): + # If option exists in the old file, retain the old value + if not config_old.has_option(section, option): + # Otherwise, add the new value + config_old.set(section, option, config_new.get(section, option)) + + # Write the merged configuration to the old file path + with open(old_file_path, 'w') as configfile: + config_old.write(configfile) + + logging.info(f"Configuration has been merged and saved to {old_file_path}") + +if __name__ == "__main__": + # Get file paths from command line arguments + if len(sys.argv) != 3: + logging.error("Usage: python merge_configuration_files.py ") + sys.exit(1) + + old_file = sys.argv[1] + new_file = sys.argv[2] + + merge_ini_files(old_file, new_file)