Zabbix template bash generator
Jump to navigation
Jump to search
#!/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