How can I track the failure of rsync with Zabbix?

I have a situation where I need to control (with Zabbix) if the rsync job failed.

I want to say that I paste the exit code into a file in the source file and control this, but I have not found a good way to do this.

Does anyone have an idea of ​​a method that I can perform for this monitoring?

+4
source share
2 answers

I decided to do 3 things.

1 - Create a script to execute rsync on cron

#!/bin/bash +x
# Put your own rsync command on line below 
rsync -rlptv --delete-after root@serverA:/some_dir/ /another_dir/ > /lalla_dir/my.log

# Check if rsync was executed with success
if [ $? = 0 ];then
# If true, send a random number to log file and status=ok message
echo $[ 1 + $[ RANDOM % 1000 ]] >> /lalla_dir/my.log
echo "Status = OK" >> /lalla_dir/my.log
# If false, send a random number to log file and status=ERROR message
else
echo $[ 1 + $[ RANDOM % 1000 ]] >> /lalla_dir/my.log
echo "Status = ERROR" >> /lalla_dir/my.log
fi

2 - Create two Itens on Zabbix

A - check_sum my.log( , script , ,

Zabbix

vfs.file.cksum[]

B - OK.

Zabbix

vfs.file.regmatch[/lalla_dir/my.log,Status = OK]

3 - .

{my-server:vfs.file.cksum[/lalla_dir/my.log].change()}=0
or
{my-server:vfs.file.regmatch[/lalla_dir/my.log,Status = OK].last()}=0

, " = ", , erro ( ) (, cron)

- has has have, they...

+6

. , :

897
Status=OK,Message=

zabbix :

{svr1.xxxx.com:vfs.file.exists[/data/logs/db-backup.log].change()}=0 or {svr1.xxxx.com:vfs.file.cksum[/data/logs/db-backup.log].change()}=0 or {svr1.xxxx.com:vfs.file.regmatch[/data/logs/db-backup.log,Status=ERROR].last()}=1

script , 4:10 :

jbaptiste@svr1:/data/logs$ ls -lth
total 12K
-rw-r--r-- 1 root root  23 Mar 20 04:10 db-backup.log

zabbix 5 , , - :

Trigger: DB - Check backup last run status 
Trigger status: PROBLEM 
Trigger severity: Warning 
Trigger URL: 

Item values: 

1. Backup file exists check (svr1.xxxx.com:vfs.file.exists[/data/logs/db-backup.log]): 1 
2. Backup file checksum (svr1.xxxx.com:vfs.file.cksum[/data/logs/db-backup.log]): 1864703203 
3. Backup run status code (svr1.xxxx.com:vfs.file.regmatch[/data/logs/db-backup.log,Status=ERROR]): 0 

zabbix, , , , .

: - , .

- - ?

0

Source: https://habr.com/ru/post/1625505/


All Articles