网站首页 安全运维 zabbix监控linux进程及服务通用key方式
zabbix监控linux进程及服务通用key方式
编辑时间:2020-01-03 14:52 作者:nllihui6390 浏览量:1863

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


来说两句吧
乖,登录后才可以留言!
最新评论