网站首页 安全运维 zabbix监控linux进程及服务通用key方式
1、编写脚本
type=$1
name=$2
#服务状态监测 $1=service
if [ "X${type}" = "Xservice" ];then
v=$name".service"
sta=`systemctl --type service |grep "${v}"|awk '{print $4}'`
#echo "$sta"
if [ "X${sta}" = "Xrunning" ];then
echo "1"
else
echo "0"
fi
fi
#进程状态监测 $1=course
if [ "X${type}" = "Xcourse" ];then
sta=`ps -ef | grep "${name}" | grep -v grep| grep -v /is_status.sh`
if [ "X${sta}" = "X" ];then
echo "0"
else
echo "1"
fi
fi
#心跳IP监测 $1=vmip
if [ "X${type}" = "Xvmip" ];then
sta=`ip a |grep "${name}"|awk '{print $1}'`
#echo "$sta"
if [ "X${sta}" = "Xinet" ];then
echo "1"
else
echo "0"
fi
fi
添加配置文件
vim /etc/zabbix/zabbix_agent.conf
UserParameter=is_status[*],/etc/zabbix/scripts/is_status.sh $1 $2