forked from DennisNgrox/Shell-Scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
triggerprototype_update.sh
93 lines (82 loc) · 2.78 KB
/
triggerprototype_update.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
#1 ° Preciso da Triggerid para update de tags
#2 ° Preciso do DiscoveryID para get da trigger // FEITO
#3 ° Preciso do Hostids para get do discoveryID // FEITO
#4 ° Lista com nome dos templates. // FEITO COM $1 --- Realiza utilizando: sed
#5 ° Fazer template.get // FEITO
zabbix_user="Admin"
zabbix_pass="ip"
zabbix_api="http://ip/api_jsonrpc.php"
PRIMEIRO=$1
SEGUNDO=$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\": \"template.get\",
\"params\": {
\"output\": \"["hostid"]\",
\"filter\": {
\"host\": [
\"${PRIMEIRO}\"
]
}
},
\"auth\": \"${zabbix_auth_token}\",
\"id\": 1
}" ${zabbix_api}| awk -F\" '{print $10}')
discoveryid=$(curl -s -k -H 'Content-Type: application/json-rpc' -d "
{
\"jsonrpc\": \"2.0\",
\"method\": \"discoveryrule.get\",
\"params\": {
\"output\": [\"itemid\"],
\"hostids\": [\"${hostid}\"]
},
\"auth\": \"${zabbix_auth_token}\",
\"id\": 1
}" ${zabbix_api}| jq .result[].itemid | sed s'/"//g' > teste.dennis)
for i in $(cat teste.dennis)
do
value=$(echo $i);
triggerid=$(curl -s -k -H 'Content-Type: application/json-rpc' -d "
{
\"jsonrpc\": \"2.0\",
\"method\": \"triggerprototype.get\",
\"params\": {
\"output\": [\"triggerid\"],
\"discoveryids\": \"${value}\"
},
\"auth\": \"${zabbix_auth_token}\",
\"id\": 1
}" ${zabbix_api} | jq .result[].triggerid | sed s'/"//g' > valor.trigger);
for a in $(cat valor.trigger);
do
trigg=$(echo $a);
tagupdate=$(curl -s -k -H 'Content-Type: application/json-rpc' -d "
{
\"jsonrpc\": \"2.0\",
\"method\": \"triggerprototype.update\",
\"params\": {
\"triggerid\": \"${trigg}\",
\"tags\": [
{
\"tag\": \"integ_itsm_grp\",
\"value\": \"${SEGUNDO}\"
},
{
\"tag\": \"integ_itsm_src\",
\"value\": \"remota\"
},
{
\"tag\": \"integ_itsm_type\",
\"value\": \"cluster\"
}
]
},
\"auth\": \"${zabbix_auth_token}\",
\"id\": 1
}" ${zabbix_api}| awk -F\" '{print $10}');
echo $tagupdate
done
done