Quelle: https://github.com/lippserd/docker-compose-icinga
Stack nach Anleitung von Github herunterladen und im Verzeichnis folgende Änderungen vornehmen:
init-icinga2.sh unten einfügen if [ -f /data/etc/icinga2/conf.d/hosts.conf ]; then
rm -F /data/etc/icinga2/conf.d/hosts.conf
fi
docker-compose.yml die Zeile icingaweb.passwords.icingaweb2.icingaadmin:cd /opt/docker-compose-icinga docker compose up -d
docker compose down
docker-compose.yml die Zeilen auskommentieren icingaweb.roles.Administrators.groups: Administrators icingaweb.roles.Administrators.permissions: '*' icingaweb.roles.Administrators.users: icingaadmindocker compose up -d
systemctl edit –full docker-compose-icinga.service Unit] Description=Start Icinga-Playground Docker containers After=docker.service Requires=docker.service [Service] Type=oneshot RemainAfterExit=yes WorkingDirectory=/opt/docker-compose-icinga User=linux Group=docker #ExecStart=docker compose -p icinga-playground up -d #ExecStop=docker compose -p icinga-playground stop ExecStart=docker compose up -d ExecStop=docker compose stop TimeoutStartSec=0 [Install] WantedBy=multi-user.target
Danach den Service einschalten und den Systemd-Daemon neustarten systemctl enable docker-compose-icinga.service && systemctl daemon-reload
In den Icinga2 Container verbinden und folgendes ausführen:
echo "include_recursive \"/custom_data/custom.conf.d/\"" >> /etc/icinga2/icinga2.conf
Danach auf dem Docker-Host den Ordner für die eigenen Checks erstellen und Checks dort ablegen.
mkdir -p /opt/docker-compose-icinga/icinga2.conf.d/my-plugins/
Hier ein Check zum Überwachen von QNap-NAS (Quelle: siehe Inhalt):
#!/bin/bash
############################# Created and written by Matthias Luettermann ###############
#
#
# special thnaks to
# Nicola Bandini n.bandini@gmail.com
# Tom Lesniak and Hugo Geijteman
# for the nice and useful inspiratipon
#
# This progmem is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation;
#
# This progmem is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# contact the author directly for more information at: matthias@xcontrol.de
##########################################################################################
#Version 1.40
usage="
-ver Check_qnap Version
-C community default public
-t timeout default 10 secdons
-v snmpversion default 2c
-p snmpport defauilt 161
-a checks you can use
cpuload: check´s the system CPU load in perent
cputemp: check´s the sytem CPU Temperature
systemp: check´s the system Temperature
hdtemp: check´s the Harddive Temperature
diskusage: check´s the diskusage on perent
mem: check´s the mem usage in perent
volstatus: check´s the Volume status
fan: check´s the Fan Speed
hdstatus: check´s the Harddive status
cachediskstatus: check´s the Cachedisk status
lunstatus: check´s the LUN status
raidstatus: check´s the Raid status
powerstatus: check´s the Power status
sysinfo: provides the QNAP infos
example
check_qanp -H 192.168.0.2 -a mem
responce: OK: Memory Total=15976MB used=9177MB free:6799MB|Memory usage=43%;80;90;0;100
or
check_qanp -H myqnap.domain.com -C public -v 1 -p 123 -a cputemp -u F -w 40 -c 45 -t 60
checked host myqnap.domain.com
community public
snmpversion 1
snmpport 123
check cpu Temperature
unit fahrenheit
warning 40 F
critical 45 F
timeout 60 seconds
"
while getopts H:b:C:t:v:p:a:w:c:u:help:h option;
do
case $option in
H) hostaddress=$OPTARG;;
b) version=$OPTARG;;
C) community=$OPTARG;;
t) timeout=$OPTARG;;
v) snmpversion=$OPTARG;;
p) snmpport=$OPTARG;;
a) check=$OPTARG;;
w) warning=$OPTARG;;
c) critical=$OPTARG;;
u) unit=$OPTARG;;
h) help=1;;
esac
done
check()
{
if [[ "$help" == "1" ]]; then
echo "$usage"
exit;
fi
if [[ -z "$hostaddress" ]] || [[ -z "$check" ]] && [[ "$help" != "1" ]];then
echo "
** Hostaddress and checkprocedure are mandatory **
"
echo "$usage"
exit;
fi
}
check
if [[ -z "$community" ]]; then
community=public;
fi
if [[ -z "$timeout" ]]; then
timeout=10;
fi
if [[ -z "$snmpversion" ]]; then
snmpversion=2c;
fi
if [[ -z "$snmpport" ]]; then
snmpport=161;
fi
if [[ -z "$warning" ]]; then
warning=80;
fi
if [[ -z "$critical" ]]; then
critical=90;
fi
if [[ -z "$unit" ]]; then
unit=C;
fi
if [[ "$unit" == "C" ]]; then
var1="-c2-3";
if [[ "$check" == "cputemp" ]]; then
var2=20
var3=90
else
var2=20
var3=60
fi
else
var1="-c7-9";
if [[ "check" == "cputemp" ]]; then
var2=32
var3=194
else
var=32
var=140
fi
fi
output=""
niu=0
count=0
counter=0
status=""
criticalqty=0
warningqty=0
okqty=0
avg=0
mysnmpcheck="snmpget -v $snmpversion -c $community -t $timeout $hostaddress:$snmpport"
# DISKUSAGE
if [[ "$check" == "diskusage" ]]; then
capacity=$($mysnmpcheck 1.3.6.1.4.1.24681.1.2.17.1.4.1 | awk '{print $4}' | sed 's/.\(.*\)/\1/')
free=$($mysnmpcheck 1.3.6.1.4.1.24681.1.2.17.1.5.1 | awk '{print $4}' | sed 's/.\(.*\)/\1/')
unit=$($mysnmpcheck 1.3.6.1.4.1.24681.1.2.17.1.4.1 | awk '{print $5}' | sed 's/.*\(.B\).*/\1/')
unit2=$($mysnmpcheck 1.3.6.1.4.1.24681.1.2.17.1.5.1 | awk '{print $5}' | sed 's/.*\(.B\).*/\1/')
if [[ "$unit" == "TB" ]]; then
factor=$(echo "scale=0; 1000000" | bc -l)
elif [[ "$unit" == "GB" ]]; then
factor=$(echo "scale=0; 1000" | bc -l)
else
factor=$(echo "scale=0; 1" | bc -l)
fi
if [[ "$unit2" == "TB" ]]; then
factor2=$(echo "scale=0; 1000000" | bc -l)
elif [[ "$unit2" == "GB" ]]; then
factor2=$(echo "scale=0; 1000" | bc -l)
else
factor2=$(echo "scale=0; 1" | bc -l)
fi
capacitybytes=$(echo "scale=0; $capacity*$factor" | bc -l)
freebytes=$(echo "scale=0; $free*$factor2" | bc -l)
usedbytes=$(echo "scale=0; $capacitybytes-$freebytes" | bc -l)
used=$(echo "scale=0; $usedbytes/$factor" | bc -l)
usedperc=$(echo "scale=0; $usedbytes*100/$capacitybytes" | bc -l)
freeperc=$(echo "scale=0; $freebytes*100/$capacitybytes" | bc -l)
output="Total=$capacity $unit Used=$used $unit Free=$free $unittest2|Used=$usedperc%;$warning;$critical;0;100"
if [[ $usedperc -ge $critical ]]; then
echo "critical: "$output
exit 2
elif [[ $usedperc -ge $warning ]]; then
echo "warning: "$output
exit 1
else
echo "OK: "$output
exit 0
fi
# CPULOAD
elif [[ "$check" == "cpuload" ]]; then
cpuload=$($mysnmpcheck 1.3.6.1.4.1.24681.1.2.1.0 | awk '{print $4 $5}' | sed 's/.\(.*\)...../\1/')
output="CPU-load=$cpuload%|CPU-load=$cpuload%;$warning;$critical;0;100"
if [[ $cpuload -ge $critical ]]; then
echo "critical: "$output
exit 2
elif [[ $cpuload -ge $warning ]]; then
echo "warning: "$output
exit 1
else
echo "OK: "$output
exit 0
fi
# CPUTEMP
elif [[ "$check" == "cputemp" ]]; then
temp=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.5.0 | awk '{print $4,$5}' | cut $var1)
output="CPU-temperature=$temp $unit|CPU-temperature=$temp%unit;$warning;$critical;$var2;$var3"
if [[ $temp -ge $critical ]]; then
echo "critical: "$output
exit 2
elif [[ $temp -ge $warning ]]; then
echo "warning: "$output
exit 1
else
echo "OK: "$output
exit 0
fi
# System Temperature
elif [[ "$check" == "systemp" ]]; then
temp=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.6.0 | awk '{print $4,$5}' | cut $var1)
output="System-temperature=$temp $unit|System-temperature=$temp$unit;$warning;$critical;$var2;$var3"
if [[ $temp -ge $critical ]]; then
echo "critical: "$output
exit 2
elif [[ $temp -ge $warning ]]; then
echo "warning: "$output
exit 1
else
echo "OK: "$output
exit 0
fi
# HD Temperature
elif [[ "$check" == "hdtemp" ]]; then
count=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.10.0 | awk '{print $4}')
for (( c=1; c<=$count; c++ ))
do
temp=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.11.1.3.$c | awk '{print $4,$5}' | cut $var1)
if [[ "$temp" -ge "$critical" ]]; then
crt="$crt| HD-$c $temp $unit"
criticalqty=$(echo "scale=0; $criticalqty+1" | bc -l)
avg=$(echo "scale=4; $avg + $temp" | tr , . | bc)
elif [[ "$temp" -ge "$warning" ]]; then
wrn="$wrn| HD-$c $temp $unit"
warningqty=$(echo "scale=0; $warningqty+1" | bc -l)
avg=$(echo "scale=4; $avg + $temp" | tr , . | bc)
else
okqty=$(echo "scale=0; $okqty+1" | bc -l)
avg=$(echo "scale=4; $avg + $temp" | tr , . | bc)
fi
done
avg=$(echo $avg/$count | bc )
if [[ "$criticalqty" -ge "1" ]]; then
echo "critical: $criticalqty $crt Average temperature= $avg $unit|Average-HD-temp=$avg$unit;$warning;$critical;$var2;$var3"
exit 2
elif [[ "$warningqty" -ge "1" ]]; then
echo "warning: $warningqty $wrn Average temperature= $avg $unit|Average-HD-temp=$avg$unit;$warning;$critical;$var2;$var3"
exit 1
else
echo "OK: $okqty HD´s Average temperature= $avg $unit|Average-HD-temp=$avg$unit;$warning;$critical;$var2;$var3"
exit 0
fi
# Free mem
elif [[ "$check" == "mem" ]]; then
total=$($mysnmpcheck 1.3.6.1.4.1.24681.1.2.2.0 | awk '{print $4 $5}' | sed 's/.\(.*\)...../\1/')
used=$($mysnmpcheck 1.3.6.1.4.1.24681.1.2.3.0 | awk '{print $4 $5}' | sed 's/.\(.*\)...../\1/')
perc=$(echo "scale=0; 100-($used*100)/$total" | bc -l)
unit=$($mysnmpcheck 1.3.6.1.4.1.24681.1.2.2.0 | awk '{print $5}' | sed 's/.*\(.B\).*/\1/')
free=$(echo "scale=0; $total-$used" | bc -l)
output="Memory Total=$total$unit used=$used$unit free:$free$unit|Memory-usage=$perc%;$warning;$critical;0;100"
if [[ $perc -ge $critical ]]; then
echo "critical: "$output
exit 2
elif [[ $perc -ge $warning ]]; then
echo "warning: "$output
exit 1
else
echo "OK: "$output
exit 0
fi
# Volumestatus
elif [[ "$check" == "volstatus" ]]; then
count=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.16.0 | awk '{print $4}')
for (( c=1; c<=$count; c++ ))
do
status=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.17.1.6.$c | awk '{print $4}' | sed 's/^"\(.*\).$/\1/')
if [[ $status == "Ready" ]]; then
okqty=$(echo "scale=0; okqty+1" |bc -l)
elif [[ $status == "Rebuilding..." ]]; then
warningqty=$(echo "scale=0; $warningqty+1" | bc -l)
else
criticalqty=$(echo "scale=0; $criticalqty+1" | bc -l)
fi
capacity=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.17.1.4.$c | awk '{print $4}' | sed 's/^"\(.*\).$/\1/')
free=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.17.1.5.$c | awk '{print $4}' | sed 's/^"\(.*\).$/\1/')
unit=$($mysnmpcheck 1.3.6.1.4.1.24681.1.2.17.1.4.$c | awk '{print $5}' | sed 's/.*\(.B\).*/\1/')
unit2=$($mysnmpcheck 1.3.6.1.4.1.24681.1.2.17.1.5.$c | awk '{print $5}' | sed 's/.*\(.B\).*/\1/')
if [[ "$unit" == "TB" ]]; then
factor=$(echo "scale=0; 1000" | bc -l)
elif [[ "$unit" == "GB" ]]; then
factor=$(echo "scale=0; 100" | bc -l)
else
factor=$(echo "scale=0; 1" | bc -l)
fi
if [[ "$unit2" == "TB" ]]; then
factor2=$(echo "scale=0; 1000" | bc -l)
elif [[ "$unit2" == "GB" ]]; then
factor2=$(echo "scale=0; 100" | bc -l)
else
factor2=$(echo "scale=0; 1" | bc -l)
fi
capacitybytes=$(echo "scale=0; $capacity*$factor" | bc -l)
freebytes=$(echo "scale=0; $free*$factor2" | bc -l)
usedbytes=$(echo "scale=0; $capacitybytes-$freebytes" | bc -l)
used=$(echo "scale=0; $usedbytes/$factor" | bc -l)
usedperc=$(echo "scale=0; $usedbytes*100/$capacitybytes" | bc -l)
freeperc=$(echo "scale=0; $freebytes*100/$capacitybytes" | bc -l)
if [[ $usedperc -ge $critical ]]; then
crt="$usedperc"
criticalqty=$(echo "scale=0; $criticalqty+1" | bc -l)
elif [[ $perc -ge $warning ]]; then
wrn="$usedperc"
warningqty=$(echo "scale=0; $warningqty+1" | bc -l)
fi
if [[ $c -lt $count ]]; then
output="$output Volume-$c $status, Total=$capacity $unit, Used=$used $unit, Free=$free $unit2, "
else
output="$output Volume-$c $status, Total=$capacity $unit, Used=$used $unit, Free=$free $unit2"
fi
done
if [[ $criticalqty -ge 1 ]]; then
echo "critical: $criticalqty $crt, $output|Used=$usedperc%;$warning;$critical;0;100"
exit 2
elif [[ $warningqty -ge 1 ]]; then
echo "warning: $warningqty $wrn, $output|Used=$usedperc%;$warning;$critical;0;100"
exit 1
else
echo "OK: $okqty Volumes, $output|Used=$usedperc%;$warning;$critical;0;100"
exit 0
fi
# Fan
elif [[ "$check" == "fan" ]]; then
count=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.14.0 | awk '{print $4}')
for (( c=1; c<=$count; c++ ))
do
speed=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.15.1.3.$c | awk '{print $4}' | cut -c 2-5 )
if [[ $speed -le 5000 ]]; then
okqty=$(echo "scale=0; $okqty+1" | bc -l)
avg=$(echo "scale=4; $avg + $speed" | tr , . | bc)
else
crt="$crt| HD-$c $speed RPM"
criticalqty=$(echo "scale=0; $criticalqty+1" | bc -l)
avg=$(echo "scale=4; $avg + $speed" | tr , . | bc)
fi
done
avg=$(echo $avg/$count | bc )
if [[ "$criticalqty" -ge "1" ]]; then
echo "CRITICAL: $criticalqty Average Speed=$avg RPM"
exit 2
else
echo "OK Fans $okqty Average Speed=$avg RPM|Average-Speed=$avg RPM;4800;5200"
exit 0
fi
# HD Status
elif [[ "$check" == "hdstatus" ]]; then
count=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.10.0 | awk '{print $4}')
for (( c=1; c<=$count; c++ ))
do
status=$($mysnmpcheck 1.3.6.1.4.1.24681.1.2.11.1.7.$c | awk '{print $4}' | sed 's/^"\(.*\).$/\1/')
if [[ $status == "GOOD" ]]; then
okqty=$(echo "scale=0; $okqty+1" | bc -l)
elif [[ "$status" == "--" ]]; then
niu=$(echo "scale=0; $niu+1" | bc -l)
else
crt=" Disk ${c}"
criticalqty=$(echo "scale=0; $criticalqty+1" | bc -l)
fi
done
if [[ "$criticalqty" -ge "1" ]]; then
echo "CRITICAL: ${crt}"
exit 2
else
echo "OK: Online Disk $okqty, HD status = GOOD, Free Slot $niu"
exit 0
fi
# Cachedisstatus
elif [[ "$check" == "cachediskstatus" ]]; then
count=$($mysnmpcheck .1.3.6.1.4.1.24681.1.4.1.1.1.1.6.1.0 | awk '{print $4}')
for (( c=1; c<=$count; c++ ))
do
status=$($mysnmpcheck .1.3.6.1.4.1.24681.1.4.1.1.1.1.6.2.1.4.$c | awk '{print $4}' | sed 's/^"\(.*\).$/\1/')
if [[ "$status" -eq "0" ]]; then
okqty=$(echo "scale=0; $okqty+1" | bc -l)
else
crt="Cachedisk NOK $c"
criticalqty=$(echo "scale=0; $criticalqty+1" | bc -l)
fi
done
if [[ "$criticalqty" -ge "1" ]]; then
echo "CRITICAL: ${criticalqty}"
exit 2
else
echo "OK: Cachedisk $okqty "
exit 0
fi
# LUN Status
elif [[ "$check" == "lunstatus" ]]; then
count=$($mysnmpcheck .1.3.6.1.4.1.24681.1.4.1.1.2.1.10.1.0 | awk '{print $4}')
for (( c=1; c<=$count; c++ ))
do
status=$($mysnmpcheck .1.3.6.1.4.1.24681.1.4.1.1.2.1.10.2.1.5.$c | awk '{print $4}' | sed 's/^"\(.*\).$/\1/')
if [[ $status == "Enabled" ]]; then
okqty=$(echo "scale=0; $okqty+1" | bc -l)
else
crt=" LUN NOK ${c}"
criticalqty=$(echo "scale=0; $criticalqty+1" | bc -l)
fi
done
if [[ "$criticalqty" -ge "1" ]]; then
echo "CRITICAL: ${criticalqty}"
exit 2
else
echo "OK: LUN´s $okqty"
exit 0
fi
# raid Status
elif [[ "$check" == "raidstatus" ]]; then
count=$($mysnmpcheck .1.3.6.1.4.1.24681.1.4.1.1.1.2.1.1.0 | awk '{print $4}')
for (( c=1; c<=$count; c++ ))
do
status=$($mysnmpcheck .1.3.6.1.4.1.24681.1.4.1.1.1.2.1.2.1.5.$c | awk '{print $4}' | sed 's/^"\(.*\).$/\1/')
if [[ $status == "Ready" ]]; then
okqty=$(echo "scale=0; $okqty+1" | bc -l)
else
crt=" Raid NOK $c"
fi
done
if [[ "$criticalqty" -ge "1" ]]; then
echo "CRITICAL: $crt"
criticalqty=$(echo "scale=0; $criticalqty+1" | bc -l)
exit 2
else
echo "OK: Raid $okqty Ready"
exit 0
fi
# Power stuply status
elif [[ "$check" == "powerstatus" ]]; then
count=$($mysnmpcheck .1.3.6.1.4.1.24681.1.4.1.1.1.1.3.1.0 | awk '{print $4}')
for (( c=1; c<=$count; c++ ))
do
status=$($mysnmpcheck .1.3.6.1.4.1.24681.1.4.1.1.1.1.3.2.1.4.$c | awk '{print $4}')
if [[ "$status" -eq "0" ]]; then
okqty=$(echo "scale=0; $okqty+1" | bc -l)
else
crt="Powersupply NOK $c"
criticalqty=$(echo "scale=0; $criticalqty+1" | bc -l)
fi
done
if [[ "$criticalqty" -ge "1" ]]; then
echo "CRITICAL: ${criticalqty}"
exit 2
else
echo "OK: Powersupply $okqty "
exit 0
fi
#Model
elif [[ "$check" == "sysinfo" ]]; then
model=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.12.0 | awk '{print $4}' | sed 's/^"\(.*\).$/\1/')
hdnum=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.10.0 | awk '{print $4}')
count=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.16.0 | awk '{print $4}')
name=$($mysnmpcheck .1.3.6.1.4.1.24681.1.2.13.0 | awk '{print $4}' | sed 's/^"\(.*\)$/\1/')
firmware=$($mysnmpcheck .1.3.6.1.2.1.47.1.1.1.1.9.1 | awk '{print $4}' | sed 's/^"\(.*\)$/\1/')
netuptime=$($mysnmpcheck .1.3.6.1.2.1.1.3.0 | awk '{print $5, $6, $7, $8}')
sysuptime=$($mysnmpcheck .1.3.6.1.2.1.25.1.1.0 | awk '{print $5, $6, $7, $8}')
echo NAS $name, Model $model, Firmware $firmware, Max HD number $hdnum, No. volume $count, system Uptime $sysuptime, Network Uptime $netuptime
exit 0
#statements
#
else
echo -e "\nUnknown check!" && exit "3"
fi
exit 0
Eigene Icinga-Constants erstellen.
vi /opt/docker-compose-icinga/icinga2.conf.d/constants.conf
Inhalt:
# My Custom Plugins const CustomPluginDir = "custom_data/custom.conf.d/my-plugins/"
Nun noch den Icinga stack neu starten.
cd /opt/docker-compose-icinga docker compose restart
Jetzt kann der neu definierte Check im Director normal verwendet werden.
Plugin Check Commandcheck_qnap2/custom_data/custom.conf.d/my-plugins/check_qnap2.sh-HHostaddressZeichenkette$qnap_address$0Icinga-DSLJa-CCommunityZeichenkette$qnap_community$1Icinga-DSLJa-aArgumentZeichenkette$qnap_argument$1Icinga-DSLJaqnap_addressqnap_addressStringSichtbarqnap_communityqnap_communityStringVerstecktqnap_argumentqnap_argumentStringSichtbarcpuload
Damit Icinga Benachrichtungen per Mail senden kann muss man sich eine msmtprc Datei erstellt werden.
Diese steuert den lokalen Mailbefehl msmtp.
cd /opt/docker-compose-icinga/ mkdir -p etc_data/msmtp/ vi etc_data/msmtp/msmtprc
Hier diesen Inhalt einfügen und nach belieben anpassen.
# Set default values: use the mail submission port 587, and always use TLS. # On this port, TLS is activated via STARTTLS. defaults tls on #tls_starttls on tls_trust_file /etc/ssl/certs/ca-certificates.crt logfile /var/log/msmtp.log #aliases /etc/aliases # Define a mail account account <NAME> # Host name of the SMTP server host <MAILHOST> port <MAILHOST_PORT> tls_starttls <on|off> # Envelope-from address from <ABSENDERADRESSE> # Authentication auth on user <USERNAME> #password <PLAINTEXT_PASSWORD> passwordeval gpg2 --no-tty -q -d /etc/.msmtp-cred.gpg account default: <ACCOUNT_NAME>
Dann erstellt man sich die verschlüsslete Datei mit dem Passwort.
vi etc_data/msmtp/.msmtp-cred.txt
Hier das Passwort einfügen und danach verschlüsseln.
gpg -c .msmtp-cred.txt
Die Passphrase merken, wird im Container jedes mal wenn er neu gestartet wurde abgefragt.
Möchte man gpg nicht verwenden, dann einfach wie oben beschrieben das Passwort als Plaintext einfügen.
Den Inhalt kann man so prüfen.
<cocde bash>gpg -d –no-tty -q .msmtp-cred.txt.gpg</code>
Die beiden Dateien msmtp und .msmtp-cred.php müssen noch in den „icinga2“ container eingebunden werden.
Dazu in der „docker-compose.yml“ unter dem Service „icinga2“ folgende Volumes hinzufügen.
- ./etc_data/msmtp/msmtprc:/etc/msmtprc:ro - ./etc_data/msmtp/.msmtp-cred.txt.gpg:/etc/.msmtp-cred.txt.gpg:ro
Jetzt noch die Konfiguration bekannt machen.
docker compose stop && docker compose up -d
Die Grundlage zum Senden von Mails ist nun vorhanden.
Man kann im „icinga2“ container das senden mit diesem Befehl testen.
echo "Irgend ein Text" | mail -a "From: <ABSENDER_ADRESSE" -s "Mailtest" <EMPFAENGER_ADRESSE> --debug-level=all
Jetzt noch IcingaWeb konfigurieren.
Wenn nun noch der Host oder Service die Benachrichtigungen aktiviert hat, werden Mails gesendet.
Man kann in IcingaWeb an einem Host oder Server eine Benutzerdefinierte Benachrichtigung senden und dann im Log des Containers das senden der Mail sehen.
Dazu müssen Benutzerdefinierte Benachrichtigungen oben überall als Änderungsstypen angegeben werden.
Die Logs des Containers kann man sich so anzeigen.
cd /opt/docker-compose-icinga docker compose logs -f icinga2
Mit Graphite kann man Performancedaten der einzelnen Checks grafisch darstellen.
Zum einbinden von Graphite folgendes tun.
cd /opt/docker-compose-icinga vi docker-compose.yml
icingaweb.enabledModules: director, icingadb, incubator, graphite
graphite:
container_name: graphite
image: graphiteapp/graphite-statsd
restart: always
ports:
- "50080:80"
- "52003-52004:2003-2004"
- "52023-52024:2023-2024"
- "58125:8125/udp"
- "58126:8126"
hostname: graphite
volumes:
#- ./backup:/opt/backup
#- ./conf/graphite/conf:/opt/graphite/conf
- ./graphite/graphite/storage:/opt/graphite/storage
#- ./conf/webapp/graphite/functions/custom:/opt/graphite/webapp/graphite/functions/custom
#- ./conf/nginx:/etc/nginx
#- ./conf/statsd/config:/opt/statsd/config
#- ./conf/logrotate.d:/etc/logrotate.d
#- ./var/log:/var/log
#- ./var/lib/redis:/var/lib/redis
environment:
- GRAPHITE_TIME_ZONE=Europe/Berlin
- GRAPHITE_DATE_FORMAT=%m/%d
- COLLECTD=1
mkdir -p ./graphite/graphite/storage
mkdir -p ./icinga2.conf.d/features-enabled
/**
* The GraphiteWriter type writes check result metrics and
* performance data to a graphite tcp socket.
*/
object GraphiteWriter "graphite" {
host = "graphite"
port = 2003
}
docker compose stop && docker compose up -d