forked from aigarskadikis/externalscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export-host-info-curl.sh
executable file
·45 lines (34 loc) · 1.13 KB
/
export-host-info-curl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# description: Remove unreachable host from Zabbix
USER=$1
PASS=$2
API='http://localhost/zabbix/api_jsonrpc.php'
HOST_NAME=$3
# Authenticate with Zabbix API
authenticate() {
echo `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`
}
AUTH_TOKEN=`echo $(authenticate)|grep -oP '([0-9a-z]{32})'`
echo $AUTH_TOKEN
# Get HostId:
gethostid() {
echo `curl -s -H 'Content-Type: application/json-rpc' -d "{\"jsonrpc\": \"2.0\",\"method\":\"host.get\",\"params\":{\"output\":[\"hostid\"],\"filter\":{\"host\":[\"$HOST_NAME\"]}},\"auth\":\""${AUTH_TOKEN}"\",\"id\":0}" $API`
}
HOST_ID=`echo $(gethostid)| grep -oP '[0-9]{5,15}'`
echo $HOST_ID
# Remove Host
curl -s -H 'Content-Type: application/json-rpc' -d "{
\"jsonrpc\": \"2.0\",
\"method\": \"configuration.export\",
\"params\": {
\"options\": {
\"hosts\": [
\"$HOST_ID\"
]
},
\"format\": \"xml\"
},
\"auth\": \""${AUTH_TOKEN}"\",
\"id\": 1
}" $API
exit 0