#!/bin/bash
# Bacula director monitorization plugin for Pandora FMS agent
# Author: Manuel A. GulĂn Bejarano
# Version: 1.0
# Date: 15/03/2013
#
# This program 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, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
function help {
echo -e "Bacula director monitorization agent plugin for Pandora FMS agent. http://pandorafms.com"
echo -e "Syntax:"
echo -e "\t\t$0 'dbuser' 'dbpass' 'bacula_catalog_name'"
exit
}
if [ $# -ne 3 ]
then
help
exit -1
fi
MY_USER="$1"
MY_PASS="$2"
MY_CATALOG="$3"
ACT_DAY=`date +%Y-%m-%d`
ACT_MONTH=`date +%Y-%m`
PRE_DAY=`date --date='yesterday' +%Y-%m-%d`
PRE_MONTH=`date --date='-1 month' +%Y-%m`
# # Query to get the total number of clients
MY_QUERY="SELECT 'Clients', IFNULL(COUNT(ClientId),0) FROM $3.Client;"
# # Query to get the total number of tapes
MY_QUERY="$MY_QUERY SELECT 'Tapes', IFNULL(COUNT(MediaId),0) from $3.Media WHERE Enabled=1;"
# # Query to get the total number of storage devices
MY_QUERY="$MY_QUERY SELECT 'Storage', IFNULL(COUNT(StorageId),0) FROM $3.Storage;"
# # Query to get the total number of ran jobs
MY_QUERY="$MY_QUERY SELECT 'Jobs', IFNULL(COUNT(JobId),0) FROM $3.Job;"
# # Query to get the total size in megabytes of data stored in tapes
MY_QUERY="$MY_QUERY SELECT 'Media_MB', IFNULL(SUM(VolBytes),0)/(1024*1024) FROM $3.Media;"
# # Query to get the number of files from backup jobs without errors actually stored on tapes
MY_QUERY="$MY_QUERY SELECT 'JobFiles', IFNULL(SUM(JobFiles),0) FROM $3.Job WHERE Type='B' AND JobStatus='T' AND PurgedFiles=0;"
# # Query to get the size of the index and data of the catalog of bacula
MY_QUERY="$MY_QUERY SELECT 'Index_Catalog_MB', IFNULL(SUM(INDEX_LENGTH),0)/(1024*1024), 'Data_Catalog_MB', IFNULL(SUM(DATA_LENGTH),0)/(1024*1024) FROM information_schema.TABLES WHERE TABLE_SCHEMA='$3';"
# # Query to get the number of backups without errors done today
MY_QUERY="$MY_QUERY SELECT 'BJobs_wo_errors_act_day', IFNULL(COUNT(JobId),0) FROM $3.Job WHERE TYPE='B' AND JobStatus='T' AND JobErrors=0 AND LEFT(StartTime,10)='$ACT_DAY';"
# # Query to get the number of backups with errors done today
MY_QUERY="$MY_QUERY SELECT 'BJobs_w_errors_act_day', IFNULL(COUNT(JobId),0) FROM $3.Job WHERE TYPE='B' AND LEFT(StartTime,10)='$ACT_DAY' AND JobStatus IN ('E','e','f');"
# # Query to get the number of backups without errors done yesterday
MY_QUERY="$MY_QUERY SELECT 'BJobs_wo_errors_prev_day', IFNULL(COUNT(JobId),0) FROM $3.Job WHERE TYPE='B' AND JobStatus='T' AND JobErrors=0 AND LEFT(StartTime,10)='$PRE_DAY';"
# # Query to get the number of backups with errors done yesterday
MY_QUERY="$MY_QUERY SELECT 'BJobs_w_errors_prev_day', IFNULL(COUNT(JobId),0) FROM $3.Job WHERE TYPE='B' AND LEFT(StartTime,10)='$PRE_DAY' AND JobStatus IN ('E','e','f');"
# # Query to get the number of backups without errors done the present month
MY_QUERY="$MY_QUERY SELECT 'BJobs_wo_errors_act_month', IFNULL(COUNT(JobId),0)FROM $3.Job WHERE TYPE='B' AND JobStatus='T' AND JobErrors=0 AND LEFT(StartTime,7)='$ACT_MONTH';"
# # Query to get the number of backups without errors done the previous month
MY_QUERY="$MY_QUERY SELECT 'BJobs_wo_errors_prev_month', IFNULL(COUNT(JobId),0) FROM $3.Job WHERE TYPE='B' AND JobStatus='T' AND JobErrors=0 AND LEFT(StartTime,7)='$PRE_MONTH';"
# # Query to get the number of backups with errors done the present month
MY_QUERY="$MY_QUERY SELECT 'BJobs_w_errors_act_month', IFNULL(COUNT(JobId),0) FROM $3.Job WHERE TYPE='B' AND LEFT(StartTime,7)='$ACT_MONTH' AND JobStatus IN ('E','e','f');"
# # Query to get the number of backups with errors done the previous month
MY_QUERY="$MY_QUERY SELECT 'BJobs_w_errors_prev_month', IFNULL(COUNT(JobId),0) FROM $3.Job WHERE TYPE='B' AND LEFT(StartTime,7)='$PRE_MONTH' AND JobStatus IN ('E','e','f');"
# All retrieved with one connection, later it's going to be appropiately parsed
BAC_INFO=`mysql -u $MY_USER -p"$MY_PASS" -Bse "$MY_QUERY"`
# Info about the total number of clients
BAC_CLIENTS=`echo $BAC_INFO | grep -o "Clients [0-9]*" | awk '{print $2}'`
# Info about the total number of tapes
BAC_TAPES=`echo $BAC_INFO | grep -o "Tapes [0-9]*" | awk '{print $2}'`
# Info about the total number of storage devices
BAC_STORAGE=`echo $BAC_INFO | grep -o "Storage [0-9]*" | awk '{print $2}'`
# Info about the total number of ran jobs
BAC_JOBS=`echo $BAC_INFO | grep -o "Jobs [0-9]*" | awk '{print $2}'`
# Info about the number of files from backup jobs without errors actually stored on tapes
BAC_JOBFILES=`echo $BAC_INFO | grep -o "JobFiles [0-9]*" | awk '{print $2}'`
# Info about the total size in megabytes of data stored in tapes
BAC_MEDIA_MB=`echo $BAC_INFO | grep -o "Media_MB [0-9]*" | awk '{print $2}'`
# Info about the size of the index of the catalog of bacula
BAC_CAT_INDEX_MB=`echo $BAC_INFO | grep -o "Index_Catalog_MB [0-9]*" | awk '{print $2}'`
# Info about the size of the data of the catalog of bacula
BAC_CAT_DATA_MB=`echo $BAC_INFO | grep -o "Data_Catalog_MB [0-9]*" | awk '{print $2}'`
# Info about the number of backups without errors done today
BAC_JOBS_WO_T_D=`echo $BAC_INFO | grep -o "BJobs_wo_errors_act_day [0-9]*" | awk '{print $2}'`
# Info about the number of backups with errors done today
BAC_JOBS_W_T_D=`echo $BAC_INFO | grep -o "BJobs_w_errors_act_day [0-9]*" | awk '{print $2}'`
# Info about the number of backups without errors done yesterday
BAC_JOBS_WO_P_D=`echo $BAC_INFO | grep -o "BJobs_wo_errors_prev_day [0-9]*" | awk '{print $2}'`
# Info about the number of backups with errors done yesterday
BAC_JOBS_W_P_D=`echo $BAC_INFO | grep -o "BJobs_w_errors_prev_day [0-9]*" | awk '{print $2}'`
# Info about the number of backups without errors done the present month
BAC_JOBS_WO_T_M=`echo $BAC_INFO | grep -o "BJobs_wo_errors_act_month [0-9]*" | awk '{print $2}'`
# Info about the number of backups with errors done the present month
BAC_JOBS_WO_P_M=`echo $BAC_INFO | grep -o "BJobs_wo_errors_prev_month [0-9]*" | awk '{print $2}'`
# Info about the number of backups without errors done the previous month
BAC_JOBS_W_T_M=`echo $BAC_INFO | grep -o "BJobs_w_errors_act_month [0-9]*" | awk '{print $2}'`
# Info about the number of backups with errors done the previous month
BAC_JOBS_W_P_M=`echo $BAC_INFO | grep -o "BJobs_w_errors_prev_month [0-9]*" | awk '{print $2}'`
# Module to get the number of clients
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\t#"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the number of tapes
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\t#"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the number of storage devices
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\t#"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the number of jobs
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\t#"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the number of files from backup jobs without errors actually stored on tapes
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\t#"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the total size in megabytes of data stored in tapes
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the size of the index of the catalog of bacula
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the size of the data of the catalog of bacula
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the number of backups without errors done today
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\t#"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the number of backups with errors done today
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\t#"
echo -e "\t0"
echo -e "\t1"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the number of backups without errors done yesterday
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\t#"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the number of backups with errors done yesterday
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\t#"
echo -e "\t0"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the number of backups without errors done this month
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\t#"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the number of backups with errors done this month
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\t#"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the number of backups without errors done the past month
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\t#"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the number of backups with errors done the past month
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t0"
echo -e "\t#"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"