add the option for variable delimiter
All checks were successful
build container icingaweb2 / build (push) Successful in 4m4s
All checks were successful
build container icingaweb2 / build (push) Successful in 4m4s
This commit is contained in:
@@ -6,7 +6,7 @@ import subprocess
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
class IniFile:
|
class IniFile:
|
||||||
def __init__(self, file: str, prefix: str):
|
def __init__(self, file: str, prefix: str, delimiter: str = '__'):
|
||||||
"""class for edit a ini file
|
"""class for edit a ini file
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -16,6 +16,7 @@ class IniFile:
|
|||||||
self.file = file
|
self.file = file
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
self.config = configparser.ConfigParser()
|
self.config = configparser.ConfigParser()
|
||||||
|
self.delimiter = delimiter
|
||||||
|
|
||||||
if os.path.exists(self.file):
|
if os.path.exists(self.file):
|
||||||
self.config.read(self.file)
|
self.config.read(self.file)
|
||||||
@@ -25,9 +26,9 @@ class IniFile:
|
|||||||
|
|
||||||
def get_env_vars_with_prefix(self):
|
def get_env_vars_with_prefix(self):
|
||||||
"""read the environment and get all env start with prefix"""
|
"""read the environment and get all env start with prefix"""
|
||||||
env_vars = {key: value for key, value in os.environ.items() if key.startswith(self.prefix)}
|
env_vars = {key: value for key, value in os.environ.items() if key.startswith(self.prefix + self.delimiter)}
|
||||||
for env_var, value in env_vars.items():
|
for env_var, value in env_vars.items():
|
||||||
tmp_list = env_var.split('__')
|
tmp_list = env_var.split(self.delimiter)
|
||||||
if len(tmp_list) == 3:
|
if len(tmp_list) == 3:
|
||||||
_, section, key = tmp_list
|
_, section, key = tmp_list
|
||||||
self.edit_ini(section, key, value)
|
self.edit_ini(section, key, value)
|
||||||
@@ -52,16 +53,17 @@ class IniFile:
|
|||||||
|
|
||||||
|
|
||||||
class InitDB:
|
class InitDB:
|
||||||
def __init__(self):
|
def __init__(self, delimiter: str = '__'):
|
||||||
|
self.delimiter = delimiter
|
||||||
## check if all needes env vars a set
|
## check if all needes env vars a set
|
||||||
required_env_vars = [ 'INIT_DB', 'ICINGAWEB2_DB_RESOURCE_NAME',
|
required_env_vars = [ 'INIT_DB', 'ICINGAWEB2_DB_RESOURCE_NAME',
|
||||||
'ICINGAWEB2_DEFAULT_ADMIN_USER', 'ICINGAWEB2_DEFAULT_ADMIN_PASS' ]
|
'ICINGAWEB2_DEFAULT_ADMIN_USER', 'ICINGAWEB2_DEFAULT_ADMIN_PASS' ]
|
||||||
if all(key in os.environ.keys() for key in required_env_vars):
|
if all(key in os.environ.keys() for key in required_env_vars):
|
||||||
prefix = 'ICINGAWEB2_RESOURCES.' + os.environ['ICINGAWEB2_DB_RESOURCE_NAME']
|
prefix = 'ICINGAWEB2_RESOURCES' + self.delimiter + os.environ['ICINGAWEB2_DB_RESOURCE_NAME']
|
||||||
self.host = os.environ[prefix + '__host'] # not check if exists
|
self.host = os.environ[prefix + self.delimiter + 'host'] # not check if exists
|
||||||
self.user = os.environ[prefix + '__username'] # not check if exists
|
self.user = os.environ[prefix + self.delimiter + 'username'] # not check if exists
|
||||||
self.passwd = os.environ[prefix + '__password'] # not check if exists
|
self.passwd = os.environ[prefix + self.delimiter + 'password'] # not check if exists
|
||||||
self.dbname = os.environ[prefix + '__dbname'] # not check if exists
|
self.dbname = os.environ[prefix + self.delimiter + 'dbname'] # not check if exists
|
||||||
self.default_admin_user = os.environ['ICINGAWEB2_DEFAULT_ADMIN_USER']
|
self.default_admin_user = os.environ['ICINGAWEB2_DEFAULT_ADMIN_USER']
|
||||||
self.default_admin_pass = os.environ['ICINGAWEB2_DEFAULT_ADMIN_PASS']
|
self.default_admin_pass = os.environ['ICINGAWEB2_DEFAULT_ADMIN_PASS']
|
||||||
|
|
||||||
@@ -113,34 +115,35 @@ class InitDB:
|
|||||||
def main():
|
def main():
|
||||||
## icingaweb2 config
|
## icingaweb2 config
|
||||||
ICINGAWEB_CONFDIR = '/etc/icingaweb2/'
|
ICINGAWEB_CONFDIR = '/etc/icingaweb2/'
|
||||||
|
delimiter = '__'
|
||||||
### config.ini : https://icinga.com/docs/icinga-web/latest/doc/03-Configuration/#configuration-general
|
### config.ini : https://icinga.com/docs/icinga-web/latest/doc/03-Configuration/#configuration-general
|
||||||
IniFile(ICINGAWEB_CONFDIR + 'config.ini', 'ICINGAWEB2_CONF__')
|
IniFile(ICINGAWEB_CONFDIR + 'config.ini', 'ICINGAWEB2_CONF', delimiter)
|
||||||
### resources.ini : https://icinga.com/docs/icinga-web/latest/doc/04-Resources/#resources
|
### resources.ini : https://icinga.com/docs/icinga-web/latest/doc/04-Resources/#resources
|
||||||
IniFile(ICINGAWEB_CONFDIR + 'resources.ini', 'ICINGAWEB2_RESOURCES__')
|
IniFile(ICINGAWEB_CONFDIR + 'resources.ini', 'ICINGAWEB2_RESOURCES', delimiter)
|
||||||
### authentication.ini : https://icinga.com/docs/icinga-web/latest/doc/05-Authentication/#authentication
|
### authentication.ini : https://icinga.com/docs/icinga-web/latest/doc/05-Authentication/#authentication
|
||||||
IniFile(ICINGAWEB_CONFDIR + 'authentication.ini', 'ICINGAWEB2_AUTH__')
|
IniFile(ICINGAWEB_CONFDIR + 'authentication.ini', 'ICINGAWEB2_AUTH', delimiter)
|
||||||
### groups.ini : https://icinga.com/docs/icinga-web/latest/doc/05-Authentication/#groups
|
### groups.ini : https://icinga.com/docs/icinga-web/latest/doc/05-Authentication/#groups
|
||||||
IniFile(ICINGAWEB_CONFDIR + 'groups.ini', 'ICINGAWEB2_GROUPS__')
|
IniFile(ICINGAWEB_CONFDIR + 'groups.ini', 'ICINGAWEB2_GROUPS', delimiter)
|
||||||
### roles.ini : https://icinga.com/docs/icinga-web/latest/doc/06-Security/#roles
|
### roles.ini : https://icinga.com/docs/icinga-web/latest/doc/06-Security/#roles
|
||||||
IniFile(ICINGAWEB_CONFDIR + 'roles.ini', 'ICINGAWEB2_ROLES__')
|
IniFile(ICINGAWEB_CONFDIR + 'roles.ini', 'ICINGAWEB2_ROLES', delimiter)
|
||||||
|
|
||||||
## icingaweb2 modul: icingadb web config
|
## icingaweb2 modul: icingadb web config
|
||||||
ICINGADB_WEB_CONFDIR = ICINGAWEB_CONFDIR + 'modules/icingadb/'
|
ICINGADB_WEB_CONFDIR = ICINGAWEB_CONFDIR + 'modules/icingadb/'
|
||||||
### config.ini : https://icinga.com/docs/icinga-db-web/latest/doc/03-Configuration/#general-configuration
|
### config.ini : https://icinga.com/docs/icinga-db-web/latest/doc/03-Configuration/#general-configuration
|
||||||
IniFile(ICINGADB_WEB_CONFDIR + 'config.ini', 'ICINGAWEB2_ICINGADB_CONF__')
|
IniFile(ICINGADB_WEB_CONFDIR + 'config.ini', 'ICINGAWEB2_ICINGADB_CONF', delimiter)
|
||||||
### redis.ini : https://icinga.com/docs/icinga-db-web/latest/doc/03-Configuration/#redis-configuration
|
### redis.ini : https://icinga.com/docs/icinga-db-web/latest/doc/03-Configuration/#redis-configuration
|
||||||
IniFile(ICINGADB_WEB_CONFDIR + 'redis.ini', 'ICINGAWEB2_ICINGADB_REDIS__')
|
IniFile(ICINGADB_WEB_CONFDIR + 'redis.ini', 'ICINGAWEB2_ICINGADB_REDIS', delimiter)
|
||||||
### commandtransports.ini : https://icinga.com/docs/icinga-db-web/latest/doc/03-Configuration/#command-transport-configuration
|
### commandtransports.ini : https://icinga.com/docs/icinga-db-web/latest/doc/03-Configuration/#command-transport-configuration
|
||||||
IniFile(ICINGADB_WEB_CONFDIR + 'commandtransports.ini', 'ICINGAWEB2_ICINGADB_API__')
|
IniFile(ICINGADB_WEB_CONFDIR + 'commandtransports.ini', 'ICINGAWEB2_ICINGADB_API', delimiter)
|
||||||
|
|
||||||
## icingaweb2 modul: grafana
|
## icingaweb2 modul: grafana
|
||||||
ICINGAWEB_GRAFANA_DIR = ICINGAWEB_CONFDIR + 'modules/grafana/'
|
ICINGAWEB_GRAFANA_DIR = ICINGAWEB_CONFDIR + 'modules/grafana/'
|
||||||
### config.ini : https://github.com/NETWAYS/icingaweb2-module-grafana/blob/main/doc/03-module-configuration.md
|
### config.ini : https://github.com/NETWAYS/icingaweb2-module-grafana/blob/main/doc/03-module-configuration.md
|
||||||
IniFile(ICINGADB_WEB_CONFDIR + 'config.ini', 'ICINGAWEB2_GRAFANA_CONF__')
|
IniFile(ICINGADB_WEB_CONFDIR + 'config.ini', 'ICINGAWEB2_GRAFANA_CONF', delimiter)
|
||||||
### grafana.ini : https://github.com/NETWAYS/icingaweb2-module-grafana/blob/main/doc/02-installation.md
|
### grafana.ini : https://github.com/NETWAYS/icingaweb2-module-grafana/blob/main/doc/02-installation.md
|
||||||
IniFile(ICINGADB_WEB_CONFDIR + 'grafana.ini', 'ICINGAWEB2_GRAFANA_AUTH__')
|
IniFile(ICINGADB_WEB_CONFDIR + 'grafana.ini', 'ICINGAWEB2_GRAFANA_AUTH', delimiter)
|
||||||
### graphs.ini : https://github.com/NETWAYS/icingaweb2-module-grafana/blob/main/doc/04-graph-configuration.md
|
### graphs.ini : https://github.com/NETWAYS/icingaweb2-module-grafana/blob/main/doc/04-graph-configuration.md
|
||||||
IniFile(ICINGADB_WEB_CONFDIR + 'graph.ini', 'ICINGAWEB2_GRAFANA_GRAPH__')
|
IniFile(ICINGADB_WEB_CONFDIR + 'graph.ini', 'ICINGAWEB2_GRAFANA_GRAPH', delimiter)
|
||||||
|
|
||||||
## run db init
|
## run db init
|
||||||
InitDB()
|
InitDB()
|
||||||
|
|||||||
Reference in New Issue
Block a user