forked from DennisNgrox/Shell-Scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createhosturl.sh
60 lines (51 loc) · 1.34 KB
/
createhosturl.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
ZABBIX_USER="Admin"
ZABBIX_PASS="zabbix"
ZABBIX_API="http://192.168.126.142/api_jsonrpc.php"
HOSTNAME_ZABBIX=$1
IP_ZABBIX=$2
ZABBIX_AUTH_TOKEN=$(curl -s -H 'Content-Type: application/json-rpc' -d "{\"jsonrpc\": \"2.0\",\"method\":\"user.login\",\"params\":{\"user\":\""${ZABBIX_USER}"\",\"password\":\""${ZABBIX_PASS}"\"},\"auth\": null,\"id\":0}" $ZABBIX_API | jq -r .result)
TESTE=$(echo $1 | egrep "\.com\.br")
if [ $1 = $TESTE ] ;
then
HM=$(curl -s -H 'Content-Type: application/json-rpc' -d "
{
\"jsonrpc\": \"2.0\",
\"method\": \"host.create\",
\"params\": {
\"host\": \"Certificado - $1\",
\"interfaces\": [
{
\"type\": 1,
\"main\": 1,
\"useip\": 0,
\"ip\": \"$2\",
\"dns\": \"$3\",
\"port\": \"161\"
}
],
\"groups\": [
{
\"groupid\": \"19\"
}
],
\"templates\": [
{
\"templateid\": \"10437\"
}
],
\"macros\": [
{
\"macro\": \"{\$WEB}\",
\"value\": \"$1\"
}
]
},
\"auth\": \"${ZABBIX_AUTH_TOKEN}\",
\"id\": 1
}" ${ZABBIX_API}
)
echo $HM
else
echo "$1 - URL INCORRETA" >> error.url
fi