Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Remove-Zabbix Init script should run when an AWS instance goes down and remove itself from Zabbix Server
- # chkconfig: - 84 02
- # description: Remove from zabbix
- # Source function library.
- HOST_NAME=$2
- USER='Admin'
- PASS='zabbix'
- ZABBIX_SERVER='192.168.100.150'
- API='http://192.168.100.150/zabbix/api_jsonrpc.php'
- # Authenticate with Zabbix API
- echo $HOST_NAME
- echo $USER
- echo $PASS
- app=`curl -s -H 'Content-Type: application/json-rpc' -d '{"jsonrpc": "2.0","method":"user.login","params":{"user":"'$USER'","password":"'$PASS'"},"auth": null,"id":0}' $API`
- #{"jsonrpc":"2.0","result":"305c41fa941f185a586e332a68f1312d","id":0}
- AUTH_TOKEN=`echo $app| ./jq '.result'`
- echo $AUTH_TOKEN
- #curl -s -H 'Content-Type: application/json-rpc' -d '{"jsonrpc": "2.0","method":"host.get","params":{"output":"extend","filter":{"host":["postgre"]}},"auth":"305c41fa941f185a586e332a68f1312d","id":0}' http://192.168.100.150/zabbix/api_jsonrpc.php
- app=`curl -s -H 'Content-Type: application/json-rpc' -d '{"jsonrpc": "2.0","method":"host.get","params":{"output":"extend","filter":{"host":["'$HOST_NAME'"]}},"auth":'$AUTH_TOKEN',"id":0}' $API`
- HOST_ID=`echo $app| ./jq '.result[0].hostid'`
- echo $HOST_ID
- #GET HOST INTERFACE
- app=`curl -s -H 'Content-Type: application/json-rpc' -d '{"jsonrpc": "2.0","method": "hostinterface.get","params": {"output": "extend","hostids": '$HOST_ID'},"auth": '$AUTH_TOKEN',"id": 0}' $API`
- #{"jsonrpc":"2.0","result":[{"interfaceid":"67","hostid":"10177","main":"1","type":"1","useip":"1","ip":"192.168.100.154","dns":"","port":"10050","bulk":"1"}],"id":0}
- INTERFACE_ID=`echo $app| ./jq '.result[0].interfaceid'`
- HOST_IP=`echo $app| ./jq '.result[0].ip'`
- HOST_IP=$(echo $HOST_IP | sed 's/^"\(.*\)"$/\1/')
- echo $HOST_IP
- echo $1
- if [ "$HOST_IP" = "$1" ]; then
- exit 0
- else
- app=`curl -s -H 'Content-Type: application/json-rpc' -d '{"jsonrpc": "2.0","method": "hostinterface.update","params": {"interfaceid": '$INTERFACE_ID',"ip":"'$1'"},"auth": '$AUTH_TOKEN' ,"id": 0}' $API`
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement