INT 21h

Hi, I am Vladimir Smagin, SysAdmin and Kaptain. Telegram Email / GIT / Thingiverse / RSS / GPG

Zabbix: monitor bash script results

№ 9533 В разделе "Sysadmin" от November 10th, 2018,
В подшивках: , ,

Install zabbix-agent (sometimes zabbix-sender) package to your server that contains zabbix_sender. Now add some exit codes checks after every monitored command.

#!/bin/bash
set -e
source /etc/profile

ftp_user="username"
ftp_pass="pas5w0rd"
ftp_serv="myftp.server.ru"

pg_user="dbusername"
pg_pass="dbpasswd"
pg_host="127.0.0.1"
pg_port="5432"
pg_dbname="mydatabase"

weekday=$(date '+%w') # 7 days history
history=$weekday

docker exec -it pg2-server su -c "pg_dump postgresql://${pg_user}:${pg_pass}@${pg_host}:${pg_port}/ \
    ${pg_dbname}" postgres |gzip -7 > /tmp/db_backup_${pg_dbname}_${history}.sql.gz
if [ $? -ne 0 ]
then
    echo "pg_dump failed to dump"
    /usr/bin/zabbix_sender -z zabbix.server.ru -s pg2-server -k pgdumper.dump -o failed
    rm -f /tmp/db_backup_${pg_dbname}_${history}.sql.gz
    exit 1
else
    /usr/bin/zabbix_sender -z zabbix.server.ru -s pg2-server -k pgdumper.dump -o successful
    curl --upload-file /tmp/db_backup_${pg_dbname}_${history}.sql.gz ftp://${ftp_user}:${ftp_pass}@${ftp_serv}/
    if [ $? -ne 0 ]
        then
            echo "curl failed to upload dumped file"
            /usr/bin/zabbix_sender -z zabbix.server.ru -s pg2-server -k pgdumper.upload -o failed
            rm -f /tmp/db_backup_${pg_dbname}_${history}.sql.gz
            exit 1
        fi
    /usr/bin/zabbix_sender -z zabbix.server.ru -s pg2-server -k pgdumper.upload -o successful
    rm -f /tmp/db_backup_${pg_dbname}_${history}.sql.gz
fi

Create template

Add your monitored items

And add triggers to raise exceptions

You can combine items in one trigger

Do not forget to activate email notices.

Нет комментариев »

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Яндекс.Метрика

Fortune cookie: Today's spam: No More Average Lifestyle