setup full autodeployment for icingaweb with grafana

This commit is contained in:
2025-02-02 02:35:29 +01:00
parent 99858ab83d
commit 1e7e1f829c
5 changed files with 420 additions and 24 deletions

View File

@@ -20,20 +20,15 @@ If you run the setup without any environment vars the setup token will be printe
## understand environment ## understand environment
For the configuration (primarily the initial setup) I use a similar method as: https://hub.docker.com/r/icinga/icingaweb2 For the configuration (primarily the initial setup) I use a similar method as: https://hub.docker.com/r/icinga/icingaweb2
* In my case a prefix like `ICINGAWEB2_CONF` refers a configuration file. * In my case a prefix like `ICINGAWEB2_CONF` refers a configuration file.
* As a separator I no (longer) use `.` rather `__` (2x `_`) * As a separator I not (longer) use `.` rather `__` (2x `_`)
* After the first `__` it follows the `Section` from this ini file. * After the first `__` it follows the `Section` from this ini file.
* After the second `__` it follows the `Key` from this `Section` before. * After the second `__` it follows the `Key` from this `Section` before.
* And after the `=` is comes the `value`. * And after the `=` is comes the `value`.
* As long as you don't need `.` in `Section`'s or `Key`'s you can use both spellings of docker compose environment
So will this: So will this:
``` ```
ICINGAWEB2_CONF__global__config_backend=db ICINGAWEB2_CONF__global__config_backend=db
``` ```
or
```
ICINGAWEB2_CONF__global__config_backend: db
```
create this: create this:
```ini ```ini
@@ -52,7 +47,6 @@ ICINGAWEB2_AUTH | /etc/icingaweb2/authentication.ini | [Authentication](https://
ICINGAWEB2_GROUPS | /etc/icingaweb2/groups.ini | [Groups](https://icinga.com/docs/icinga-web/latest/doc/05-Authentication/#groups) ICINGAWEB2_GROUPS | /etc/icingaweb2/groups.ini | [Groups](https://icinga.com/docs/icinga-web/latest/doc/05-Authentication/#groups)
ICINGAWEB2_ROLES | /etc/icingaweb2/roles.ini | [Roles](https://icinga.com/docs/icinga-web/latest/doc/06-Security/#roles) ICINGAWEB2_ROLES | /etc/icingaweb2/roles.ini | [Roles](https://icinga.com/docs/icinga-web/latest/doc/06-Security/#roles)
### vars modules ### vars modules
prefix | module | file | ref prefix | module | file | ref
--- | --- | --- | --- --- | --- | --- | ---
@@ -60,10 +54,12 @@ ICINGAWEB2_ICINGADB_CONF | icingadb | /etc/icingaweb2/modules/icingadb/config.in
ICINGAWEB2_ICINGADB_REDIS | icingadb | /etc/icingaweb2/modules/icingadb/redis.ini | [Redis® Configuration](https://icinga.com/docs/icinga-db-web/latest/doc/03-Configuration/#redis-configuration) ICINGAWEB2_ICINGADB_REDIS | icingadb | /etc/icingaweb2/modules/icingadb/redis.ini | [Redis® Configuration](https://icinga.com/docs/icinga-db-web/latest/doc/03-Configuration/#redis-configuration)
ICINGAWEB2_ICINGADB_API | icingadb | /etc/icingaweb2/modules/icingadb/commandtransports.ini | [Command Transport Configuration](https://icinga.com/docs/icinga-db-web/latest/doc/03-Configuration/#command-transport-configuration) ICINGAWEB2_ICINGADB_API | icingadb | /etc/icingaweb2/modules/icingadb/commandtransports.ini | [Command Transport Configuration](https://icinga.com/docs/icinga-db-web/latest/doc/03-Configuration/#command-transport-configuration)
ICINGAWEB2_GRAFANA_CONF | grafana | /etc/icingaweb2/modules/grafana/config.ini | [General Configuration](https://github.com/NETWAYS/icingaweb2-module-grafana/blob/main/doc/03-module-configuration.md) ICINGAWEB2_GRAFANA_CONF | grafana | /etc/icingaweb2/modules/grafana/config.ini | [General Configuration](https://github.com/NETWAYS/icingaweb2-module-grafana/blob/main/doc/03-module-configuration.md)
ICINGAWEB2_GRAFANA_AUTH | grafana | /etc/icingaweb2/modules/grafana/grafana.ini | [Grafana Preparations](https://github.com/NETWAYS/icingaweb2-module-grafana/blob/main/doc/02-installation.md)
ICINGAWEB2_GRAFANA_GRAPH | grafana | /etc/icingaweb2/modules/grafana/graphs.ini | [Graph Configuration](https://github.com/NETWAYS/icingaweb2-module-grafana/blob/main/doc/04-graph-configuration.md) ICINGAWEB2_GRAFANA_GRAPH | grafana | /etc/icingaweb2/modules/grafana/graphs.ini | [Graph Configuration](https://github.com/NETWAYS/icingaweb2-module-grafana/blob/main/doc/04-graph-configuration.md)
--- ---
### external vars
See sources below
### static vars ### static vars
var | description var | description
--- | --- --- | ---
@@ -117,22 +113,49 @@ services:
- ICINGAWEB2_ICINGADB_CONF__icingadb__resource=icingadb - ICINGAWEB2_ICINGADB_CONF__icingadb__resource=icingadb
- ICINGAWEB2_ICINGADB_REDIS__redis1__host=redis - ICINGAWEB2_ICINGADB_REDIS__redis1__host=redis
- ICINGAWEB2_ICINGADB_REDIS__redis1__port=6379 - ICINGAWEB2_ICINGADB_REDIS__redis1__port=6379
- ICINGAWEB2_ICINGADB_API__icinga2__transport=api - ICINGAWEB2_ICINGADB_CMD__icinga2__transport=api
- ICINGAWEB2_ICINGADB_API__icinga2__host=icinga2 - ICINGAWEB2_ICINGADB_CMD__icinga2__host=icinga2
- ICINGAWEB2_ICINGADB_API__icinga2__port=5665 - ICINGAWEB2_ICINGADB_CMD__icinga2__port=5665
- ICINGAWEB2_ICINGADB_API__icinga2__username=icingaweb - ICINGAWEB2_ICINGADB_CMD__icinga2__username=icingaweb
- ICINGAWEB2_ICINGADB_API__icinga2__password=icingaweb - ICINGAWEB2_ICINGADB_CMD__icinga2__password=icingaweb
- ICINGAWEB2_DB_RESOURCE_NAME=${ICINGAWEB_DB_RESOURCE_NAME:-icingaweb_db} - ICINGAWEB2_DB_RESOURCE_NAME=${ICINGAWEB_DB_RESOURCE_NAME:-icingaweb_db}
- ICINGAWEB2_DEFAULT_ADMIN_USER=${ICINGAWEB_DEFAULT_ADMIN_USER:-icingaadmin} - ICINGAWEB2_DEFAULT_ADMIN_USER=${ICINGAWEB_DEFAULT_ADMIN_USER:-icingaadmin}
- ICINGAWEB2_DEFAULT_ADMIN_PASS=${ICINGAWEB_DEFAULT_ADMIN_PASS:-icingaadmin} - ICINGAWEB2_DEFAULT_ADMIN_PASS=${ICINGAWEB_DEFAULT_ADMIN_PASS:-icingaadmin}
- ICINGAWEB2_GRAFANA_CONF__grafana__host=grafana
- ICINGAWEB2_GRAFANA_CONF__grafana__defaultdashboard=
- ICINGAWEB2_GRAFANA_CONF__grafana__defaultdashboarduid=
- ICINGAWEB2_GRAFANA_CONF__grafana__defaultdashboardpanelid=1
- ICINGAWEB2_GRAFANA_CONF__grafana__defaultorgid=1
- ICINGAWEB2_GRAFANA_CONF__grafana__timerange=12h
- ICINGAWEB2_GRAFANA_GRAPH__check_command__name=
- ICINGAWEB2_GRAFANA_GRAPH__check_command__dashboard=
- ICINGAWEB2_GRAFANA_GRAPH__check_command__dashboarduid=
- ICINGAWEB2_GRAFANA_GRAPH__check_command__panelId=
``` ```
If you ask why the hell vars with `.` :
- Due to the dynamic translation of variables to ini files, some modules use this peculiarity.
- currently in the module `grafana` in file `grafana.ini`
- https://stackoverflow.com/questions/2821043/allowed-characters-in-linux-environment-variable-names
You can remove the environment var `ICINGAWEB2_CONF_ONCE` whan will changes in `compose.yml` environment deploy every time if the container starts. You can remove the environment var `ICINGAWEB2_CONF_ONCE` whan will changes in `compose.yml` environment deploy every time if the container starts.
You can use this for future config changes, but this isn't tested and i am not sure i will recommend this... You can use this for future config changes, but this isn't tested and i am not sure i will recommend this...
For now be save and use it only for inital setup. For now be save and use it only for inital setup.
## Sources
### Icingaweb2
* [Install Icinga Web 2](https://icinga.com/docs/icinga-web/latest/doc/02-Installation/01-Debian/)
* [Installing Icinga DB Web](https://icinga.com/docs/icinga-db-web/latest/doc/02-Installation/Debian/#installing-icinga-db-web-package)
* [Feature: InfluxdbWriter ](https://icinga.com/docs/icinga-2/latest/doc/14-features/#influxdb-writer)
* [Object Type: InfluxdbWriter ](https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#influxdbwriter)
* [Grafana Integration](https://icinga.com/docs/icinga-for-windows/latest/doc/110-Installation/40-Grafana-Integration/)
### Grafana
* [Run Grafana Docker image](https://grafana.com/docs/grafana/latest/setup-grafana/installation/docker/)
* [Override configuration with environment variable](https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#override-configuration-with-environment-variables)
* [Provision Grafana](https://grafana.com/docs/grafana/latest/administration/provisioning/)
* [Dashboard JSON model](https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/view-dashboard-json-model/)
* [Original JSON: icinga2-default.json](https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/view-dashboard-json-model/)
* [Tutorial: Provision dashboards and data sources](https://grafana.com/tutorials/provision-dashboards-and-data-sources/)
* [Anonymous authentication](https://grafana.com/docs/grafana/latest/setup-grafana/configure-security/configure-authentication/anonymous-auth/)
* [Docker Hub: grafana/grafana-oos](https://hub.docker.com/r/grafana/grafana-oss)
* [Docker Hub: grafana/grafana](https://hub.docker.com/r/grafana/grafana)
* [Image Rendering](https://github.com/grafana/grafana-image-renderer?tab=readme-ov-file#remote-rendering-service-installation) (if you dont want grafana direct accessable, but have many cons)
* [Docker Hub: grafana/grafana-image-renderer](https://hub.docker.com/r/grafana/grafana-image-renderer)
* [Grafana Plugin: grafana-image-renderer](https://grafana.com/grafana/plugins/grafana-image-renderer/)

View File

@@ -1,6 +1,6 @@
services: services:
icingaweb2: icingaweb2:
image: git.ao-it.net/docker/icingaweb2 image: git.ao-it.net/docker/icingaweb2:latest
hostname: icingaweb2 hostname: icingaweb2
depends_on: depends_on:
- db_icingaweb - db_icingaweb
@@ -10,7 +10,7 @@ services:
ports: ports:
- 8080:8080 - 8080:8080
networks: networks:
- icingaweb - icinga
environment: environment:
## icingaweb2 general ## icingaweb2 general
- ICINGAWEB2_DB_RESOURCE_NAME=${ICINGAWEB_DB_RESOURCE_NAME:-icingaweb_db} - ICINGAWEB2_DB_RESOURCE_NAME=${ICINGAWEB_DB_RESOURCE_NAME:-icingaweb_db}
@@ -61,6 +61,16 @@ services:
#- ICINGAWEB2_ICINGADB_CMD__icinga2__port=${ICINGA_API_PORT:-5665} #- ICINGAWEB2_ICINGADB_CMD__icinga2__port=${ICINGA_API_PORT:-5665}
#- ICINGAWEB2_ICINGADB_CMD__icinga2__username=${ICINGA_API_ICINGAWEB_USER:-icingaweb} #- ICINGAWEB2_ICINGADB_CMD__icinga2__username=${ICINGA_API_ICINGAWEB_USER:-icingaweb}
#- ICINGAWEB2_ICINGADB_CMD__icinga2__password=${ICINGA_API_ICINGAWEB_PASS:-icingaweb} #- ICINGAWEB2_ICINGADB_CMD__icinga2__password=${ICINGA_API_ICINGAWEB_PASS:-icingaweb}
## module: grafana
### grafana: conf.ini
- ICINGAWEB2_GRAFANA_CONF__grafana__host=${GRAFANA_HOST:-grafana}:${GRAFANA_PORT:-3000}
- ICINGAWEB2_GRAFANA_CONF__grafana__defaultdashboard=${GRAFANA_DASHBOARD_NAME:-icinga2-default}
- ICINGAWEB2_GRAFANA_CONF__grafana__defaultdashboarduid=${GRAFANA_DASHBOARD_UID:-icinga2-default}
- ICINGAWEB2_GRAFANA_CONF__grafana__defaultdashboardpanelid=1
- ICINGAWEB2_GRAFANA_CONF__grafana__defaultorgid=1
- ICINGAWEB2_GRAFANA_CONF__grafana__timerange=12h
- ICINGAWEB2_GRAFANA_CONF__grafana__shadows="1"
- ICINGAWEB2_GRAFANA_CONF__grafana__accessmode=iframe
db_icingaweb: db_icingaweb:
image: mariadb:latest image: mariadb:latest
@@ -69,12 +79,47 @@ services:
volumes: volumes:
- ./files/dbs/icingaweb:/var/lib/mysql - ./files/dbs/icingaweb:/var/lib/mysql
networks: networks:
- icingaweb - icinga
environment: environment:
MARIADB_RANDOM_ROOT_PASSWORD: yes MARIADB_RANDOM_ROOT_PASSWORD: yes
MARIADB_DATABASE: ${ICINGAWEB_DB:-icingaweb} MARIADB_DATABASE: ${ICINGAWEB_DB:-icingaweb}
MARIADB_USER: ${ICINGAWEB_DB_USER:-icingaweb} MARIADB_USER: ${ICINGAWEB_DB_USER:-icingaweb}
MARIADB_PASSWORD: ${ICINGAWEB_DB_PASS:-icingaweb} MARIADB_PASSWORD: ${ICINGAWEB_DB_PASS:-icingaweb}
grafana:
image: grafana/grafana:latest
hostname: grafana
depends_on:
- icingaweb2
restart: always
#user: '0'
ports:
- ${GRAFANA_PORT:-3000}:3000
networks:
- icinga
volumes:
- ./grafana/default.source.yml:/etc/grafana/provisioning/datasources/default.yml
- ./grafana/default.dashboard.yml:/etc/grafana/provisioning/dashboards/default.yml
- ./grafana/icinga2-default.json:/var/lib/grafana/dashboards/${GRAFANA_DASHBOARD_FILE:-icinga2-default.json}
environment:
## required configs
GF_AUTH_ANONYMOUS_ENABLED: true
GF_SECURITY_ALLOW_EMBEDDING: true
#GF_AUTH_ANONYMOUS_ORG_NAME: Main Org.
GF_AUTH_ANONYMOUS_ORG_ROLE: Viewer
GF_AUTH_ANONYMOUS_HIDE_VERSION: true
## user settings
GF_SECURITY_ADMIN_USER: ${GRAFANA_ADMIN_USER:-grafanaadmin}
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASS:-grafanaadmin}
## default data source
GRAFANA_DEFAULT_SOURCE_NAME: ${ICINGA_INFLUX_HOST:-influxdb}
GRAFANA_DEFAULT_SOURCE_UID: ${ICINGA_INFLUX_HOST:-influxdb}
GRAFANA_DEFAULT_SOURCE_USER: ${ICINGA_INFLUX_USER:-icinga}
GRAFANA_DEFAULT_SOURCE_DB: ${ICINGA_INFLUX_DB:-icinga}
GRAFANA_DEFAULT_SOURCE_PASS: ${ICINGA_INFLUX_PASS:-icinga}
## default dashboard
GRAFANA_DEFAULT_DASHBOARD_NAME: ${GRAFANA_DASHBOARD_NAME:-icinga2-default}
GRAFANA_DEFAULT_DASHBOARD_FILE: ${GRAFANA_DASHBOARD_FILE:-icinga2-default.json}
networks: networks:
icingaweb: icinga:

View File

@@ -0,0 +1,7 @@
apiVersion: 1
providers:
- name: $GRAFANA_DEFAULT_DASHBOARD_NAME
type: file
options:
path: /var/lib/grafana/dashboards/$GRAFANA_DEFAULT_DASHBOARD_FILE

View File

@@ -0,0 +1,14 @@
apiVersion: 1
datasources:
- name: $GRAFANA_DEFAULT_SOURCE_NAME
type: influxdb
uid: $GRAFANA_DEFAULT_SOURCE_UID
access: proxy
user: $GRAFANA_DEFAULT_SOURCE_USER
url: http://influxdb:8086
jsonData:
dbName: $GRAFANA_DEFAULT_SOURCE_DB
httpMode: GET
secureJsonData:
password: $GRAFANA_DEFAULT_SOURCE_PASS

View File

@@ -0,0 +1,307 @@
{
"__inputs": [
{
"name": "DS_ICINGA2",
"label": "Icinga2",
"description": "",
"type": "datasource",
"pluginId": "influxdb",
"pluginName": "InfluxDB"
},
{
"name": "VAR_HOSTNAME",
"type": "constant",
"label": "hostname",
"value": "null",
"description": ""
},
{
"name": "VAR_SERVICE",
"type": "constant",
"label": "service",
"value": "null",
"description": ""
},
{
"name": "VAR_COMMAND",
"type": "constant",
"label": "command",
"value": "null",
"description": ""
}
],
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "4.6.3"
},
{
"type": "panel",
"id": "graph",
"name": "Graph",
"version": ""
},
{
"type": "datasource",
"id": "influxdb",
"name": "InfluxDB",
"version": "1.0.0"
}
],
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"description": "Show all metrics from a Icinga2 service or host",
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"hideControls": false,
"id": null,
"links": [],
"rows": [
{
"collapse": false,
"height": "250px",
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "influxdb",
"fill": 1,
"id": 1,
"legend": {
"alignAsTable": false,
"avg": false,
"current": false,
"max": false,
"min": false,
"rightSide": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 1,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 12,
"stack": false,
"steppedLine": false,
"targets": [
{
"alias": "$tag_metric",
"dsType": "influxdb",
"groupBy": [
{
"params": [
"$__interval"
],
"type": "time"
},
{
"params": [
"metric"
],
"type": "tag"
},
{
"params": [
"none"
],
"type": "fill"
}
],
"measurement": "/^$command$/",
"orderByTime": "ASC",
"policy": "default",
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"value"
],
"type": "field"
},
{
"params": [],
"type": "mean"
}
]
],
"tags": [
{
"key": "hostname",
"operator": "=~",
"value": "/^$hostname$/"
},
{
"condition": "AND",
"key": "service",
"operator": "=~",
"value": "/^$service$/"
}
]
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "$service",
"tooltip": {
"shared": true,
"sort": 1,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
]
}
],
"repeat": null,
"repeatIteration": null,
"repeatRowId": null,
"showTitle": false,
"title": "Default",
"titleSize": "h6"
}
],
"schemaVersion": 14,
"style": "dark",
"tags": [
"Icinga2",
"influxdb"
],
"templating": {
"list": [
{
"current": {
"value": "${VAR_HOSTNAME}",
"text": "${VAR_HOSTNAME}"
},
"hide": 2,
"label": null,
"name": "hostname",
"options": [
{
"value": "${VAR_HOSTNAME}",
"text": "${VAR_HOSTNAME}"
}
],
"query": "${VAR_HOSTNAME}",
"type": "custom"
},
{
"current": {
"value": "${VAR_SERVICE}",
"text": "${VAR_SERVICE}"
},
"hide": 2,
"label": null,
"name": "service",
"options": [
{
"value": "${VAR_SERVICE}",
"text": "${VAR_SERVICE}"
}
],
"query": "${VAR_SERVICE}",
"type": "custom"
},
{
"current": {
"value": "${VAR_COMMAND}",
"text": "${VAR_COMMAND}"
},
"hide": 2,
"label": null,
"name": "command",
"options": [
{
"value": "${VAR_COMMAND}",
"text": "${VAR_COMMAND}"
}
],
"query": "${VAR_COMMAND}",
"type": "custom"
}
]
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
},
"timezone": "",
"title": "icinga2-default",
"uid": "icinga-default",
"version": 3
}