zabbix_agentd卸载API

zabbix_agentd 卸载

[@bjyf_43_77 test]$ cat zabbix_delete.sh 
#!/bin/bash
Local_IP=$(ifconfig eth0|grep "\binet\b"|awk -F'[ :]+' '{print $(NF-4)}')
ZABBIX_API="http://10.134.115.94/api_jsonrpc.php"
CURL_REQ="curl -s -i -X POST -H 'Content-type:application/json' -d"

#Acquisition system version(Centos5|Centos6|Centos7)
version=$(cat /etc/redhat-release |awk '{if($(NF-1)~/^5/){print 5}else if($(NF-1)~/^6/){print 6}else{print 7}}')

#Must be the root user
if [ $(echo $(id -u)) -ne 0 ];then
    echo -e "\033[34mMust be carried out using the root user, current user is $(whoami)\033[0m"
    exit 1
fi

#For rsync way of unloading
pkill -9 zabbix_agentd
grep -q zabbix /etc/passwd
if [ $? -eq 0 ]
then
    userdel zabbix
fi
chkconfig --list|grep -q zabbix_agentd
if [ $? -eq 0 ]
then
    chkconfig --del zabbix_agentd
    chkconfig --level 35 zabbix_agentd off
fi
[ -f /etc/init.d/zabbix_agentd ] && rm -f /etc/init.d/zabbix_agentd
[ -d /search/zabbix ] && rm -rf /search/zabbix

#In view of the RPM way of unloading
rpm_package=$(echo zabbix-agent-redhat${version}*|sed -r 's/.rpm//g')
rpm -qa|grep -q zabbix
if [ $? -eq 0 ]
then
    rpm -e "$rpm_package"
fi

#Zabbix template variables
Hostname="$Local_IP"

HOST_ID='{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "filter": {
            "host": [
                "'$Hostname'"
            ]
        }
    },
    "auth": "00000000000000000000000000000000",
    "id": 1
}'

H_ID=$(curl -s -i -X POST -H 'Content-type:application/json' -d "$HOST_ID" "$ZABBIX_API"|sed -rn '/"hostid"/s/.*:"(.*)","proxy_.*/\1/gp')
echo $H_ID

HOST_DEL='{
    "jsonrpc": "2.0",
    "method": "host.delete",
    "params": [
        "'$H_ID'"
    ],
    "auth": "00000000000000000000000000000000",
    "id": 1
}'
if [ "x$H_ID" != "x" ];then
	curl -s -i -X POST -H 'Content-type:application/json' -d "$HOST_DEL" "$ZABBIX_API"
fi
[ -f /tmp/zabbix_delete.sh ] && rm -f /tmp/zabbix_delete.sh
[@bjyf_43_77 test]$
上一篇:Cisco Catalyst 9100 无线接入点,IOS XE Software Release 17.06.01 ED


下一篇:Shell案例11——20