Skip to content
Snippets Groups Projects
Commit 1048b4dc authored by PICHOU Kyâne's avatar PICHOU Kyâne
Browse files

Merge branch 'checkmk' into 'master'

CheckMK stable image

See merge request picasoft/dockerfiles!5
parents 92c31980 41d3d200
No related branches found
No related tags found
1 merge request!5CheckMK stable image
FROM registry.picasoft.net:5000/pica-debian:stretch
MAINTAINER kyane@kyane.fr
# Set CheckMK version
ENV CHECKMK_VERSION=1.4.0p19
# Install dependencies
RUN apt-get update -y \
&& apt-get install -y \
apache2 \
binutils \
dialog \
dnsutils \
fping \
graphviz \
lcab \
libdbi1 \
libevent-2.0-5 \
libfreeradius3 \
libgd3 \
libglib2.0-0 \
libgsf-1-114 \
libltdl7 \
libnet-snmp-perl \
libpango1.0-0 \
libpcap0.8 \
libsnmp-perl \
php \
php-cgi \
php-cli \
php-gd \
php-mcrypt \
php-pear \
php-sqlite3 \
poppler-utils \
rpcbind \
rpm \
smbclient \
snmp \
time \
traceroute \
unzip \
xinetd \
&& rm -rf /var/lib/apt/lists/*
# Install CheckMK
RUN wget -O checkmk.deb "https://mathias-kettner.de/support/"$CHECKMK_VERSION"/check-mk-raw-"$CHECKMK_VERSION"_0.stretch_amd64.deb" \
&& dpkg -i checkmk.deb \
&& rm -rf checkmk.deb
# Expose CheckMK web interface
EXPOSE 5000
# Add entrypoint
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
# CheckMK
Docker image for CheckMK monitoring system.
## Configuration
This image need some environment variables to be set in order to work:
- `SITE_NAME`: Name for the Checkmk site (eg `monitoring`)
- `ADMIN_MAIL`: Admin mail (which will be used to send alerts)
- `ADMIN_PASSWORD`: Password for admin account (login is `cmkadmin`)
You can also add some optionnal variables to customize your container:
- `USER_ID`: Force the site user UID (default to `1234`)
- `GROUP_ID`: Force the site user GID (default to `1234`)
## Deploy
Here is a `docker-compose.yml` example to deploy CheckMK behind Traefik.
```
checkmk:
image: registry.picasoft.net:5000/checkmk:1.4.0p19
container_name: checkmk
volumes:
- /path/to/persistant/folder:/omd/sites
environment:
- SITE_NAME=monitoring
- ADMIN_MAIL=contact@picasoft.net
- ADMIN_PASSWORD=mypassword
labels:
- "traefik.frontend.rule=Host:checkmk.picasoft.net"
- "traefik.port=5000"
restart: always
```
## Upgrade
CheckMK provide a tool to upgrade a site version. Unfortunately this tools need that both CheckMK versions (old and new one) are installed. This is something tricky when working with containers, so the upgrade process of an existing site is quite manual. First, enter in your current container (with `docker exec -it checkmk bash`), install new CheckMK version and run upgrade process.
```
# Replace 1.4.0p22 with the new version you want to use
NEW_CHECKMK_VERSION=1.4.0p22
# Get new version
wget -O checkmk.deb "https://mathias-kettner.de/support/"$NEW_CHECKMK_VERSION"/check-mk-raw-"$NEW_CHECKMK_VERSION"_0.stretch_amd64.deb"
dpkg -i checkmk.deb
# Upgrade the site
omd stop $SITE_NAME
omd update $SITE_NAME
```
When everything is ok, you can exit and kill your container. Then build a new CheckMK image with the new version you want to use in your Dockerfile, and use this image to start again your CheckMK service. Your site will be working on the new CheckMK version.
#!/bin/bash
# Check for mandatory environment variables
: "${SITE_NAME:?You have to set SITE_NAME environment variable}"
: "${ADMIN_MAIL:?You have to set ADMIN_MAIL environment variable}"
: "${ADMIN_PASSWORD:?You have to set ADMIN_PASSWORD environment variable}"
# Some default value
USER_ID=${USER_ID:-1234}
GROUP_ID=${GROUP_ID:-1234}
site=$(omd sites | grep $SITE_NAME)
if [ $? -ne 0 ]; then
# Create the site
omd create --uid $USER_ID --gid $GROUP_ID --admin-password $ADMIN_PASSWORD $SITE_NAME
# Check that it worked
if [ $? -ne 0 ]; then
echo "Site creation failed ! Exiting..."
exit 1
fi
else
# Check site versions
version=$(echo $site | awk '{print $2}')
if [ ! -z "${version##$CHECKMK_VERSION*}" ]; then
echo "Invalid CheckMK version. This Docker image use $CHECKMK_VERSION and site $SITE_NAME is on $version. Exiting..."
exit 1
fi
# Restore existing site by creating the user/group
groupadd --force --gid $GROUP_ID $SITE_NAME
useradd $SITE_NAME --uid $USER_ID --gid $GROUP_ID --home-dir /omd/sites/$SITE_NAME
# Add this user to omd group
usermod -a -G omd $SITE_NAME
# Add www-data user to this new group
usermod -a -G $SITE_NAME www-data
# Set correct permissions on existing files
chown -R $SITE_NAME:$SITE_NAME /omd/sites/$SITE_NAME
# Override existing admin password
htpasswd -b -m /omd/sites/$SITE_NAME/etc/htpasswd cmkadmin $ADMIN_PASSWORD
# Enable the existing CheckMK site
omd enable $SITE_NAME
fi
# Stop site before changing config
omd stop $SITE_NAME
# Disable ramdisk (needed inside Docker container)
omd config $SITE_NAME set TMPFS off
# Configure mail admin
omd config $SITE_NAME set ADMIN_MAIL $ADMIN_MAIL
# Configure web access
omd config $SITE_NAME set APACHE_TCP_ADDR 0.0.0.0
omd config $SITE_NAME set APACHE_TCP_PORT 5000
# Start site
omd start $SITE_NAME
# Function to terminate properly when using docker stop
_terminate() {
echo "Caught SIGTERM signal!"
omd stop $SITE_NAME
}
trap _terminate SIGTERM
# Just sleep forever since CheckMK only run in background
sleep infinity &
pid=$!
wait
../mysql-backup/
\ No newline at end of file
../postgres-backup/
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment