-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_webmonitoring.sh
61 lines (53 loc) · 1.57 KB
/
create_webmonitoring.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
60
61
#!/bin/bash
zabbix_user="user"
zabbix_pass="pass"
zabbix_api="http://ip/api_jsonrpc.php"
host=$1
url=$2
zabbix_auth_token=$(curl -s -k -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)
hostid=$(curl -s -k -H 'Content-Type: application/json-rpc' -d "
{
\"jsonrpc\": \"2.0\",
\"method\": \"host.create\",
\"params\": {
\"host\": \"${host}\",
\"interfaces\": [
{
\"type\": 1,
\"main\": 1,
\"useip\": 1,
\"ip\": \"127.0.0.1\",
\"dns\": \"\",
\"port\": \"10050\"
}
],
\"groups\": [
{
\"groupid\": \"50\"
}
]
},
\"auth\": \"${zabbix_auth_token}\",
\"id\": 1
}" ${zabbix_api}| jq .result.hostids[] | sed s'/"//g')
echo $hostid
webscenario=$(curl -s -k -H 'Content-Type: application/json-rpc' -d "
{
\"jsonrpc\": \"2.0\",
\"method\": \"httptest.create\",
\"params\": {
\"name\": \"monitoring\",
\"hostid\": \"${hostid}\",
\"steps\": [
{
\"name\": \"Check URL\",
\"url\": \"https://${url}\",
\"status_codes\": \"200\",
\"no\": 1
}
]
},
\"auth\": \"${zabbix_auth_token}\",
\"id\": 1
}" ${zabbix_api}| jq .result.httptestids[] | sed s'/"//g')
echo $w ebscenario