Zabbix

Deployment
# mysql server for zabbix
docker run --name mysql -p 3306:3306 -v /etc/my.cnf:/etc/my.cnf -v /var/lib/mysql:/var/lib/mysql --restart always -d mysql/mysql-server

# install zabbix server
docker run --name zabbix-server -p 10051:10051 -v /data/zabbix/alertscripts:/usr/lib/zabbix/alertscripts -v /data/zabbix/externalscripts:/usr/lib/zabbix/externalscripts -e ZBX_STARTPOLLERS=20 -e ZBX_STARTPINGERS=10 -e ZBX_STARTDISCOVERERS=5 -e DB_SERVER_HOST="127.0.0.1" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="[email protected]" -d zabbix/zabbix-server-mysql
# install curl for telegram alert script
docker exec -ti zabbix-server bash -c 'apk update && apk upgrade && apk add curl openssl'

# install zabbix web
docker run --name zabbix-web -p 80:80 -e DB_SERVER_HOST="127.0.0.1" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="[email protected]" -e ZBX_SERVER_HOST="127.0.0.1" -e TZ="Europe/Moscow" -d zabbix/zabbix-web-nginx-mysql
/data/zabbix/alertscripts/telegram.sh
#!/bin/bash

if [ $# -lt 2 ] ; then echo 'Error. Minimum 2 params needed.' && exit 1 ; fi

#export https_proxy=http://proxy-server-if-needed:3128

TO=$1
SUBJECT=$2
MESSAGE=$3
TIMEOUT="10"
TOKEN="xxxxxxxxxx:xxxxxx-your-token-here-xxxx"

curl -s --max-time $TIMEOUT -X POST "https://api.telegram.org/bot$TOKEN/sendMessage" -d chat_id="$TO" -d text="$SUBJECT" | grep -q '"ok":false,'
if [ $? -eq 0 ] ; then exit 1 ; fi
exit 0
backup db and files
#!/bin/bash

MAXBACKUPS=7
BACKUPDIR=/data/backup/
USER=zabbix
[email protected]
DBNAME=zabbix

cd $BACKUPDIR

# cleanup old backups
ls -A1t | grep zabbix-schema | tail -n +$MAXBACKUPS | xargs rm
ls -A1t | grep zabbix-sqlbkp | tail -n +$MAXBACKUPS | xargs rm
ls -A1t | grep zabbix-files  | tail -n +$MAXBACKUPS | xargs rm

# backup prefs folders
tar -zcvf zabbix-files-`date +"%Y%m%d.%H%M%S"`.prefs.tar.gz /data/switches /etc/zabbix /usr/lib/zabbix /etc/sudoers.d/zabbix /etc/my.cnf /etc/crontab/etc/httpd /etc/sysconfig/iptables

# backup db schema
mysqldump -h 127.0.0.1 -u$USER -p$PASSWORD $DBNAME --no-data | gzip > $DBNAME-schema-`date +"%Y%m%d.%H%M%S"`.sql.gz

# backup db data (without monitoring data, only customizations)
mysqldump --lock-tables -h 127.0.0.1 -u$USER -p$PASSWORD $DBNAME \
        --ignore-table=$DBNAME.acknowledges \
        --ignore-table=$DBNAME.alerts \
        --ignore-table=$DBNAME.auditlog \
        --ignore-table=$DBNAME.auditlog_details \
        --ignore-table=$DBNAME.escalations \
        --ignore-table=$DBNAME.events \
        --ignore-table=$DBNAME.history \
        --ignore-table=$DBNAME.history_log \
        --ignore-table=$DBNAME.history_str \
        --ignore-table=$DBNAME.history_str_sync \
        --ignore-table=$DBNAME.history_sync \
        --ignore-table=$DBNAME.history_text \
        --ignore-table=$DBNAME.history_uint \
        --ignore-table=$DBNAME.history_uint_sync \
        --ignore-table=$DBNAME.trends \
        --ignore-table=$DBNAME.trends_uint \
        | gzip > $DBNAME-sqlbkp_`date +"%Y%m%d.%H%M%S"`.sql.gz

exit 0
restore db:
gunzip < zabbix-schema-20170205.231242.sql.gz | mysql -uroot zabbix
gunzip < zabbix-sqlbkp-20170205.231242.sql.gz | mysql -uroot zabbix