diff --git a/docs/modules/deployment/pages/prometheus-monitoring.adoc b/docs/modules/deployment/pages/prometheus-monitoring.adoc index 6647fbd8b9e4..566bac2f956b 100644 --- a/docs/modules/deployment/pages/prometheus-monitoring.adoc +++ b/docs/modules/deployment/pages/prometheus-monitoring.adoc @@ -237,4 +237,4 @@ To customize the JMX exporter configuration, inject your own `config.yaml` file IMPORTANT: If you need a more sophisticated configuration with JMX rules, you need to inject your own `config.yaml` file. -For configuring container deployments, refer to xref:reference:configuration/core-docker.adoc#core-oci-confd[Core], xref:reference:configuration/minion-docker.adoc#minion-docker[Minion], and xref:reference:configuration/sentinel-features.adoc#sentinel-oci-confd[Sentinel]. +For configuring container deployments, refer to xref:reference:configuration/core-docker.adoc#core-oci-confd[Core], xref:reference:configuration/minion-docker.adoc#minion-docker[Minion], and xref:reference:configuration/sentinel-features.adoc#sentinel-configuration[Sentinel]. diff --git a/docs/modules/reference/pages/configuration/sentinel-features.adoc b/docs/modules/reference/pages/configuration/sentinel-features.adoc index 56270c751a8e..66c52b583327 100644 --- a/docs/modules/reference/pages/configuration/sentinel-features.adoc +++ b/docs/modules/reference/pages/configuration/sentinel-features.adoc @@ -328,101 +328,114 @@ admin@sentinel> config:update Please note, that the file `/opt/sentinel/etc/junos-telemetry-interface.groovy` must also be provided manually, e.g. by manually copying it over from _{page-component-title}_. -[[sentinel-oci-confd]] -== Configure Sentinel via confd - -=== Mount -When starting the Sentinel container, mount a YAML file to the following path `/opt/sentinel/sentinel-config.yaml`. - -Any configuration provided to confd will overwrite configuration specified as environment variables. -Direct overlay of specific configuration files will overwrite the corresponding config provided by confd. - -=== Contents -The following describes the keys available in `sentinel-config.yaml` to configure the Sentinel via confd. - -==== Sentinel controller config -[source, yaml] ----- -broker-url: "" -id: "" -location: "" ----- -Config specified will be written to `etc/org.opennms.sentinel.controller.cfg`. - -==== User/password -Supplying the broker username/password via YAML file for configuration via confd is not supported. - -==== Sentinel Elasticsearch config -[source, yaml] ----- -elasticsearch: -url: "http://elastic-ip:9200" -index-strategy: "hourly" -replicas: 0 -conn-timeout: 30000 -read-timeout: 60000 ----- -Config specified will be written to `etc/org.opennms.features.flows.persistence.elastic.cfg`. - -==== Sentinel datasource config -[source, yaml] ----- -datasource: -url: "jdbc:postgresql://localhost:5432/opennms" -username: "postgres" -password: "postgres" -database-name: "opennms" ----- -Config specified will be written to `etc/org.opennms.netmgt.distributed.datasource.cfg`. - -==== Sentinel Kafka config -[source, yaml] ----- -ipc: -kafka: -bootstrap.servers: "my-kafka-ip-1:9092,my-kafka-ip-2:9092" -group.id: "OpenNMS" ----- -Config specified will be written to `etc/org.opennms.core.ipc.sink.kafka.cfg` and `etc/org.opennms.core.ipc.sink.kafka.consumer.cfg`. - -==== Telemetry flow adapters -You can configure individual flow adapters and any number of uniquely named listeners. -See the example below for how to specify parameters and parsers. -[source, yaml] ----- -telemetry: -flows: -adapters: -NetFlow-5: -class-name: "org.opennms.netmgt.telemetry.protocols.netflow.adapter.netflow5.Netflow5Adapter" -parameters: -some-key: "some-value" ----- -Config specified will be written to `deploy/confd-flows-feature.xml`. - -==== Instance ID -[source, yaml] ----- -org.opennms.instance.id: "" ----- -Config specified will be written to `etc/custom.system.properties`. - -=== JMX Prometheus Exporter - -.JMX Exporter with a Confd YAML configuration file -[source, yaml] ----- -java: - agent: - prom-jmx-exporter: - startDelaySeconds: 0 - lowerCaseOutputName: true - lowercaseOutputLabelNames: true - autoExcludeObjectNameAttributes: true - includeObjectNames: - - "java.lang:*" - - "org.opennms.*:*" - - "kafka.producer:*" - excludeObjectNames: - - "org.apache.camel:*" ----- \ No newline at end of file +[[sentinel-configuration]] +== Configure Sentinel container + +The Sentinel container image reads its configuration from environment variables at startup. +For settings not covered by environment variables, you can overlay individual configuration files directly (see <>). + +=== Controller configuration + +[options="header, autowidth"] +|=== +| Variable | Description | Default value +| `SENTINEL_ID` | Unique identifier for this Sentinel instance. | generated UUID +| `SENTINEL_LOCATION` | Location name associated with this Sentinel instance. | `SENTINEL` +| `OPENNMS_BROKER_URL` | ActiveMQ broker URL. | – +|=== + +NOTE: You cannot supply credentials via environment variables without exposing them in `docker inspect` output and container logs. +To store credentials securely, initialize a keystore file using the `-s` flag and mount it to `$\{SENTINEL_HOME}/etc/scv.jce`. + +.Credentials (use only in non-production environments) +[options="header, autowidth"] +|=== +| Variable | Description +| `OPENNMS_HTTP_USER` | Username for the OpenNMS HTTP API. +| `OPENNMS_HTTP_PASS` | Password for the OpenNMS HTTP API. +| `OPENNMS_BROKER_USER` | Username for ActiveMQ authentication. +| `OPENNMS_BROKER_PASS` | Password for ActiveMQ authentication. +|=== + +=== IPC strategy + +Set `SENTINEL_IPC` to choose the inter-process communication transport. + +[options="header, autowidth"] +|=== +| Value | Description +| (unset) | Use JMS (ActiveMQ). This is the default when `SENTINEL_IPC` is not set. +| `jms` | Use JMS (ActiveMQ) explicitly. +| `kafka` | Use Apache Kafka. Requires additional Kafka variables (see <>). +|=== + +[[sentinel-kafka-config]] +==== Kafka configuration + +Environment variables prefixed with `KAFKA_IPC_` are written to both `$\{SENTINEL_HOME}/etc/org.opennms.core.ipc.sink.kafka.cfg` and `$\{SENTINEL_HOME}/etc/org.opennms.core.ipc.sink.kafka.consumer.cfg`. +The prefix is stripped, the remainder is lowercased, and underscores are converted to dots before being written as property keys. + +[options="header, autowidth"] +|=== +| Variable | Description | Example value +| `KAFKA_IPC_BOOTSTRAP_SERVERS` | Comma-separated list of Kafka broker addresses. | `kafka-1:9092,kafka-2:9092` +| `KAFKA_IPC_GROUP_ID` | Kafka consumer group ID. | `OpenNMS` +| `KAFKA_IPC_*` | Any additional Kafka client property. | `KAFKA_IPC_AUTO_OFFSET_RESET=latest` +|=== + +=== Datasource configuration + +[options="header, autowidth"] +|=== +| Variable | Description | Default value +| `POSTGRES_HOST` | PostgreSQL host. | – +| `POSTGRES_PORT` | PostgreSQL port. | – +| `POSTGRES_DB` | PostgreSQL database name. | – +| `POSTGRES_USER` | PostgreSQL username. | – +| `POSTGRES_PASSWORD` | PostgreSQL password. | – +|=== + +=== Elasticsearch configuration + +Environment variables prefixed with `ELASTICSEARCH_` are written to `$\{SENTINEL_HOME}/etc/org.opennms.features.flows.persistence.elastic.cfg`. + +[options="header, autowidth"] +|=== +| Variable | Description | Example value +| `ELASTICSEARCH_URL` | Elasticsearch URL. | `http://elastic:9200` +| `ELASTICSEARCH_INDEX_STRATEGY` | Index strategy. | `hourly` +| `ELASTICSEARCH_REPLICAS` | Number of index replicas. | `0` +| `ELASTICSEARCH_CONN_TIMEOUT` | Connection timeout in milliseconds. | `30000` +| `ELASTICSEARCH_READ_TIMEOUT` | Read timeout in milliseconds. | `60000` +|=== + +=== Instance ID + +[options="header, autowidth"] +|=== +| Variable | Description +| `OPENNMS_INSTANCE_ID` | Sets `org.opennms.instance.id` in `$\{SENTINEL_HOME}/etc/custom.system.properties`. +|=== + +=== Prometheus JMX exporter + +[options="header, autowidth"] +|=== +| Variable | Description | Default value +| `PROM_JMX_EXPORTER_ENABLED` | Set to `true` to enable the Prometheus JMX exporter. | `false` +| `PROM_JMX_EXPORTER_PORT` | Port on which the JMX exporter listens. | `9299` +| `PROM_JMX_EXPORTER_CONFIG` | Path to the exporter configuration file inside the container. | `/opt/prom-jmx-exporter/config.yaml` +|=== + +IMPORTANT: If you need a more sophisticated JMX configuration with custom rules, inject your own `config.yaml` file rather than relying on the default. + +[[sentinel-etc-overlay]] +=== Directory conventions + +[options="header, autowidth"] +|=== +| Mountpoint | Description +| `/opt/sentinel-etc-overlay` | Files copied into `$\{SENTINEL_HOME}/etc/` at startup, after environment variable processing. Direct file overlays take precedence over the corresponding environment variable settings. +| `/opt/sentinel-overlay` | Files copied into `$\{SENTINEL_HOME}/` at startup. +| `/keystore` | Directory for the encrypted keystore file initialized with the `-s` flag. +|=== \ No newline at end of file diff --git a/opennms-container/sentinel/Dockerfile b/opennms-container/sentinel/Dockerfile index 7bf777acbeac..4d19aa55c1dd 100644 --- a/opennms-container/sentinel/Dockerfile +++ b/opennms-container/sentinel/Dockerfile @@ -98,9 +98,8 @@ COPY container-fs/health.sh / # Install a default JMX Prometheus configuration COPY container-fs/prom-jmx-default-config.yaml /opt/prom-jmx-exporter/config.yaml -# Install confd.io configuration files and scripts and ensure they are executable -COPY ./container-fs/confd/ /opt/sentinel/confd/ -RUN chmod +x /opt/sentinel/confd/scripts/* +# Overlay container-specific etc files (config files and featuresBoot templates) +COPY --chown=10001:0 container-fs/etc/ /opt/sentinel/etc/ VOLUME [ "/opt/sentinel/deploy", "/opt/sentinel/etc", "/opt/sentinel/data" ] diff --git a/opennms-container/sentinel/container-fs/confd/conf.d/confd-flows-feature.xml.toml b/opennms-container/sentinel/container-fs/confd/conf.d/confd-flows-feature.xml.toml deleted file mode 100644 index 6efa83787896..000000000000 --- a/opennms-container/sentinel/container-fs/confd/conf.d/confd-flows-feature.xml.toml +++ /dev/null @@ -1,8 +0,0 @@ -[template] -src = "confd-flows-feature.xml.tmpl" -dest = "/opt/sentinel/deploy/confd-flows-feature.xml" -keys = [ - "/telemetry/flows/adapters" -] - -reload_cmd = "/opt/sentinel/confd/scripts/remove-if-empty /opt/sentinel/deploy/confd-flows-feature.xml" diff --git a/opennms-container/sentinel/container-fs/confd/conf.d/custom.system.properties.toml b/opennms-container/sentinel/container-fs/confd/conf.d/custom.system.properties.toml deleted file mode 100644 index 5fdc63ad0f2f..000000000000 --- a/opennms-container/sentinel/container-fs/confd/conf.d/custom.system.properties.toml +++ /dev/null @@ -1,7 +0,0 @@ -[template] -src = "custom.system.properties.tmpl" -dest = "/opt/sentinel/etc/custom.system.properties" -keys = [ - "/org.opennms.instance.id", -] -reload_cmd = "/opt/sentinel/confd/scripts/remove-if-empty /opt/sentinel/etc/custom.system.properties" diff --git a/opennms-container/sentinel/container-fs/confd/conf.d/ipc-strategy.boot.toml b/opennms-container/sentinel/container-fs/confd/conf.d/ipc-strategy.boot.toml deleted file mode 100644 index 4de26d46f2d9..000000000000 --- a/opennms-container/sentinel/container-fs/confd/conf.d/ipc-strategy.boot.toml +++ /dev/null @@ -1,7 +0,0 @@ -[template] -src = "ipc-strategy.boot.tmpl" -dest = "/opt/sentinel/etc/featuresBoot.d/ipc-strategy.boot" -keys = [ - "/ipc/kafka/bootstrap-servers" -] -reload_cmd = "/opt/sentinel/confd/scripts/remove-if-empty /opt/sentinel/etc/featuresBoot.d/ipc-strategy.boot" diff --git a/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.core.ipc.sink.kafka.cfg.toml b/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.core.ipc.sink.kafka.cfg.toml deleted file mode 100644 index 3dfd5a689592..000000000000 --- a/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.core.ipc.sink.kafka.cfg.toml +++ /dev/null @@ -1,7 +0,0 @@ -[template] -src = "org.opennms.core.ipc.sink.kafka.cfg.tmpl" -dest = "/opt/sentinel/etc/org.opennms.core.ipc.sink.kafka.cfg" -keys = [ - "/ipc/kafka" -] -reload_cmd = "/opt/sentinel/confd/scripts/remove-if-empty /opt/sentinel/etc/org.opennms.core.ipc.sink.kafka.cfg" diff --git a/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.core.ipc.sink.kafka.consumer.cfg.toml b/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.core.ipc.sink.kafka.consumer.cfg.toml deleted file mode 100644 index 7c7a63287058..000000000000 --- a/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.core.ipc.sink.kafka.consumer.cfg.toml +++ /dev/null @@ -1,7 +0,0 @@ -[template] -src = "org.opennms.core.ipc.sink.kafka.consumer.cfg.tmpl" -dest = "/opt/sentinel/etc/org.opennms.core.ipc.sink.kafka.consumer.cfg" -keys = [ - "/ipc/kafka" -] -reload_cmd = "/opt/sentinel/confd/scripts/remove-if-empty /opt/sentinel/etc/org.opennms.core.ipc.sink.kafka.consumer.cfg" diff --git a/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.features.flows.persistence.elastic.cfg.toml b/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.features.flows.persistence.elastic.cfg.toml deleted file mode 100644 index 26697278393e..000000000000 --- a/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.features.flows.persistence.elastic.cfg.toml +++ /dev/null @@ -1,11 +0,0 @@ -[template] -src = "org.opennms.features.flows.persistence.elastic.cfg.tmpl" -dest = "/opt/sentinel/etc/org.opennms.features.flows.persistence.elastic.cfg" -keys = [ - "/elasticsearch/url", - "/elasticsearch/index-strategy", - "/elasticsearch/replicas", - "/elasticsearch/conn-timeout", - "/elasticsearch/read-timeout", -] -reload_cmd = "/opt/sentinel/confd/scripts/remove-if-empty /opt/sentinel/etc/org.opennms.features.flows.persistence.elastic.cfg" diff --git a/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.netmgt.distributed.datasource.cfg.toml b/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.netmgt.distributed.datasource.cfg.toml deleted file mode 100644 index b93388ca499d..000000000000 --- a/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.netmgt.distributed.datasource.cfg.toml +++ /dev/null @@ -1,10 +0,0 @@ -[template] -src = "org.opennms.netmgt.distributed.datasource.cfg.tmpl" -dest = "/opt/sentinel/etc/org.opennms.netmgt.distributed.datasource.cfg" -keys = [ - "/datasource/url", - "/datasource/username", - "/datasource/password", - "/datasource/database-name", -] -reload_cmd = "/opt/sentinel/confd/scripts/remove-if-empty /opt/sentinel/etc/org.opennms.netmgt.distributed.datasource.cfg" diff --git a/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.sentinel.controller.cfg.toml b/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.sentinel.controller.cfg.toml deleted file mode 100644 index 7d206ee5b79d..000000000000 --- a/opennms-container/sentinel/container-fs/confd/conf.d/org.opennms.sentinel.controller.cfg.toml +++ /dev/null @@ -1,9 +0,0 @@ -[template] -src = "org.opennms.sentinel.controller.cfg.tmpl" -dest = "/opt/sentinel/etc/org.opennms.sentinel.controller.cfg" -keys = [ - "/location", - "/id", - "/broker-url" -] -reload_cmd = "/opt/sentinel/confd/scripts/remove-if-empty /opt/sentinel/etc/org.opennms.sentinel.controller.cfg" diff --git a/opennms-container/sentinel/container-fs/confd/conf.d/prom-jmx-exporter.toml b/opennms-container/sentinel/container-fs/confd/conf.d/prom-jmx-exporter.toml deleted file mode 100644 index 3cde4f6b8efa..000000000000 --- a/opennms-container/sentinel/container-fs/confd/conf.d/prom-jmx-exporter.toml +++ /dev/null @@ -1,6 +0,0 @@ -[template] -src = "prom-jmx-exporter.yaml.tmpl" -dest = "/opt/prom-jmx-exporter/config.yaml" -keys = [ - "/java/agent/prom-jmx-exporter" -] diff --git a/opennms-container/sentinel/container-fs/confd/confd.toml b/opennms-container/sentinel/container-fs/confd/confd.toml deleted file mode 100644 index 33cff06e0c6d..000000000000 --- a/opennms-container/sentinel/container-fs/confd/confd.toml +++ /dev/null @@ -1,4 +0,0 @@ -confdir = "/opt/sentinel/confd" -backend = "file" -file = [ "/opt/sentinel/sentinel-config.yaml" ] -log-level = "debug" diff --git a/opennms-container/sentinel/container-fs/confd/directories b/opennms-container/sentinel/container-fs/confd/directories deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/opennms-container/sentinel/container-fs/confd/scripts/confd_lib.sh b/opennms-container/sentinel/container-fs/confd/scripts/confd_lib.sh deleted file mode 100755 index 03f7bda1128d..000000000000 --- a/opennms-container/sentinel/container-fs/confd/scripts/confd_lib.sh +++ /dev/null @@ -1,19 +0,0 @@ -SENTINEL_ETC_DIR="/opt/sentinel/etc" -STATIC_DIR="/opt/sentinel/confd/static" - -# Checks if the given file is empty and if so deletes it. -removeIfEmpty() { - local file="$1" - - if [ -z "$file" ]; then - echo "No rendered template was specified" - exit 1 - fi - - if [ -s "$file" ]; then - return 1 - fi - - rm "$file" - return 0 -} diff --git a/opennms-container/sentinel/container-fs/confd/scripts/remove-if-empty b/opennms-container/sentinel/container-fs/confd/scripts/remove-if-empty deleted file mode 100755 index df005f14ac33..000000000000 --- a/opennms-container/sentinel/container-fs/confd/scripts/remove-if-empty +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -. "/opt/sentinel/confd/scripts/confd_lib.sh" - -if removeIfEmpty "$1"; then - echo "Removed file '$1' since it was empty after rendering" -fi diff --git a/opennms-container/sentinel/container-fs/confd/templates/confd-flows-feature.xml.tmpl b/opennms-container/sentinel/container-fs/confd/templates/confd-flows-feature.xml.tmpl deleted file mode 100644 index 142fbfabda69..000000000000 --- a/opennms-container/sentinel/container-fs/confd/templates/confd-flows-feature.xml.tmpl +++ /dev/null @@ -1,29 +0,0 @@ -{{- /* Upon updating this file please ensure that the schema sentinel-config-schema.yml accurately reflects the keys that -are used by this template. */ -}} -{{if ls "/telemetry/flows/adapters"}} - - - - - -{{$flowsPath := "/telemetry/flows" -}} -{{range lsdir (print $flowsPath "/adapters") -}} -{{$adaptersPath := (print $flowsPath "/adapters/" .) -}} -{{$adapterName := base $adaptersPath -}} - - name={{$adapterName}} - class-name={{getv (print $adaptersPath "/class-name")}} - {{range gets (print $adaptersPath "/parameters/*") -}} - parameters.{{base .Key}}={{.Value}} - {{end -}} - -{{end -}} - - - sentinel-flows - sentinel-jsonstore-postgres - sentinel-blobstore-noop - - -{{end -}} \ No newline at end of file diff --git a/opennms-container/sentinel/container-fs/confd/templates/custom.system.properties.tmpl b/opennms-container/sentinel/container-fs/confd/templates/custom.system.properties.tmpl deleted file mode 100644 index ea2bac243763..000000000000 --- a/opennms-container/sentinel/container-fs/confd/templates/custom.system.properties.tmpl +++ /dev/null @@ -1,5 +0,0 @@ -{{- /* Upon updating this file please ensure that the schema sentinel-config-schema.yml accurately reflects the keys that -are used by this template. */ -}} -{{if exists "/org.opennms.instance.id" -}} -org.opennms.instance.id = {{getv "/org.opennms.instance.id"}} -{{end -}} diff --git a/opennms-container/sentinel/container-fs/confd/templates/ipc-strategy.boot.tmpl b/opennms-container/sentinel/container-fs/confd/templates/ipc-strategy.boot.tmpl deleted file mode 100644 index 2fea211fc1fb..000000000000 --- a/opennms-container/sentinel/container-fs/confd/templates/ipc-strategy.boot.tmpl +++ /dev/null @@ -1,9 +0,0 @@ -{{- /* Upon updating this file please ensure that the schema sentinel-config-schema.yml accurately reflects the keys that -are used by this template. */ -}} -{{if (exists "/ipc/kafka/bootstrap.servers") -}} -!sentinel-jms -sentinel-kafka -{{else}} -sentinel-jms -!sentinel-kafka -{{end -}} \ No newline at end of file diff --git a/opennms-container/sentinel/container-fs/confd/templates/org.opennms.core.ipc.sink.kafka.cfg.tmpl b/opennms-container/sentinel/container-fs/confd/templates/org.opennms.core.ipc.sink.kafka.cfg.tmpl deleted file mode 100644 index 6108c3ba27c0..000000000000 --- a/opennms-container/sentinel/container-fs/confd/templates/org.opennms.core.ipc.sink.kafka.cfg.tmpl +++ /dev/null @@ -1,5 +0,0 @@ -{{- /* Upon updating this file please ensure that the schema sentinel-config-schema.yml accurately reflects the keys that -are used by this template. */ -}} -{{range gets "/ipc/kafka/*" -}} -{{base .Key}} = {{.Value}} -{{end -}} \ No newline at end of file diff --git a/opennms-container/sentinel/container-fs/confd/templates/org.opennms.core.ipc.sink.kafka.consumer.cfg.tmpl b/opennms-container/sentinel/container-fs/confd/templates/org.opennms.core.ipc.sink.kafka.consumer.cfg.tmpl deleted file mode 100644 index 6108c3ba27c0..000000000000 --- a/opennms-container/sentinel/container-fs/confd/templates/org.opennms.core.ipc.sink.kafka.consumer.cfg.tmpl +++ /dev/null @@ -1,5 +0,0 @@ -{{- /* Upon updating this file please ensure that the schema sentinel-config-schema.yml accurately reflects the keys that -are used by this template. */ -}} -{{range gets "/ipc/kafka/*" -}} -{{base .Key}} = {{.Value}} -{{end -}} \ No newline at end of file diff --git a/opennms-container/sentinel/container-fs/confd/templates/org.opennms.features.flows.persistence.elastic.cfg.tmpl b/opennms-container/sentinel/container-fs/confd/templates/org.opennms.features.flows.persistence.elastic.cfg.tmpl deleted file mode 100644 index 383aab65ede3..000000000000 --- a/opennms-container/sentinel/container-fs/confd/templates/org.opennms.features.flows.persistence.elastic.cfg.tmpl +++ /dev/null @@ -1,17 +0,0 @@ -{{- /* Upon updating this file please ensure that the schema sentinel-config-schema.yml accurately reflects the keys that -are used by this template. */ -}} -{{if exists "/elasticsearch/url" -}} -elasticUrl = {{getv "/elasticsearch/url"}} -{{end -}} -{{if exists "/elasticsearch/index-strategy" -}} -elasticIndexStrategy = {{getv "/elasticsearch/index-strategy"}} -{{end -}} -{{if exists "/elasticsearch/replicas" -}} -settings.index.number_of_replicas = {{getv "/elasticsearch/replicas"}} -{{end -}} -{{if exists "/elasticsearch/conn-timeout" -}} -connTimeout = {{getv "/elasticsearch/conn-timeout"}} -{{end -}} -{{if exists "/elasticsearch/read-timeout" -}} -readTimeout = {{getv "/elasticsearch/read-timeout"}} -{{end -}} diff --git a/opennms-container/sentinel/container-fs/confd/templates/org.opennms.netmgt.distributed.datasource.cfg.tmpl b/opennms-container/sentinel/container-fs/confd/templates/org.opennms.netmgt.distributed.datasource.cfg.tmpl deleted file mode 100644 index c82b9d721475..000000000000 --- a/opennms-container/sentinel/container-fs/confd/templates/org.opennms.netmgt.distributed.datasource.cfg.tmpl +++ /dev/null @@ -1,14 +0,0 @@ -{{- /* Upon updating this file please ensure that the schema sentinel-config-schema.yml accurately reflects the keys that -are used by this template. */ -}} -{{if exists "/datasource/url" -}} -datasource.url = {{getv "/datasource/url"}} -{{end -}} -{{if exists "/datasource/username" -}} -datasource.username = {{getv "/datasource/username"}} -{{end -}} -{{if exists "/datasource/password" -}} -datasource.password = {{getv "/datasource/password"}} -{{end -}} -{{if exists "/datasource/database-name" -}} -datasource.databaseName = {{getv "/datasource/database-name"}} -{{end -}} diff --git a/opennms-container/sentinel/container-fs/confd/templates/org.opennms.sentinel.controller.cfg.tmpl b/opennms-container/sentinel/container-fs/confd/templates/org.opennms.sentinel.controller.cfg.tmpl deleted file mode 100644 index 14d4a174ec6a..000000000000 --- a/opennms-container/sentinel/container-fs/confd/templates/org.opennms.sentinel.controller.cfg.tmpl +++ /dev/null @@ -1,11 +0,0 @@ -{{- /* Upon updating this file please ensure that the schema sentinel-config-schema.yml accurately reflects the keys that -are used by this template. */ -}} -{{if exists "/location" -}} -location = {{getv "/location"}} -{{end -}} -{{if exists "/id" -}} -id = {{getv "/id"}} -{{end -}} -{{if exists "/broker-url" -}} -broker-url = {{getv "/broker-url"}} -{{end -}} diff --git a/opennms-container/sentinel/container-fs/confd/templates/prom-jmx-exporter.yaml.tmpl b/opennms-container/sentinel/container-fs/confd/templates/prom-jmx-exporter.yaml.tmpl deleted file mode 100644 index 16fd45b27f4c..000000000000 --- a/opennms-container/sentinel/container-fs/confd/templates/prom-jmx-exporter.yaml.tmpl +++ /dev/null @@ -1,39 +0,0 @@ -# -# DON'T EDIT THIS FILE :: GENERATED WITH CONFD -# -{{$promJmxPath := "/java/agent/prom-jmx-exporter" -}} -startDelaySeconds: {{getv (print $promJmxPath "/startDelaySeconds") "0"}} -lowercaseOutputName: {{getv (print $promJmxPath "/lowerCaseOutputName") "true"}} -lowercaseOutputLabelNames: {{getv (print $promJmxPath "/lowercaseOutputLabelNames") "true"}} -autoExcludeObjectNameAttributes: {{getv (print $promJmxPath "/autoExcludeObjectNameAttributes") "true"}} - -{{$woSize := len (getvs (print $promJmxPath "/includeObjectNames/*")) -}} -{{if gt $woSize 0 -}} -includeObjectNames: -{{range getvs (print $promJmxPath "/includeObjectNames/*") -}} -- "{{.}}" -{{end -}} -{{end -}} - -{{$boSize := len (getvs (print $promJmxPath "/excludeObjectNames/*")) -}} -{{if gt $boSize 0 -}} -excludeObjectNames: -{{range getvs (print $promJmxPath "/excludeObjectNames/*") -}} -- "{{.}}" -{{end -}} -{{end -}} - -rules: -- pattern: org\.opennms\..+\.(.+)<>Value - name: sentinel_$1_$2 - type: GAUGE - -- pattern: org\.opennms\..+\.(.+)<>Count - name: sentinel_$1_$2_count - type: COUNTER - -- pattern: org\.opennms\..+\.(.+)<>(\d+)thPercentile - name: sentinel_$1_$2 - type: GAUGE - labels: - quantile: "0.$3" diff --git a/opennms-container/sentinel/container-fs/entrypoint.sh b/opennms-container/sentinel/container-fs/entrypoint.sh index 1df7efe80800..86a29b830e60 100755 --- a/opennms-container/sentinel/container-fs/entrypoint.sh +++ b/opennms-container/sentinel/container-fs/entrypoint.sh @@ -10,7 +10,10 @@ # Cause false/positives # shellcheck disable=SC2086 -set -e +set -eE + +# shellcheck disable=SC2064 +trap 'rc=$?; echo "[Startup][ERROR] entrypoint failed at line ${LINENO} (exit=${rc})"; exit ${rc}' ERR umask 002 export SENTINEL_HOME="/opt/sentinel" @@ -18,10 +21,8 @@ export KARAF_HOME="${SENTINEL_HOME}" SENTINEL_OVERLAY_ETC="/opt/sentinel-etc-overlay" SENTINEL_OVERLAY="/opt/sentinel-overlay" -CONFD_KEY_STORE="${SENTINEL_HOME}/sentinel-config.yaml" -CONFD_CONFIG_DIR="${SENTINEL_HOME}/confd" -CONFD_BIN="/usr/bin/confd" -CONFD_CONFIG_FILE="${CONFD_CONFIG_DIR}/confd.toml" +FEATURES_BOOT_DIR="${SENTINEL_HOME}/etc/featuresBoot.d" +FEATURES_BOOT_TEMPLATES_DIR="${FEATURES_BOOT_DIR}/templates" # Prometheus JMX Exporter Configuration # @@ -33,8 +34,7 @@ CONFD_CONFIG_FILE="${CONFD_CONFIG_DIR}/confd.toml" # - All other settings are optional and have sensible defaults # # Default behavior: -# - Configuration is managed via confd templates -# - Template uses key/values from /java/agent/prom-jmx-exporter +# - Configuration is managed via environment variables, which can be set in the Dockerfile, via docker run -e, or in a docker-compose file. PROM_JMX_EXPORTER_ENABLED="${PROM_JMX_EXPORTER_ENABLED:-false}" # required PROM_JMX_EXPORTER_JAR="${PROM_JMX_EXPORTER_JAR:-/opt/prom-jmx-exporter/jmx_prometheus_javaagent.jar}" PROM_JMX_EXPORTER_PORT="${PROM_JMX_EXPORTER_PORT:-9299}" @@ -94,6 +94,83 @@ setCredentials() { rsync --out-format="%n %C" ${SENTINEL_HOME}/etc/scv.jce /keystore/. } +function updateConfig() { + key=$1 + value=$2 + file=$3 + + # Omit $value here, in case there is sensitive information + echo "[Configuring] '$key' in '$file'" + + # If config exists in file, replace it. Otherwise, append to file. + if grep -E -q "^#?\s*$key\s*=" "$file"; then + sed -r -i "s@^#?\s*$key\s*=.*@$key=$value@g" "$file" #note that no config values may contain an '@' char + else + echo "$key=$value" >> "$file" + fi +} + +function parseEnvironment() { + IFS=$'\n' + + for VAR in $(env) + do + env_var=$(echo "$VAR" | cut -d= -f1) + + if [[ $env_var =~ ^KAFKA_IPC_ ]]; then + ipc_name=$(echo "$env_var" | cut -d_ -f3- | tr '[:upper:]' '[:lower:]' | tr _ .) + updateConfig "$ipc_name" "${!env_var}" "${SENTINEL_HOME}/etc/org.opennms.core.ipc.sink.kafka.cfg" + updateConfig "$ipc_name" "${!env_var}" "${SENTINEL_HOME}/etc/org.opennms.core.ipc.sink.kafka.consumer.cfg" + fi + + if [[ $env_var =~ ^ELASTICSEARCH_ ]]; then + es_name=$(echo "$env_var" | cut -d_ -f2- | tr '[:upper:]' '[:lower:]' | tr _ .) + case "$es_name" in + url) es_key="elasticUrl" ;; + index.strategy) es_key="elasticIndexStrategy" ;; + replicas) es_key="settings.index.number_of_replicas" ;; + conn.timeout) es_key="connTimeout" ;; + read.timeout) es_key="readTimeout" ;; + *) es_key="$es_name" ;; + esac + updateConfig "$es_key" "${!env_var}" "${SENTINEL_HOME}/etc/org.opennms.features.flows.persistence.elastic.cfg" + fi + + if [[ $env_var == "OPENNMS_INSTANCE_ID" ]]; then + updateConfig "org.opennms.instance.id" "${!env_var}" "${SENTINEL_HOME}/etc/custom.system.properties" + fi + done +} + +function applyFeatureBootTemplates() { + local managed_boot_files=( + "sentinel-ipc.boot" + ) + local boot_file + for boot_file in "${managed_boot_files[@]}"; do + rm -f "${FEATURES_BOOT_DIR}/${boot_file}" + done + + apply_template() { + local name="$1" + cp "${FEATURES_BOOT_TEMPLATES_DIR}/${name}" "${FEATURES_BOOT_DIR}/${name}" + echo "[Features] Enabled: ${name}" + } + + case "${SENTINEL_IPC:-}" in + kafka) + echo "[Features] IPC strategy set to Kafka." + apply_template "sentinel-ipc.boot" + ;; + jms|"") + echo "[Features] IPC strategy set to JMS (default)." + ;; + *) + echo "[Features] Unknown IPC strategy '${SENTINEL_IPC}', using defaults." + ;; + esac +} + initConfig() { if [ ! -d ${SENTINEL_HOME} ]; then echo "OpenNMS Sentinel home directory doesn't exist in ${SENTINEL_HOME}." @@ -134,6 +211,12 @@ initConfig() { else echo "OpenNMS Sentinel is already configured, skipped." fi + + # Re-applied on every start (not gated by the configured marker) so that + # environment-driven config takes effect on container restarts, matching + # the old confd behavior where templates were re-rendered on every start. + parseEnvironment + applyFeatureBootTemplates } applyOverlayConfig() { @@ -150,15 +233,6 @@ applyOverlayConfig() { rsync -r --out-format="%n %C" ${SENTINEL_OVERLAY}/* ${SENTINEL_HOME}/. || exit ${E_INIT_CONFIG} else echo "No custom config found in ${SENTINEL_OVERLAY}. Use default configuration." - fi -} - -applyConfd() { - if [ -f "${CONFD_KEY_STORE}" ]; then - echo "Found a configuration key store, applying configuration via confd." - runConfd - else - echo "No configuration key store present, skipping confd configuration." fi } @@ -182,17 +256,6 @@ start() { exec ./karaf server ${SENTINEL_DEBUG} } -runConfd() { - # Create any directories that confd might write to - while IFS= read -r dir; do - local dirToCreate="$SENTINEL_HOME"/"$dir" - echo "Creating $dirToCreate so confd can write to it" - mkdir -p "$dirToCreate" - done < "$CONFD_CONFIG_DIR"/directories - - "$CONFD_BIN" -onetime -config-file "$CONFD_CONFIG_FILE" -} - # Evaluate arguments for build script. if [[ "${#}" == 0 ]]; then usage @@ -205,7 +268,6 @@ while getopts csdfh flag; do c) useEnvCredentials initConfig - applyConfd applyOverlayConfig applyKarafDebugLogging start @@ -216,14 +278,12 @@ while getopts csdfh flag; do d) SENTINEL_DEBUG="debug" initConfig - applyConfd applyOverlayConfig applyKarafDebugLogging start ;; f) initConfig - applyConfd applyOverlayConfig applyKarafDebugLogging start diff --git a/opennms-container/sentinel/container-fs/etc/featuresBoot.d/templates/sentinel-ipc.boot b/opennms-container/sentinel/container-fs/etc/featuresBoot.d/templates/sentinel-ipc.boot new file mode 100644 index 000000000000..ab3713a3eb46 --- /dev/null +++ b/opennms-container/sentinel/container-fs/etc/featuresBoot.d/templates/sentinel-ipc.boot @@ -0,0 +1,2 @@ +!sentinel-jms +sentinel-kafka diff --git a/opennms-container/sentinel/container-fs/etc/org.opennms.core.ipc.sink.kafka.cfg b/opennms-container/sentinel/container-fs/etc/org.opennms.core.ipc.sink.kafka.cfg new file mode 100644 index 000000000000..50d019d5fd18 --- /dev/null +++ b/opennms-container/sentinel/container-fs/etc/org.opennms.core.ipc.sink.kafka.cfg @@ -0,0 +1 @@ +bootstrap.servers=${env:KAFKA_IPC_BOOTSTRAP_SERVERS:-kafka:29092} diff --git a/opennms-container/sentinel/container-fs/etc/org.opennms.core.ipc.sink.kafka.consumer.cfg b/opennms-container/sentinel/container-fs/etc/org.opennms.core.ipc.sink.kafka.consumer.cfg new file mode 100644 index 000000000000..50d019d5fd18 --- /dev/null +++ b/opennms-container/sentinel/container-fs/etc/org.opennms.core.ipc.sink.kafka.consumer.cfg @@ -0,0 +1 @@ +bootstrap.servers=${env:KAFKA_IPC_BOOTSTRAP_SERVERS:-kafka:29092} diff --git a/opennms-container/sentinel/container-fs/etc/org.opennms.features.flows.persistence.elastic.cfg b/opennms-container/sentinel/container-fs/etc/org.opennms.features.flows.persistence.elastic.cfg new file mode 100644 index 000000000000..0f471871bf60 --- /dev/null +++ b/opennms-container/sentinel/container-fs/etc/org.opennms.features.flows.persistence.elastic.cfg @@ -0,0 +1 @@ +elasticUrl=${env:ELASTICSEARCH_URL:-http://elasticsearch:9200}