Difference between revisions of "Zabbix template bash generator"
Jump to navigation
Jump to search
(Created page with "``` #!/bin/bash set -eu create_item(){ dnshost=$1 fqdn=$2 uuidv4=$(uuid -v 4 | sed 's/-//g') item_line=$(cat <<EOF - uuid: ${uuidv4} name:...") |
|||
Line 6: | Line 6: | ||
dnshost=$1 | dnshost=$1 | ||
fqdn=$2 | fqdn=$2 | ||
− | + | uuidv4_a=$(uuid -v 4 | sed 's/-//g') | |
+ | # uuidv4_a=$3 | ||
+ | uuidv4_b=$(uuid -v 4 | sed 's/-//g') | ||
+ | uuidv4_c=$(uuid -v 4 | sed 's/-//g') | ||
item_line=$(cat <<EOF | item_line=$(cat <<EOF | ||
- | - | ||
− | uuid: ${ | + | uuid: ${uuidv4_a} |
name: ${dnshost}_${fqdn} | name: ${dnshost}_${fqdn} | ||
type: EXTERNAL | type: EXTERNAL | ||
key: 'dnsname-resolve["${dnshost}", "${fqdn}"]' | key: 'dnsname-resolve["${dnshost}", "${fqdn}"]' | ||
+ | triggers: | ||
+ | - | ||
+ | uuid: ${uuidv4_b} | ||
+ | expression: 'last(/dns-resolver-tests/dnsname-resolve["${dnshost}", "${fqdn}"])<>0' | ||
+ | name: 'dns resolve failure ${dnshost} ${fqdn} 1 time' | ||
+ | priority: WARNING | ||
+ | description: 'DNS resolution from resolver ${dnshost} for FQDN ${fqdn} has failed 1 time.' | ||
+ | - | ||
+ | uuid: ${uuidv4_c} | ||
+ | expression: 'last(/dns-resolver-tests/dnsname-resolve["${dnshost}", "${fqdn}"],#3)<>0' | ||
+ | name: 'dns resolve failure ${dnshost} ${fqdn} 3 times' | ||
+ | priority: AVERAGE | ||
+ | description: 'DNS resolution from resolver ${dnshost} for FQDN ${fqdn} has failed 3 times consecutively. Check DNS zone record for deletion or DNS resolver host for issues.' | ||
EOF | EOF | ||
) | ) | ||
Line 47: | Line 63: | ||
main(){ | main(){ | ||
create_header | create_header | ||
+ | itemuuids=($(cat itemuuids.txt)) | ||
+ | i=0 | ||
for dnshost in $(cat dnshosts.txt); do | for dnshost in $(cat dnshosts.txt); do | ||
for fqdn in $(cat fqdns.txt); do | for fqdn in $(cat fqdns.txt); do | ||
create_item ${dnshost} ${fqdn} | create_item ${dnshost} ${fqdn} | ||
+ | # create_item ${dnshost} ${fqdn} ${itemuuids[$i]} | ||
+ | # i=$(($i + 1)) | ||
done | done | ||
done | done |
Latest revision as of 16:07, 11 February 2023
#!/bin/bash set -eu create_item(){ dnshost=$1 fqdn=$2 uuidv4_a=$(uuid -v 4 | sed 's/-//g') # uuidv4_a=$3 uuidv4_b=$(uuid -v 4 | sed 's/-//g') uuidv4_c=$(uuid -v 4 | sed 's/-//g') item_line=$(cat <<EOF - uuid: ${uuidv4_a} name: ${dnshost}_${fqdn} type: EXTERNAL key: 'dnsname-resolve["${dnshost}", "${fqdn}"]' triggers: - uuid: ${uuidv4_b} expression: 'last(/dns-resolver-tests/dnsname-resolve["${dnshost}", "${fqdn}"])<>0' name: 'dns resolve failure ${dnshost} ${fqdn} 1 time' priority: WARNING description: 'DNS resolution from resolver ${dnshost} for FQDN ${fqdn} has failed 1 time.' - uuid: ${uuidv4_c} expression: 'last(/dns-resolver-tests/dnsname-resolve["${dnshost}", "${fqdn}"],#3)<>0' name: 'dns resolve failure ${dnshost} ${fqdn} 3 times' priority: AVERAGE description: 'DNS resolution from resolver ${dnshost} for FQDN ${fqdn} has failed 3 times consecutively. Check DNS zone record for deletion or DNS resolver host for issues.' EOF ) echo "${item_line}" } create_header(){ header_line=$(cat <<EOF zabbix_export: version: '6.0' date: '2023-02-10T18:59:20Z' groups: - uuid: 3f372bbb7eca47978fc251a6312cc577 name: Green templates: - uuid: 840d80e8fc84470ba450e5bddb82a736 template: dns-resolver-tests name: dns-resolver-tests groups: - name: Green items: EOF ) echo "${header_line}" } main(){ create_header itemuuids=($(cat itemuuids.txt)) i=0 for dnshost in $(cat dnshosts.txt); do for fqdn in $(cat fqdns.txt); do create_item ${dnshost} ${fqdn} # create_item ${dnshost} ${fqdn} ${itemuuids[$i]} # i=$(($i + 1)) done done } main