Advertisement
Guest User

Zabbix UserIp update

a guest
Feb 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.04 KB | None | 0 0
  1. #!/bin/bash
  2. # Remove-Zabbix Init script should run when an AWS instance goes down and remove itself from Zabbix Server
  3. # chkconfig: - 84 02
  4. # description: Remove from zabbix
  5. # Source function library.
  6. HOST_NAME=$2
  7.  
  8. USER='Admin'
  9. PASS='zabbix'
  10. ZABBIX_SERVER='192.168.100.150'
  11. API='http://192.168.100.150/zabbix/api_jsonrpc.php'
  12.  
  13. # Authenticate with Zabbix API
  14.  
  15. echo $HOST_NAME
  16.  
  17. echo $USER
  18.  
  19. echo $PASS
  20.  
  21. 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`
  22.  
  23. #{"jsonrpc":"2.0","result":"305c41fa941f185a586e332a68f1312d","id":0}
  24.  
  25. AUTH_TOKEN=`echo $app| ./jq '.result'`
  26.  
  27. echo $AUTH_TOKEN
  28.  
  29. #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
  30.  
  31. 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`
  32.  
  33. HOST_ID=`echo $app| ./jq '.result[0].hostid'`
  34.  
  35. echo $HOST_ID
  36.  
  37. #GET HOST INTERFACE
  38.  
  39. 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`
  40.  
  41. #{"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}
  42.  
  43. INTERFACE_ID=`echo $app| ./jq '.result[0].interfaceid'`
  44.  
  45. HOST_IP=`echo $app| ./jq '.result[0].ip'`
  46.  
  47. HOST_IP=$(echo $HOST_IP | sed 's/^"\(.*\)"$/\1/')
  48.  
  49. echo $HOST_IP
  50. echo $1
  51.  
  52. if [ "$HOST_IP" = "$1" ]; then
  53.     exit 0
  54. else
  55.        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`
  56.  
  57. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement