From d98015ef092c0a8dcd298a6c0c2befe68232f90e Mon Sep 17 00:00:00 2001 From: Thilo W Date: Thu, 12 Oct 2023 09:59:00 +0200 Subject: [PATCH 1/4] added documentation --- doc/role-icingaweb2/module-graphite.md | 77 ++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 doc/role-icingaweb2/module-graphite.md diff --git a/doc/role-icingaweb2/module-graphite.md b/doc/role-icingaweb2/module-graphite.md new file mode 100644 index 00000000..077717e7 --- /dev/null +++ b/doc/role-icingaweb2/module-graphite.md @@ -0,0 +1,77 @@ +## Module Graphite + +This module only configures the module in Icinga Web and not the graphite backend itself. + +## Variables + +### Module Configuration File + +The general module parameter like `enabled` and `source` can be applied here. + +For the **config** file, create a dictionary with sections as keys and the parameters as values. + +Example: + +``` +icingaweb2_modules: + graphite: + enabled: true + source: package + config: + graphite: # This is the section + url: 127.0.0.1:9000 + user: graphite + password: graphitepw + ui: + default_time_range: 6 + +``` + +#### Section graphite + +| Variable | Type | Example | +|----------|--------|------------------| +| url | string | "127.0.0.1:9000" | +| user | string | "graphite" | +| password | string | "password" | +| insecure | number | "1" | + +#### Section ui + +| Variable | Type | Example | +|-------------------------|--------|---------| +| default_time_range | number | "1" | +| defautl_time_range_unit | string | "hours" | +| disable_no_graphs_found | bool | "0"/"1" | + + +#### Section icinga + +| Variable | Type | Example | +|---------------------------------------|--------|----------------------| +| graphite_writer_host_name_template | string | "$host.template$" | +| graphite_writer_service_name_template | string | "$service.template$" | +| customvar_obscured_check_command | string | "customvar" | + + +### Custom Template Files + +Custom templates are good to enhance the graphite basic template library. To include own +graphs and modifications. + +To copy them into the templates folder please use the `custom_template_files` dictionary. + +The `src_path` will search within any `files/` directory in the Ansible environment. + + +``` +icingaweb2_modules: + graphite: + enabled: true + source: package + custom_template_files: + - name: mygraph.ini + src_path: graphite_templates/mygraph.ini + - name: myothergraph.ini + src_path: graphite_templates/myothergraph.ini +``` From b64b4b64d8efec7ba926187b3fa8657138e25690 Mon Sep 17 00:00:00 2001 From: Thilo W Date: Thu, 12 Oct 2023 10:42:32 +0200 Subject: [PATCH 2/4] add module support graphite --- roles/icingaweb2/tasks/main.yml | 2 +- roles/icingaweb2/tasks/modules/graphite.yml | 39 +++++++++++++++++++++ roles/icingaweb2/vars/main.yml | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 roles/icingaweb2/tasks/modules/graphite.yml diff --git a/roles/icingaweb2/tasks/main.yml b/roles/icingaweb2/tasks/main.yml index e6bd7b6b..264419f2 100644 --- a/roles/icingaweb2/tasks/main.yml +++ b/roles/icingaweb2/tasks/main.yml @@ -16,7 +16,7 @@ ansible.builtin.set_fact: icingaweb2_packages: "{{ icingaweb2_packages + [ icingaweb2_module_packages[item.key] ] }}" loop: "{{ icingaweb2_modules | dict2items }}" - when: icingaweb2_modules is defined and icingaweb2_module_packages[item.key] is defined and item.value.enabled is true and item.value.source == "package" + when: icingaweb2_modules is defined and icingaweb2_module_packages[item.key] is defined and item.value.enabled is true and item.value.source | default('package') == "package" - name: Include OS specific installation ansible.builtin.include_tasks: "install_on_{{ ansible_os_family | lower }}.yml" diff --git a/roles/icingaweb2/tasks/modules/graphite.yml b/roles/icingaweb2/tasks/modules/graphite.yml new file mode 100644 index 00000000..e842ced2 --- /dev/null +++ b/roles/icingaweb2/tasks/modules/graphite.yml @@ -0,0 +1,39 @@ +- name: Module Graphite | Ensure config directory + ansible.builtin.file: + state: directory + dest: "{{ icingaweb2_modules_config_dir }}/{{ item.key }}" + owner: "{{ icingaweb2_httpd_user }}" + group: "{{ icingaweb2_group }}" + mode: "2770" + +- name: Module Graphite | Ensure templates directory + ansible.builtin.file: + state: directory + dest: "{{ icingaweb2_modules_config_dir }}/{{ item.key }}/templates" + owner: "{{ icingaweb2_httpd_user }}" + group: "{{ icingaweb2_group }}" + mode: "2770" + +- name: Module Graphite | Manage config files + ansible.builtin.include_tasks: manage_module_config.yml + loop: "{{ _files }}" + loop_control: + loop_var: _file + when: vars['icingaweb2_modules'][_module][_file] is defined + vars: + _module: "{{ item.key }}" + _files: + - config + +- name: Module Graphite | Copy custom templates + ansible.builtin.copy: + owner: "{{ icingaweb2_httpd_user }}" + group: "{{ icingaweb2_group }}" + src: "files/{{ _file.src_path }}" + dest: "{{ icingaweb2_modules_config_dir }}/{{ item.key }}/templates/{{ _file.name }}" + when: vars['icingaweb2_modules'][_module]['custom_template_files'] is defined + loop: "{{ vars['icingaweb2_modules'][_module]['custom_template_files'] }}" + loop_control: + loop_var: _file + vars: + _module: "{{ item.key }}" diff --git a/roles/icingaweb2/vars/main.yml b/roles/icingaweb2/vars/main.yml index bf432db1..f8797adb 100644 --- a/roles/icingaweb2/vars/main.yml +++ b/roles/icingaweb2/vars/main.yml @@ -2,3 +2,4 @@ icingaweb2_module_packages: icingadb: icingadb-web director: icinga-director + graphite: icinga-graphite-web From 3cd623fa95438d8ee6a54add949b4e2c18660d57 Mon Sep 17 00:00:00 2001 From: Thilo W Date: Thu, 12 Oct 2023 10:43:42 +0200 Subject: [PATCH 3/4] added web module tests in molecule default --- molecule/default/converge.yml | 48 +++++++++++++++++++ .../default/files/graphite_templates/test.ini | 30 ++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 molecule/default/files/graphite_templates/test.ini diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index e704a228..eefbd417 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -3,6 +3,54 @@ - name: Converge hosts: all vars: + icingaweb2_modules: + graphite: + enabled: true + custom_template_files: + - name: test.ini + src_path: graphite_templates/test.ini + config: + graphite: + url: 127.0.0.1:9000 + ui: + default_time_range: 6 + director: + enabled: true + source: package + import_schema: false + run_kickstart: false + kickstart: + config: + endpoint: icinga-default + host: 127.0.0.1 + username: root + password: root + config: + db: + resource: director_db + icingadb: + enabled: true + source: package + commandtransports: + instance01: + transport: api + host: 127.0.0.1 + username: root + password: root + config: + icingadb: + resource: icingadb + redis: + tls: '0' + redis: + redis1: + host: "127.0.0.1" + monitoring: + enabled: false + backends: + icinga2_ido_mysql: + type: ido + resource: icinga_ido icingaweb2_db: type: mysql name: icingaweb diff --git a/molecule/default/files/graphite_templates/test.ini b/molecule/default/files/graphite_templates/test.ini new file mode 100644 index 00000000..a7755e80 --- /dev/null +++ b/molecule/default/files/graphite_templates/test.ini @@ -0,0 +1,30 @@ +[hostalive-rta.graph] +check_command = "hostalive" + +[hostalive-rta.metrics_filters] +rta.value = "$host_name_template$.perfdata.rta.value" + +[hostalive-rta.urlparams] +areaAlpha = "0.5" +areaMode = "all" +min = "0" +yUnitSystem = "none" + +[hostalive-rta.functions] +rta.value = "alias(color(scale($metric$, 1000), '#1a7dd7'), 'Round trip time (ms)')" + + +[hostalive-pl.graph] +check_command = "hostalive" + +[hostalive-pl.metrics_filters] +pl.value = "$host_name_template$.perfdata.pl.value" + +[hostalive-pl.urlparams] +areaAlpha = "0.5" +areaMode = "all" +min = "0" +yUnitSystem = "none" + +[hostalive-pl.functions] +pl.value = "alias(color($metric$, '#1a7dd7'), 'Packet loss (%)')" From 15d7301edf360059d967b2eb04dfbd3d1e686286 Mon Sep 17 00:00:00 2001 From: Thilo Wening Date: Wed, 13 Nov 2024 21:58:31 +0100 Subject: [PATCH 4/4] Fixed variable expansion --- roles/icingaweb2/tasks/modules/graphite.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/icingaweb2/tasks/modules/graphite.yml b/roles/icingaweb2/tasks/modules/graphite.yml index e842ced2..87bebf5a 100644 --- a/roles/icingaweb2/tasks/modules/graphite.yml +++ b/roles/icingaweb2/tasks/modules/graphite.yml @@ -19,7 +19,7 @@ loop: "{{ _files }}" loop_control: loop_var: _file - when: vars['icingaweb2_modules'][_module][_file] is defined + when: icingaweb2_modules[_module][_file] is defined vars: _module: "{{ item.key }}" _files: @@ -31,8 +31,8 @@ group: "{{ icingaweb2_group }}" src: "files/{{ _file.src_path }}" dest: "{{ icingaweb2_modules_config_dir }}/{{ item.key }}/templates/{{ _file.name }}" - when: vars['icingaweb2_modules'][_module]['custom_template_files'] is defined - loop: "{{ vars['icingaweb2_modules'][_module]['custom_template_files'] }}" + when: icingaweb2_modules[_module].custom_template_files is defined + loop: "{{ icingaweb2_modules[_module].custom_template_files }}" loop_control: loop_var: _file vars: