其他分享
首页 > 其他分享> > Zabbix二次开发脚本控制

Zabbix二次开发脚本控制

作者:互联网

执行方式:sh scripts.sh scriptsfile="Linux_Memory.sh" check="failed/true"


脚本参数详解:

scriptsfile="" ---zbx二次开发监控脚本

check="" ---failed(执行)true(查看)

 

脚本内容:

#! /bin/sh

scriptsfile=""
check=""

########################################## zbx internal-control ##########################################
if [ -f "/home/zabbix/zabbix-agent/etc/scripts/zabbixlog.sh" ];then
source /home/zabbix/zabbix-agent/etc/scripts/zabbixlog.sh
elif [ -f "/home/zabbix/zabbix-agent/etc/scripts/zabbixtimeout.sh" ];then
source /home/zabbix/zabbix-agent/etc/scripts/zabbixtimeout.sh
else
echo "Zabbix failed to invoke the internal control function.Procedure"
exit 1
fi

########################################## Checking Script Parameters ##########################################
[[ $# -gt 2 ]] && echo "ERROR:you should provide 2 parameters at most!!!" && exit
[[ $# -eq 0 ]] && echo "Script location parameters dose not exits!!!" && exit

########################################## zbx Right-control ##########################################
function checkPermission {
############################ os file ############################
if [ -f "/etc/redhat-release" ];then
############# redhat Linux #############
echo "redhat Linux file exist "
return 0
elif [ -f "/etc/os-release" ];then
############# Kylin/OpenEuler/EulerOS Linux #############
echo "Kylin/OpenEuler/EulerOS Linux file exist "
return 0
elif [ -f "/etc/issue" ];then
############# SUSE Linux #############
echo "SUSE Linux file exist "
return 0
fi
############################ command permission check ############################
whichcommend=`which which |wc -l`
grepcommend=`which grep |wc -l`
bccommend=`which bc |wc -l`
catcommend=`which cat |wc -l`

############################ memroy file ############################
if [ -f /proc/meminfo ];then
echo "OK:/proc/meminfo file exist" >>$logfile
return 0
else
echo "Error:/proc/meminfo file dnoe not exist"
return 0
fi

if [ "$whichcommend" -eq 1 ];then
echo "OK:The command is" >>$logfile
return 0
elif [ "$grepcommend" -eq 1 ];then
echo "OK:The command is" >>$logfile
return 0
elif [ "$bccommend" -eq 1 ];then
echo "OK:The command is" >>$logfile
return 0
elif [ "$catcommend" -eq 1 ];then
echo "OK:The command is" >>$logfile
return 0
else
echo "Error:Some commands do not exist"
return 1
fi
}

########################################## zbx function-module ##########################################
function checkZabbix {
Zabbixcheck=`cat /etc/passwd |grep zabbix |wc -l`
if [ "$Zabbixcheck" -eq 1 ];then
if [ -f "$scriptsfile" ];then
sh "$scriptsfile"
return 0
else
echo "ScriptsFile Inexistence"
return 1
fi
fi
}

########################################## intrinsic parameter ##########################################
while [[ $# -ne 0 ]]
do
opt_name=$(echo $1 |awk -F= '{print $1}')
opt_value=$(echo $1 |awk -F= '{print $2}')
case $opt_name in
scriptsfile)
if [[ -n $opt_value ]];then
scriptsfile=$opt_value
echo "opt_name=$opt_name opt_value=$opt_value"
[[ $opt_name !=$(hostname) ]] && echo "hostname-check-failure" && exit 1|| echo "hostname-check-success"
else
echo "$opt_name cat not be null"
exit 1
fi
;;
check)
[[ $opt_name != true ]] && [[ $opt_value != false ]] && ech0 "echo value is true or false!!!" && exit 1
echo "opt_name=$opt_name opt_value=$opt_value"
check=$opt_value
;;
*)
echo "ERROR: you provide a non-exist paramter, paramter name is $opt_name,value is $opt_value!!!" && exit 1
;;
esac
shift
done
[[ $check != true ]] && [[ $check != false ]] && echo "check value is true or false!!!" && exit 1
########################################## Call vg_check_status and vgact action function ##########################################
checkPermission
checkZabbix

标签:脚本,opt,return,value,echo,##########################################,Zabbix,&
来源: https://www.cnblogs.com/A121/p/16440460.html