-
Notifications
You must be signed in to change notification settings - Fork 66
/
export_templates
executable file
·75 lines (69 loc) · 1.91 KB
/
export_templates
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
#!/bin/bash
. ../zapish/zapish.inc
for i in \
"ICMP" \
"MIB/F5-BIGIP-LOCAL-MIB" \
"MIB/F5-BIGIP-SYSTEM-MIB" \
"MIB/IF-MIB" \
"MIB/IP-MIB" \
"MIB/SNMP-MPD-MIB" \
"MIB/SNMP-USER-BASED-SM-MIB" \
"MIB/SNMP-VIEW-BASED-ACM-MIB" \
"MIB/SNMPv2-MIB" \
"MIB/UDP-MIB" \
"OS Linux" \
"OS Solaris" \
"OS Windows" \
"Service Apache" \
"Service MySQL" \
"Service Nginx" \
"Service Zabbix Agent" \
"Service Zabbix Proxy" \
"Service Zabbix Server" \
"SNMP Devices/BIG-IP 5000" \
"SNMP Devices/DSL-3782"
do
template_name=$(basename "$i")
templates="$(zabbix_api template.get \
"$(json_list params \
"$(json_str output simple \
"")" \
"$(json_list filter \
"$(json_array_str "name" \
"${template_name}" \
"")" \
"")" \
"")" \
)"
templateid="$(json_get "${templates=}" .result[].templateid)"
xml_output="$(zabbix_api configuration.export \
"$(json_list params \
"$(json_list options \
"$(json_array_num templates \
${templateid} \
"")" \
"")" \
"$(json_str format xml \
"")" \
"")" \
)"
# Create template directory if it does not exiest
if [ ! -d "${i}" ]; then
mkdir -p "${i}"
fi
# export template
echo "${xml_output}" | jq -r .result | xmllint --format - > "${i}/${template_name}".new.xml
if [ -f "${i}/${template_name}.xml" ]; then
cmp -s <(sed 4d "${i}/${template_name}".new.xml) <(sed 4d "${i}/${template_name}.xml")
if [ $? -ne 0 ]; then
printf "Template id=%7s, Name=%-40s export to %s.xml\n" ${templateid} "\"${template_name}\"" "${i}/${template_name}"
mv -f "${i}/${template_name}"{.new,}.xml
else
printf "Template id=%7s, Name=%-40s no changes\n" ${templateid} \""${template_name}"\"
rm -f "${i}/${template_name}".new.xml
fi
else
printf "Template id=%7s, Name=%-40s export to %s.xml\n" ${templateid} "\"${template_name}\"" "${i}/${template_name}"
mv -f "${i}/${template_name}"{.new,}.xml
fi
done