diff --git a/image-files/Dockerfile b/Dockerfile similarity index 83% rename from image-files/Dockerfile rename to Dockerfile index e362db1..1c4f3a6 100644 --- a/image-files/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ RUN printf "deb http://packages.icinga.com/ubuntu icinga-bionic main\ndeb-src ht chown -R nagios:nagios /var/lib/icinga2/certs COPY create-satellite.sh /create-satellite.sh -RUN chmod +x /create-satellite.sh +COPY run-icinga.sh /run-icinga.sh +RUN chmod +x /create-satellite.sh ; chmod +x /run-icinga.sh -CMD /create-satellite.sh ; /usr/sbin/icinga2 daemon +ENTRYPOINT ["/run-icinga.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..6e7cc8c --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# icinga-satellite +An easy-to-use Dockerized Icinga2 satellite setup. It could be used as an +Icinga2 agent aswell, but I don't think that would make much sense. The goal +is instead to create an easy-to-deploy satellite Docker. + +## Environment variables +Everything is controlled using the follwing environment variables. + +* **CN** is the Common Name of the satellite +* **ZONE** is the Zone name in which the satellite is. If no zone is specified + it defaults to using the **CN** as the zone. +* **PARENTCN** is the Common Name of the parent host, for example the master. If + no **PARENTCN** is specified it defaults to using the **PARENTHOST** as a + **PARENTCN** +* **PARENTHOST** is the FQDN or IP of the parent host, for example the master. +* **PARENTPORT** is the Icinga2 port on the parent host. Defaults to 5665. +* **TICKET** is the ticket you get from the master (if you are using Director + you find it under the Agent tab of the host). +* **ACCEPT_CONFIG** takes a *y* or *n* value for yes or no. The default is + *n*(o). +* **ACCEPT_COMMANDS** takes a *y* or *n* value for yes or no. The default is + *n*(o). +* **DISABLE_CONFD** takes a *y* or *n* value for yes or no. The default is + *y*(es). This should be a sane default for most people. + +## Example usage +``` +#> docker run -d --name my-icinga-sat \ + -e CN=icinga-sat02.local \ + -e PARENTHOST=icinga-master.local \ + -e PARENTCN=icinga-master.local \ + -e PARENTZONE=master \ + -e TICKET=124de0573705d1133db62a974aaf \ + -e DISABLE_CONFD=y -e ACCEPT_CONFIG=y -e ACCEPT_COMMANDS=y \ + jackbenny/icinga-satellite +``` + +## docker-compose.yml example +``` +version: "3.8" +services: + my-icinga-sat: + image: jackbenny/icinga-satellite + environment: + - CN=icinga-sat02.local + - ZONE=icinga-sat02.local + - PARENTHOST=icinga-master.local + - PARENTCN=icinga-master.local + - PARENTZONE=master + - TICKET=124de0573705d1133db62a974aaf + - ACCEPT_CONFIG=y + - ACCEPT_COMMANDS=y + - DISABLE_CONFD=y +``` + diff --git a/image-files/create-satellite.sh b/create-satellite.sh similarity index 54% rename from image-files/create-satellite.sh rename to create-satellite.sh index 8911fa8..04f9e86 100755 --- a/image-files/create-satellite.sh +++ b/create-satellite.sh @@ -1,7 +1,7 @@ #!/bin/bash -# If parent cn is not specified, default it to the parent host. -# If the zone if not specified, default it to the cn of the satellite/agent. +# If parent CN is not specified, default it to the parent host. +# If the zone if not specified, default it to the CN of the satellite/agent. # Use the default port if none is specified. if [ -z "$PARENTCN" ]; then @@ -16,6 +16,26 @@ if [ -z "$PARENTPORT" ]; then PARENTPORT=5665 fi +# Set accept config and accept commands (defaults to no) +if [ "$ACCEPT_CONFIG" == "y" ]; then + ACCEPT_CONF="--accept-config" +else + ACCEPT_CONF=" " +fi + +if [ "$ACCEPT_COMMANDS" == "y" ]; then + ACCEPT_COMM="--accept-commands" +else + ACCEPT_COMM=" " +fi + +# Defaults to disable conf.d (so to "n" or anything else to enable inclusion of +# conf.d directory +if [ -z "$DISABLE_CONFD" ] || [ "$DISABLE_CONFD" == "y" ]; then + DISABLE_CONF="--disable-confd" +else + DISABLE_CONF=" " +fi icinga2 pki new-cert --cn "$CN" \ --key /var/lib/icinga2/certs/"${CN}".key \ @@ -33,5 +53,6 @@ icinga2 node setup --ticket "$TICKET" \ --parent_zone "$PARENTZONE" \ --parent_host "$PARENTHOST" \ --trustedcert /var/lib/icinga2/certs/"${PARENTCN}".crt \ ---accept-commands --accept-config \ ---disable-confd +$ACCEPT_CONF \ +$ACCEPT_COMM \ +$DISABLE_CONF diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 2e6f6e9..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: "3.8" -services: - - icinga: - build: - context: ./image-files - dockerfile: Dockerfile - environment: - - CN= - - ZONE= - - PARENTHOST= - - PARENTCN= - - PARENTZONE= - - TICKET= diff --git a/run-icinga.sh b/run-icinga.sh new file mode 100755 index 0000000..849cb20 --- /dev/null +++ b/run-icinga.sh @@ -0,0 +1,3 @@ +#!/bin/bash +/create-satellite.sh +/usr/sbin/icinga2 daemon