From 995fadbab98c170044034c93ea2cb873c87ce94b Mon Sep 17 00:00:00 2001 From: ssv1982 Date: Wed, 17 Jun 2015 10:39:46 +0700 Subject: [PATCH 1/5] fix postgresql sql command and zabbix template --- bacula-template.xml | 6 +++--- bacula-zabbix.bash | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bacula-template.xml b/bacula-template.xml index d6d3aa4..d841512 100644 --- a/bacula-template.xml +++ b/bacula-template.xml @@ -208,7 +208,7 @@ 0 0 - KB/s + bps 0 @@ -466,7 +466,7 @@ 0 0 - KB/s + bps 0 @@ -724,7 +724,7 @@ 0 0 - KB/s + bps 0 diff --git a/bacula-zabbix.bash b/bacula-zabbix.bash index 30bb7d2..da2b74f 100644 --- a/bacula-zabbix.bash +++ b/bacula-zabbix.bash @@ -61,12 +61,19 @@ $zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacul if [ $? -ne 0 ] ; then return=$(($return+4)) ; fi # Get from database the time spent by the Job and send it to Zabbix server -baculaJobTime=$($sql "select timestampdiff(second,StartTime,EndTime) from Job where JobId=$baculaJobId;" 2>/dev/null) + +case $baculaDbSgdb in + M) baculaJobTime=$($sql "select timestampdiff(second,StartTime,EndTime) from Job where JobId=$baculaJobId;" 2>/dev/null);; + P) baculaJobTime=$($sql "select EXTRACT(epoch from (EndTime-StartTime)) from Job where JobId=$baculaJobId;" 2>/dev/null);; +esac $zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.time" -o $baculaJobTime >/dev/null 2>&1 if [ $? -ne 0 ] ; then return=$(($return+8)) ; fi # Get Job speed from database and send it to Zabbix server -baculaJobSpeed=$($sql "select round(JobBytes/timestampdiff(second,StartTime,EndTime)/1024,2) from Job where JobId=$baculaJobId;" 2>/dev/null) +case $baculaDbSgdb in + M) baculaJobSpeed=$($sql "select round(JobBytes/timestampdiff(second,StartTime,EndTime)) from Job where JobId=$baculaJobId;" 2>/dev/null);; + P) baculaJobSpeed=$($sql "select round(JobBytes/EXTRACT(epoch from (EndTime-StartTime))) from Job where JobId=$baculaJobId;" 2>/dev/null);; +esac $zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.speed" -o $baculaJobSpeed >/dev/null 2>&1 if [ $? -ne 0 ] ; then return=$(($return+16)) ; fi From d7221311eb8107a604d31bef9e69bf793fe9a55e Mon Sep 17 00:00:00 2001 From: ssv1982 Date: Wed, 17 Jun 2015 10:42:12 +0700 Subject: [PATCH 2/5] fix string for psql --- bacula-zabbix.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bacula-zabbix.bash b/bacula-zabbix.bash index da2b74f..568b5e0 100644 --- a/bacula-zabbix.bash +++ b/bacula-zabbix.bash @@ -12,7 +12,7 @@ if [ ! -x $zabbixSender ] ; then exit 5 ; fi # Chose which database command to use case $baculaDbSgdb in - P) sql="PGPASSWORD=$baculaDbPass /usr/bin/psql -h$baculaDbAddr -p$baculaDbPort -U$baculaDbUser -d$baculaDbName -c" ;; + P) sql="PGPASSWORD=$baculaDbPass /usr/bin/psql -h$baculaDbAddr -p$baculaDbPort -U$baculaDbUser -d$baculaDbName -Ta-c" ;; M) sql="/usr/bin/mysql -NB -h$baculaDbAddr -P$baculaDbPort -u$baculaDbUser -p$baculaDbPass -D$baculaDbName -e" ;; *) exit 7 ;; esac From 9f7d9046a4bc933f9e0f16801bc925178debea72 Mon Sep 17 00:00:00 2001 From: ssv1982 Date: Wed, 17 Jun 2015 10:43:20 +0700 Subject: [PATCH 3/5] fix string for psql --- bacula-zabbix.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bacula-zabbix.bash b/bacula-zabbix.bash index 568b5e0..eb1c32e 100644 --- a/bacula-zabbix.bash +++ b/bacula-zabbix.bash @@ -12,7 +12,7 @@ if [ ! -x $zabbixSender ] ; then exit 5 ; fi # Chose which database command to use case $baculaDbSgdb in - P) sql="PGPASSWORD=$baculaDbPass /usr/bin/psql -h$baculaDbAddr -p$baculaDbPort -U$baculaDbUser -d$baculaDbName -Ta-c" ;; + P) sql="PGPASSWORD=$baculaDbPass /usr/bin/psql -h$baculaDbAddr -p$baculaDbPort -U$baculaDbUser -d$baculaDbName -Ta -c" ;; M) sql="/usr/bin/mysql -NB -h$baculaDbAddr -P$baculaDbPort -u$baculaDbUser -p$baculaDbPass -D$baculaDbName -e" ;; *) exit 7 ;; esac From e7af2f40ea7f5444efef03c9693eadc67d59c113 Mon Sep 17 00:00:00 2001 From: ssv1982 Date: Thu, 18 Jun 2015 16:19:38 +0700 Subject: [PATCH 4/5] Added two zabbix template (low level discovery): 1) Template Bacula Clients - get list bacula clients form bacula catalog and create hosts in zabbix 2) Template Bacula - create items per jobs and level in created hosts Added scripts for discovery clients and jobs modified bacula-zabbix.bash for work with new zabbix templates --- bacula-template.xml | 2817 ++++++++++++++++--------------------------- bacula-zabbix.bash | 24 +- bacula-zabbix.conf | 2 +- bacula.pl | 29 + bacula_hosts.pl | 40 + zabbix_agentd.conf | 3 + 6 files changed, 1096 insertions(+), 1819 deletions(-) mode change 100644 => 100755 bacula-zabbix.bash create mode 100755 bacula.pl create mode 100755 bacula_hosts.pl create mode 100644 zabbix_agentd.conf diff --git a/bacula-template.xml b/bacula-template.xml index d841512..7912e65 100644 --- a/bacula-template.xml +++ b/bacula-template.xml @@ -1,10 +1,10 @@ 2.0 - 2015-05-01T15:46:08Z + 2015-06-18T09:15:36Z - Templates + Bacula @@ -14,628 +14,26 @@ - Templates - - - - - Bacula - - - - - Backup Differential Bytes - 2 - - 0 - - bacula.diff.job.bytes - 0 - 90 - 365 - 0 - 3 - - B - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Differential Compression - 2 - - 0 - - bacula.diff.job.compr - 0 - 90 - 365 - 0 - 0 - - - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Differential Files - 2 - - 0 - - bacula.diff.job.files - 0 - 90 - 365 - 0 - 3 - - - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Differential OK - 2 - - 0 - - bacula.diff.job.status - 0 - 90 - 365 - 0 - 3 - - - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Differential Speed - 2 - - 0 - - bacula.diff.job.speed - 0 - 90 - 365 - 0 - 0 - - bps - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Differential Time - 2 - - 0 - - bacula.diff.job.time - 0 - 90 - 365 - 0 - 3 - - s - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Full Bytes - 2 - - 0 - - bacula.full.job.bytes - 0 - 90 - 365 - 0 - 3 - - B - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Full Compression - 2 - - 0 - - bacula.full.job.compr - 0 - 90 - 365 - 0 - 0 - - - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Full Files - 2 - - 0 - - bacula.full.job.files - 0 - 90 - 365 - 0 - 3 - - - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Full OK - 2 - - 0 - - bacula.full.job.status - 0 - 90 - 365 - 0 - 3 - - - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Full Speed - 2 - - 0 - - bacula.full.job.speed - 0 - 90 - 365 - 0 - 0 - - bps - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Full Time - 2 - - 0 - - bacula.full.job.time - 0 - 90 - 365 - 0 - 3 - - s - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Incremental Bytes - 2 - - 0 - - bacula.incr.job.bytes - 0 - 90 - 365 - 0 - 3 - - B - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Incremental Compression - 2 - - 0 - - bacula.incr.job.compr - 0 - 90 - 365 - 0 - 0 - - - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - + Bacula + + + + + Bacula + + + - Backup Incremental Files - 2 + Bacula Director is running + 0 0 - bacula.incr.job.files - 0 + proc.num[{$BAREOS.DIR}] + 30 90 365 - 0 + 1 3 @@ -669,16 +67,16 @@ - Backup Incremental OK - 2 + Bacula File is running + 0 0 - bacula.incr.job.status - 0 + proc.num[{$BAREOS.FD}] + 30 90 365 - 0 + 1 3 @@ -712,102 +110,16 @@ - Backup Incremental Speed - 2 - - 0 - - bacula.incr.job.speed - 0 - 90 - 365 - 0 - 0 - - bps - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Backup Incremental Time - 2 - - 0 - - bacula.incr.job.time - 0 - 90 - 365 - 0 - 3 - - s - 0 - - - 0 - 0 - - 0 - - 1 - - - - 0 - 0 - - - - - - - 0 - - - Bacula - - - - - - - Bacula Director is running + Bacula Storage is running 0 0 - proc.num[{$BACULA.DIR}] + proc.num[{$BAREOS.SD}] 30 90 365 - 0 + 1 3 @@ -840,21 +152,17 @@ - - Bacula File is running + + + + bacula jobs 0 - 0 - proc.num[{$BACULA.FD}] + bacula.jobs[{HOST.HOST}] 30 - 90 - 365 0 - 3 - - 0 0 @@ -862,42 +170,957 @@ 0 - 1 - 0 0 + + 0 + + + + 30 - 0 - - - Bacula - - - - - - - Bacula Storage is running + + + Backup Differential Job {#JOBNAME} on {#CLIENTNAME} Bytes + 2 + + 0 + + bacula.diff.job.bytes[{#JOBNAME}] + 0 + 90 + 365 + 0 + 3 + + B + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Differential Job {#JOBNAME} on {#CLIENTNAME} Files + 2 + + 0 + + bacula.diff.job.files[{#JOBNAME}] + 0 + 90 + 365 + 0 + 3 + + + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Differential Job {#JOBNAME} on {#CLIENTNAME} OK + 2 + + 0 + + bacula.diff.job.status[{#JOBNAME}] + 0 + 90 + 365 + 0 + 3 + + + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Differential Job {#JOBNAME} on {#CLIENTNAME} Speed + 2 + + 0 + + bacula.diff.job.speed[{#JOBNAME}] + 0 + 90 + 365 + 0 + 0 + + bps + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Differential Job {#JOBNAME} on {#CLIENTNAME} Time + 2 + + 0 + + bacula.diff.job.time[{#JOBNAME}] + 0 + 90 + 365 + 0 + 3 + + s + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Full Job {#JOBNAME} on {#CLIENTNAME} Bytes + 2 + + 0 + + bacula.full.job.bytes[{#JOBNAME}] + 0 + 90 + 365 + 0 + 3 + + B + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Full Job {#JOBNAME} on {#CLIENTNAME} Files + 2 + + 0 + + bacula.full.job.files[{#JOBNAME}] + 0 + 90 + 365 + 0 + 3 + + + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Full Job {#JOBNAME} on {#CLIENTNAME} OK + 2 + + 0 + + bacula.full.job.status[{#JOBNAME}] + 0 + 90 + 365 + 0 + 3 + + + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Full Job {#JOBNAME} on {#CLIENTNAME} Speed + 2 + + 0 + + bacula.full.job.speed[{#JOBNAME}] + 0 + 90 + 365 + 0 + 0 + + bps + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Full Job {#JOBNAME} on {#CLIENTNAME} Time + 2 + + 0 + + bacula.full.job.time[{#JOBNAME}] + 0 + 90 + 365 + 0 + 3 + + s + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Incremental Job {#JOBNAME} on {#CLIENTNAME} Bytes + 2 + + 0 + + bacula.incr.job.bytes[{#JOBNAME}] + 0 + 90 + 365 + 0 + 3 + + B + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Incremental Job {#JOBNAME} on {#CLIENTNAME} Files + 2 + + 0 + + bacula.incr.job.files[{#JOBNAME}] + 0 + 90 + 365 + 0 + 3 + + + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Incremental Job {#JOBNAME} on {#CLIENTNAME} OK + 2 + + 0 + + bacula.incr.job.status[{#JOBNAME}] + 0 + 90 + 365 + 0 + 3 + + + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Incremental Job {#JOBNAME} on {#CLIENTNAME} Speed + 2 + + 0 + + bacula.incr.job.speed[{#JOBNAME}] + 0 + 90 + 365 + 0 + 0 + + bps + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + Backup Incremental Job {#JOBNAME} on {#CLIENTNAME} Time + 2 + + 0 + + bacula.incr.job.time[{#JOBNAME}] + 0 + 90 + 365 + 0 + 3 + + s + 0 + + + 0 + 0 + + 0 + + 1 + + + + 0 + 0 + + + + + + + 0 + + + Bacula + + + + + + + + + {Template Bacula:bacula.diff.job.status[{#JOBNAME}].last()}>1 + Backup Differential Job {#JOBNAME} on {#CLIENTNAME} FAIL + + 0 + 2 + + 0 + + + {Template Bacula:bacula.full.job.status[{#JOBNAME}].last()}>1 + Backup Full Job {#JOBNAME} on {#CLIENTNAME} FAIL + + 0 + 2 + + 0 + + + {Template Bacula:bacula.incr.job.status[{#JOBNAME}].last()}>1 + Backup Incremental Job {#JOBNAME} on {#CLIENTNAME} FAIL + + 0 + 2 + + 0 + + + + + Backup Differential Job {#JOBNAME} on {#CLIENTNAME} - Bytes transferred + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 1 + 0 + C80000 + 0 + 2 + 0 + + Template Bacula + bacula.incr.job.status[{#JOBNAME}] + + + + 0 + 5 + 00C800 + 0 + 2 + 0 + + Template Bacula + bacula.diff.job.bytes[{#JOBNAME}] + + + + + + Backup Differential Job {#JOBNAME} on {#CLIENTNAME} - Transfer rate + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 0 + 5 + 00C800 + 0 + 2 + 0 + + Template Bacula + bacula.diff.job.speed[{#JOBNAME}] + + + + + + Backup Full Job {#JOBNAME} on {#CLIENTNAME}- Bytes transferred + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 0 + 0 + 00C800 + 0 + 2 + 0 + + Template Bacula + bacula.full.job.bytes[{#JOBNAME}] + + + + + + Backup Full Job {#JOBNAME} on {#CLIENTNAME}- Transfer rate + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 0 + 0 + 00C800 + 0 + 2 + 0 + + Template Bacula + bacula.full.job.speed[{#JOBNAME}] + + + + + + Backup Incremental Job {#JOBNAME} on {#CLIENTNAME} - Bytes transferred + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 0 + 5 + 00C800 + 1 + 2 + 0 + + Template Bacula + bacula.incr.job.bytes[{#JOBNAME}] + + + + 1 + 0 + C80000 + 0 + 2 + 0 + + Template Bacula + bacula.incr.job.status[{#JOBNAME}] + + + + + + Backup Incremental Job {#JOBNAME} on {#CLIENTNAME} - Transfer rate + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 0 + 0 + 00C800 + 0 + 2 + 0 + + Template Bacula + bacula.incr.job.speed[{#JOBNAME}] + + + + + + + + + + + {$BAREOS.DIR} + bareos-dir + + + {$BAREOS.FD} + bareos-fd + + + {$BAREOS.SD} + bareos-sd + + + + + + - {Template Bacula:bacula.diff.job.status.last()}>1 - Backup Differential FAIL in {HOST.NAME} - - 0 - 3 - - 0 - - - - {Template Bacula:bacula.full.job.status.last()}>1 - Backup Full FAIL in {HOST.NAME} - - 0 - 4 - - 0 - - - - {Template Bacula:bacula.incr.job.status.last()}>1 - Backup Incremental FAIL in {HOST.NAME} - - 0 - 2 - - 0 - - - - {Template Bacula:proc.num[{$BACULA.DIR}].last()}=0 + {Template Bacula:proc.num[{$BAREOS.DIR}].last()}=0 Bacula Director is DOWN in {HOST.NAME} 0 - 5 + 4 0 - {Template Bacula:proc.num[{$BACULA.FD}].last()}=0 + {Template Bacula:proc.num[{$BAREOS.FD}].last()}=0 Bacula File is DOWN in {HOST.NAME} 0 @@ -1350,676 +1209,14 @@ - {Template Bacula:proc.num[{$BACULA.SD}].last()}=0 + {Template Bacula:proc.num[{$BAREOS.SD}].last()}=0 Bacula Storage is DOWN in {HOST.NAME} 0 - 5 + 4 0 - - - Backup Differential - Bytes transferred - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - 9999FF - 0 - 2 - 0 - - Template Bacula - bacula.diff.job.bytes - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.diff.job.status - - - - - - Backup Differential - Compression rate - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - FF9999 - 0 - 2 - 0 - - Template Bacula - bacula.diff.job.compr - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.diff.job.status - - - - - - Backup Differential - Elapsed time - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - 00EEEE - 0 - 2 - 0 - - Template Bacula - bacula.diff.job.time - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.diff.job.status - - - - - - Backup Differential - Files transferred - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - 00C800 - 0 - 2 - 0 - - Template Bacula - bacula.diff.job.files - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.diff.job.status - - - - - - Backup Differential - Transfer rate - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - CCCC00 - 0 - 2 - 0 - - Template Bacula - bacula.diff.job.speed - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.diff.job.status - - - - - - Backup Full - Bytes transferred - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.full.job.status - - - - 0 - 5 - 9999FF - 0 - 2 - 0 - - Template Bacula - bacula.full.job.bytes - - - - - - Backup Full - Compression rate - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - FF9999 - 0 - 2 - 0 - - Template Bacula - bacula.full.job.compr - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.full.job.status - - - - - - Backup Full - Elapsed time - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - 00EEEE - 0 - 2 - 0 - - Template Bacula - bacula.full.job.time - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.full.job.status - - - - - - Backup Full - Files transferred - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - 00C800 - 0 - 2 - 0 - - Template Bacula - bacula.full.job.files - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.full.job.status - - - - - - Backup Full - Transfer rate - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - CCCC00 - 0 - 2 - 0 - - Template Bacula - bacula.full.job.speed - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.full.job.status - - - - - - Backup Incremental - Bytes transferred - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - 9999FF - 0 - 2 - 0 - - Template Bacula - bacula.incr.job.bytes - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.incr.job.status - - - - - - Backup Incremental - Compression rate - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - FF9999 - 0 - 2 - 0 - - Template Bacula - bacula.incr.job.compr - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.incr.job.status - - - - - - Backup Incremental - Elapsed time - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - 00EEEE - 0 - 2 - 0 - - Template Bacula - bacula.incr.job.time - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.incr.job.status - - - - - - Backup Incremental - Files transferred - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - 00C800 - 0 - 2 - 0 - - Template Bacula - bacula.incr.job.files - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.incr.job.status - - - - - - Backup Incremental - Transfer rate - 900 - 200 - 0.0000 - 100.0000 - 1 - 1 - 0 - 1 - 0 - 0.0000 - 0.0000 - 1 - 0 - 0 - 0 - - - 0 - 5 - CCCC00 - 0 - 2 - 0 - - Template Bacula - bacula.incr.job.speed - - - - 1 - 2 - C80000 - 0 - 2 - 0 - - Template Bacula - bacula.incr.job.status - - - - - diff --git a/bacula-zabbix.bash b/bacula-zabbix.bash old mode 100644 new mode 100755 index eb1c32e..ef53d3c --- a/bacula-zabbix.bash +++ b/bacula-zabbix.bash @@ -1,7 +1,7 @@ #!/bin/bash # Import configuration file -source /etc/bacula/bacula-zabbix.conf +source /etc/bareos/bacula-zabbix.conf # Get Job ID from parameter baculaJobId="$1" @@ -12,15 +12,17 @@ if [ ! -x $zabbixSender ] ; then exit 5 ; fi # Chose which database command to use case $baculaDbSgdb in - P) sql="PGPASSWORD=$baculaDbPass /usr/bin/psql -h$baculaDbAddr -p$baculaDbPort -U$baculaDbUser -d$baculaDbName -Ta -c" ;; + P) sql="/usr/bin/psql -h$baculaDbAddr -p$baculaDbPort -U$baculaDbUser -d$baculaDbName -tA -c" ;; M) sql="/usr/bin/mysql -NB -h$baculaDbAddr -P$baculaDbPort -u$baculaDbUser -p$baculaDbPass -D$baculaDbName -e" ;; *) exit 7 ;; esac # Get Job type from database, then if it is a backup job, proceed, if not, exit baculaJobType=$($sql "select Type from Job where JobId=$baculaJobId;" 2>/dev/null) + if [ "$baculaJobType" != "B" ] ; then exit 9 ; fi + # Get Job level from database and classify it as Full, Differential, or Incremental baculaJobLevel=$($sql "select Level from Job where JobId=$baculaJobId;" 2>/dev/null) case $baculaJobLevel in @@ -30,6 +32,7 @@ case $baculaJobLevel in *) exit 11 ;; esac + # Get Job exit status from database and classify it as OK, OK with warnings, or Fail baculaJobStatus=$($sql "select JobStatus from Job where JobId=$baculaJobId;" 2>/dev/null) if [ -z $baculaJobStatus ] ; then exit 13 ; fi @@ -43,21 +46,26 @@ esac baculaClientName=$($sql "select Client.Name from Client,Job where Job.ClientId=Client.ClientId and Job.JobId=$baculaJobId;" 2>/dev/null) if [ -z $baculaClientName ] ; then exit 15 ; fi +# Get Jobs's name from database +baculaJobName=$($sql "select name from Job where Job.JobId=$baculaJobId;") +if [ -z $baculaJobName ] ; then exit 15 ; fi + + # Initialize return as zero return=0 # Send Job exit status to Zabbix server -$zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.status" -o $status >/dev/null 2>&1 +$zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.status[$baculaJobName]" -o $status >/dev/null 2>&1 if [ $? -ne 0 ] ; then return=$(($return+1)) ; fi # Get from database the number of bytes transferred by the Job and send it to Zabbix server baculaJobBytes=$($sql "select JobBytes from Job where JobId=$baculaJobId;" 2>/dev/null) -$zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.bytes" -o $baculaJobBytes >/dev/null 2>&1 +$zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.bytes[$baculaJobName]" -o $baculaJobBytes >/dev/null 2>&1 if [ $? -ne 0 ] ; then return=$(($return+2)) ; fi # Get from database the number of files transferred by the Job and send it to Zabbix server baculaJobFiles=$($sql "select JobFiles from Job where JobId=$baculaJobId;" 2>/dev/null) -$zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.files" -o $baculaJobFiles >/dev/null 2>&1 +$zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.files[$baculaJobName]" -o $baculaJobFiles >/dev/null 2>&1 if [ $? -ne 0 ] ; then return=$(($return+4)) ; fi # Get from database the time spent by the Job and send it to Zabbix server @@ -66,7 +74,7 @@ case $baculaDbSgdb in M) baculaJobTime=$($sql "select timestampdiff(second,StartTime,EndTime) from Job where JobId=$baculaJobId;" 2>/dev/null);; P) baculaJobTime=$($sql "select EXTRACT(epoch from (EndTime-StartTime)) from Job where JobId=$baculaJobId;" 2>/dev/null);; esac -$zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.time" -o $baculaJobTime >/dev/null 2>&1 +$zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.time[$baculaJobName]" -o $baculaJobTime >/dev/null 2>&1 if [ $? -ne 0 ] ; then return=$(($return+8)) ; fi # Get Job speed from database and send it to Zabbix server @@ -74,12 +82,12 @@ case $baculaDbSgdb in M) baculaJobSpeed=$($sql "select round(JobBytes/timestampdiff(second,StartTime,EndTime)) from Job where JobId=$baculaJobId;" 2>/dev/null);; P) baculaJobSpeed=$($sql "select round(JobBytes/EXTRACT(epoch from (EndTime-StartTime))) from Job where JobId=$baculaJobId;" 2>/dev/null);; esac -$zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.speed" -o $baculaJobSpeed >/dev/null 2>&1 +$zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.speed[$baculaJobName]" -o $baculaJobSpeed >/dev/null 2>&1 if [ $? -ne 0 ] ; then return=$(($return+16)) ; fi # Get Job compression rate from database and send it to Zabbix server baculaJobCompr=$($sql "select round(1-JobBytes/ReadBytes,2) from Job where JobId=$baculaJobId;" 2>/dev/null) -$zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.compr" -o $baculaJobCompr >/dev/null 2>&1 +$zabbixSender -z $zabbixSrvAddr -p $zabbixSrvPort -s $baculaClientName -k "bacula.$level.job.compr[$baculaJobName]" -o $baculaJobCompr >/dev/null 2>&1 if [ $? -ne 0 ] ; then return=$(($return+32)) ; fi # Exit with return status diff --git a/bacula-zabbix.conf b/bacula-zabbix.conf index 5d49a6f..73a3738 100644 --- a/bacula-zabbix.conf +++ b/bacula-zabbix.conf @@ -4,7 +4,7 @@ # Use 'P' for PostgreSQL baculaDbSgdb='M' -# IP address or FQDN of database server +# IP address or FQDN of database server or local socket path baculaDbAddr='127.0.0.1' # TCP port of database server diff --git a/bacula.pl b/bacula.pl new file mode 100755 index 0000000..b5e1e08 --- /dev/null +++ b/bacula.pl @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +$baculaDbUser='bareos'; +$baculaDbName='bareos'; + +#@qq=`/usr/bin/psql -U$User_Preferences{'bareosDbUser'} -d$User_Preferences{'bareosDbName'} -t -A -c "select job.name,client.name from job left join client on job.clientid=client.clientid group by job.name,client.name;"`; +@qq=`/usr/bin/psql -U$baculaDbUser -d$baculaDbName -t -A -c "select job.name,client.name from job left join client on job.clientid=client.clientid group by job.name,client.name having client.name='$ARGV[0]';"`; + +$first = 1; + +print "{\n"; +print "\t\"data\":[\n\n"; + +foreach $arg(@qq) +{ + $arg=~s/\n//; + @jobs=split(/\|/, $arg); + + print "\t,\n" if not $first; + $first = 0; + + print "\t{\n"; + print "\t\t\"{#JOBNAME}\":\"$jobs[0]\",\n"; + print "\t\t\"{#CLIENTNAME}\":\"$jobs[1]\"\n"; + print "\t}\n"; + +} +print "\n\t]\n"; +print "}\n"; diff --git a/bacula_hosts.pl b/bacula_hosts.pl new file mode 100755 index 0000000..7252e34 --- /dev/null +++ b/bacula_hosts.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl + +#for (`cat /etc/bareos/bareos-zabbix.conf`) { +# chomp; # no newline +# s/#.*//; # no comments +# s/^\s+//; # no leading white +# s/\s+$//; # no trailing white +# s/\'//g; +# my ($var, $value) = split(/\s*=\s*/, $_, 2); +# +# $User_Preferences{$var} = $value; +#} + +$baculaDbUser='bareos'; +$baculaDbName='bareos'; + +#@qq=`/usr/bin/psql -U$User_Preferences{'bareosDbUser'} -d$User_Preferences{'bareosDbName'} -t -A -c "select job.name,client.name from job left join client on job.clientid=client.clientid group by job.name,client.name;"`; +@qq=`/usr/bin/psql -U$baculaDbUser -d$baculaDbName -t -A -c "select name from client;"`; + +$first = 1; + +print "{\n"; +print "\t\"data\":[\n\n"; + +foreach $arg(@qq) +{ + $arg=~s/\n//; +# @jobs=split(/\|/, $arg); + + print "\t,\n" if not $first; + $first = 0; + + print "\t{\n"; + # print "\t\t\"{#JOBNAME}\":\"$jobs[0]\",\n"; + print "\t\t\"{#CLIENTNAME}\":\"$arg\"\n"; + print "\t}\n"; + +} +print "\n\t]\n"; +print "}\n"; diff --git a/zabbix_agentd.conf b/zabbix_agentd.conf new file mode 100644 index 0000000..b9e19ed --- /dev/null +++ b/zabbix_agentd.conf @@ -0,0 +1,3 @@ +UserParameter=bacula.jobs[*],/usr/bin/perl /etc/zabbix/scripts/bacula.pl $1 +UserParameter=bacula.hosts,/usr/bin/perl /etc/zabbix/scripts/bacula_hosts.pl + From 2c2c759108bb68b6a85999d57fd9c83003e27b52 Mon Sep 17 00:00:00 2001 From: ssv1982 Date: Thu, 18 Jun 2015 21:04:57 +0700 Subject: [PATCH 5/5] new manual --- README.md | 69 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index e24e8d5..7d82d9d 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,12 @@ -# Zabbix monitoring of Bacula's backup jobs and its processes - -This project is mainly composed by a bash script and a Zabbix template. The bash script reads values from Bacula Catalog and sends it to Zabbix Server. While the Zabbix template has items and other configurations that receive this values, start alerts and generate graphs and screens. This material was created using Bacula at 7.0.5 version and Zabbix at 2.4.5 version in a GNU/Linux CentOS 7 operational system. +##Zabbix monitoring of Bacula's or Bareos's backup jobs and its processes +This project is mainly composed by a bash script and a Zabbix template. The bash script reads values from Bacula Catalog and sends it to Zabbix Server. While the Zabbix template has items and other configurations that receive this values, start alerts and generate graphs. This material was created using Bareos at 15.2.0 version and Zabbix at 2.4.5 version in a Calculate linux operational system. ### Abilities - Customizable and easy to set up - Separate monitoring for each backup job -- Different job levels have different severities -- Monitoring of Bacula Director, Storage and File processes +- Separate monitoring for each backup level of job - Generates graphs to follow the data evolution -- Screens with graphs ready for display - Works with MySQL and PostgreSQL used by Bacula Catalog ### Features @@ -25,11 +22,11 @@ This project is mainly composed by a bash script and a Zabbix template. The bash ##### Zabbix template configuration -Link this Zabbix template to each host that has a Bacula's backup job implemented. Each host configured in Zabbix with this template linked needs to have its name equals to the name configured in Bacula's Client resource. Otherwise the data collected by the bash script will not be received by Zabbix server. +Link "Template Bacula Clients" zabbix template to host that has a zabbix agent with attached zabbix scripts (bacula_hosts.pl and bacula.pl). - **Items** - This Zabbix template has two types of items, the items to receive data of backup jobs, and the itens to receive data of Bacula's processes. The items that receive data of Bacula's processes are described below: + This Zabbix templates has two types of items, the items to receive data of backup jobs, and the itens to receive data of Bacula's processes. The items that receive data of Bacula's processes ("Template Bacula Proceses") are described below: - *Bacula Director is running*: Get the Bacula Director process status. The process name is defined by the variable {$BACULA.DIR}, and has its default value as 'bacula-dir'. This item needs to be disabled in hosts that are Bacula's clients only. - *Bacula Storage is running*: Get the Bacula Storage process status. The process name is defined by the variable {$BACULA.SD}, and has its default value as 'bacula-sd'. This item needs to be disabled in hosts that are Bacula's clients only. @@ -68,10 +65,6 @@ Link this Zabbix template to each host that has a Bacula's backup job implemente - *Files transferred*: Displays a graph with the variation of the files transferred by backup jobs, faced with the variation of the exit status of these jobs - *Transfer rate*: Displays a graph with the variation of the transfer rate by backup jobs, faced with the variation of the exit status of these jobs -- **Screens** - - There are three screens, one for each backup level, that displays the five graphs previously configured for that level. - ### Requirements - Bacula's implemented infrastructure and knowledge about it @@ -102,44 +95,56 @@ Link this Zabbix template to each host that has a Bacula's backup job implemente ... } ``` - -4. Now restart the Bacula Director service. In my case I used this command: +4. Copy bacula.pl and bacula_hosts.pl to zabbix scripts directory,usually `/etc/zabbix/scripts/` and set the permission as below: + ``` + chown zabbix:zabbix /etc/zabbix/scripts/bacula.pl + chown zabbix:zabbix /etc/zabbix/scripts/bacula_hosts.pl + chmod 700 /etc/zabbix/scripts/bacula.pl + chmod 700 /etc/zabbix/scripts/bacula_hosts.pl + ``` +5. Edit the Zabbix Agent configuration file `/etc/zabbix/zabbix-agentd.conf` to attach scripts to zabbix. To do this you need to add the lines described below in UserParametr section: + ``` + UserParameter=bacula.jobs[*],/usr/bin/perl /etc/zabbix/scripts/bacula.pl $1 + UserParameter=bacula.hosts,/usr/bin/perl /etc/zabbix/scripts/bacula_hosts.pl + ``` +6. Now restart the Bacula Director service. In my case I used this command: ``` - systemctl restart bacula-dir + /etc/init.d/bacula-dir restart + ``` + or + ``` + bconsole + reload + exit + ``` +7. Restart zabbix-agent: + ``` + /etc/init.d/zabbix-agentd restart ``` 5. Make a copy of the Zabbix template from this repository and import it to your Zabbix server. -6. Edit your hosts that have configured backup jobs to use this template. Don't forget to edit the variables with the Bacula's processes names, and to disable in hosts that are only Bacula's clients the items that check the Bacula Director and Storage processes. +6. Add template: "Template Bacula Clients" to host which use modified zabbix-agent. + +7. Add template "Template Bacula Processes" to each host, where heeded monitiring status Bacula processes. Don't forget to edit the variables with the Bacula's processes names ### References - **Bacula**: - - http://www.bacula.org/7.0.x-manuals/en/main - - http://www.bacula.com.br/manual/Messages_Resource.html - - http://www.bacula-web.org/docs.html - - http://resources.infosecinstitute.com/data-backups-bacula-notifications - + - http://blog.bacula.org/documentation/documentation/ + - http://doc.bareos.org/master/html/bareos-manual-main-reference.html - **Zabbix**: - - http://novatec.com.br/livros/zabbix - - http://www.zabbix.org/wiki/InstallOnCentOS_RHEL - https://www.zabbix.com/documentation/2.4/start - - http://zabbixoverflow.com/index.php?topic=51.0 - - https://support.zabbix.com/browse/ZBX-7790 -- **Integration**: - - - https://www.zabbix.com/forum/showthread.php?t=8145 - - http://paje.net.br/?p=472 - - https://github.com/selivan/bacula_zabbix_integration ### Feedback Feel free to send bug reports and feature requests here: -- https://github.com/germanodlf/bacula-zabbix/issues -- germanodlf@gmail.com +- https://github.com/ssv1982/bacula-zabbix/issues If you are using this solution in production, please write me about it. It's very important for me to know that my work is not meaningless. + +Solution based on: https://github.com/germanodlf/bacula-zabbix.git