diff --git a/README.md b/README.md index b2d799a..24fe79f 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Templates, scripts and hints for Zabbix. * [Wireguard](templates/applications/vpn/wireguard/6.0) * [Components](templates/components) * [certificate](templates/components/certificate/6.0) + * [dns availability](templates/components/dns-availability/6.0) * [network availability](templates/components/network-availability/6.0) * [Sensors](templates/sensors) * [ds18b20](templates/sensors/ds18b20/6.0) diff --git a/templates/components/dns-availability/6.0/README.md b/templates/components/dns-availability/6.0/README.md new file mode 100755 index 0000000..124d97b --- /dev/null +++ b/templates/components/dns-availability/6.0/README.md @@ -0,0 +1,99 @@ + +# DNS availability by Zabbix agent + +## Overview + +This template is designed for dns availability monitoring by Zabbix agent via host/posh and doesn't require any external scripts. + +## Requirements + +- Zabbix version: 6.0 and higher. +- [`Define user parameters.`](#define-user-parameters) + +## Tested versions + +This template has been tested on: + +- [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/) +- [Windows 11](https://www.microsoft.com/en-us/windows/windows-11) + +### Macros used + +|Name|Description|Default| +|----|-----------|-------| +|{$REQUEST}|address to check availability|`google.com`| +|{$RESOLVER1}|dns to check availability|`ns3-l2.nic.ru`| +|{$RESOLVER2}|dns to check availability|`ns4-l2.nic.ru`| +|{$RESOLVER3}|dns to check availability|`ns8-l2.nic.ru`| +|{$RESOLVER4}|dns to check availability|`ns4-cloud.nic.ru`| +|{$RESOLVER5}|dns to check availability|`ns8-cloud.nic.ru`| + +### Items + +|Name|Description|Type|Key and additional info| +|----|-----------|----|-----------------------| +|DNS request|Address for resolve|Calculated|'dns.request'| +|DNS resolver 1 address|Resolver address|Calculated|'dns.resolver1.address'| +|DNS resolver 1 available|Availability of address|Zabbix agent|'dns.resolver1.available[{$REQUEST},{$RESOLVER1}]'| +|DNS resolver 2 address|Resolver address|Calculated|'dns.resolver2.address'| +|DNS resolver 2 available|Availability of address|Zabbix agent|'dns.resolver2.available[{$REQUEST},{$RESOLVER2}]'| +|DNS resolver 3 address|Resolver address|Calculated|'dns.resolver3.address'| +|DNS resolver 3 available|Availability of address|Zabbix agent|'dns.resolver3.available[{$REQUEST},{$RESOLVER3}]'| +|DNS resolver 4 address|Resolver address|Calculated|'dns.resolver4.address'| +|DNS resolver 4 available|Availability of address|Zabbix agent|'dns.resolver4.available[{$REQUEST},{$RESOLVER4}]'| +|DNS resolver 5 address|Resolver address|Calculated|'dns.resolver5.address'| +|DNS resolver 5 available|Availability of address|Zabbix agent|'dns.resolver5.available[{$REQUEST},{$RESOLVER5}]'| + +### Triggers + +|Name|Description|Expression|Severity|Dependencies and additional info| +|----|-----------|----------|--------|--------------------------------| +|{ITEM.VALUE1} not resolved by any DNS||length(last(/DNS availability by Zabbix agent/dns.request))>0 and last(/DNS availability by Zabbix agent/dns.resolver1.available[{$REQUEST},{$RESOLVER1}],#1)<>1 and last(/DNS availability by Zabbix agent/dns.resolver2.available[{$REQUEST},{$RESOLVER2}],#1)<>1 and last(/DNS availability by Zabbix agent/dns.resolver3.available[{$REQUEST},{$RESOLVER3}],#1)<>1 and last(/DNS availability by Zabbix agent/dns.resolver4.available[{$REQUEST},{$RESOLVER4}],#1)<>1 and last(/DNS availability by Zabbix agent/dns.resolver5.available[{$REQUEST},{$RESOLVER5}],#1)<>1|High|Manual close: No| +|{ITEM.VALUE1} not resolved by {ITEM.VALUE2}||length(last(/DNS availability by Zabbix agent/dns.request))>0 and length(last(/DNS availability by Zabbix agent/dns.resolver1.address))>0 and last(/DNS availability by Zabbix agent/dns.resolver1.available[{$REQUEST},{$RESOLVER1}],#1)<>1|Average|Manual close: No| +|{ITEM.VALUE1} not resolved by {ITEM.VALUE2}||length(last(/DNS availability by Zabbix agent/dns.request))>0 and length(last(/DNS availability by Zabbix agent/dns.resolver2.address))>0 and last(/DNS availability by Zabbix agent/dns.resolver2.available[{$REQUEST},{$RESOLVER2}],#1)<>1|Average|Manual close: No| +|{ITEM.VALUE1} not resolved by {ITEM.VALUE2}||length(last(/DNS availability by Zabbix agent/dns.request))>0 and length(last(/DNS availability by Zabbix agent/dns.resolver3.address))>0 and last(/DNS availability by Zabbix agent/dns.resolver3.available[{$REQUEST},{$RESOLVER3}],#1)<>1|Average|Manual close: No| +|{ITEM.VALUE1} not resolved by {ITEM.VALUE2}||length(last(/DNS availability by Zabbix agent/dns.request))>0 and length(last(/DNS availability by Zabbix agent/dns.resolver4.address))>0 and last(/DNS availability by Zabbix agent/dns.resolver4.available[{$REQUEST},{$RESOLVER4}],#1)<>1|Average|Manual close: No| +|{ITEM.VALUE1} not resolved by {ITEM.VALUE2}||length(last(/DNS availability by Zabbix agent/dns.request))>0 and length(last(/DNS availability by Zabbix agent/dns.resolver5.address))>0 and last(/DNS availability by Zabbix agent/dns.resolver5.available[{$REQUEST},{$RESOLVER5}],#1)<>1|Average|Manual close: No| + +### Discovery rules + +There are no discovery rules in this template. + +### Item prototypes for Clients discovery + +There are no item prototypes in this template. + +### Define user parameters + +for Linux: + +```bash +tee -a /etc/zabbix/zabbix_agentd.conf > /dev/null <<'EOF' +Timeout=30 +UserParameter=dns.resolver1.available[*], host $1 $2 >> /dev/null && echo 1 || echo 0 +UserParameter=dns.resolver2.available[*], host $1 $2 >> /dev/null && echo 1 || echo 0 +UserParameter=dns.resolver3.available[*], host $1 $2 >> /dev/null && echo 1 || echo 0 +UserParameter=dns.resolver4.available[*], host $1 $2 >> /dev/null && echo 1 || echo 0 +UserParameter=dns.resolver5.available[*], host $1 $2 >> /dev/null && echo 1 || echo 0 +EOF + +systemctl restart zabbix-agent +``` + +for Windows: + +```batch +powershell.exe +$text = @" +Timeout=30 +UserParameter=dns.resolver1.available[*], powershell.exe -Command "if (Resolve-DnsName -Name $1 -Type A -Server $2 -ErrorAction SilentlyContinue) {return '1'}; return '0'" +UserParameter=dns.resolver2.available[*], powershell.exe -Command "if (Resolve-DnsName -Name $1 -Type A -Server $2 -ErrorAction SilentlyContinue) {return '1'}; return '0'" +UserParameter=dns.resolver3.available[*], powershell.exe -Command "if (Resolve-DnsName -Name $1 -Type A -Server $2 -ErrorAction SilentlyContinue) {return '1'}; return '0'" +UserParameter=dns.resolver4.available[*], powershell.exe -Command "if (Resolve-DnsName -Name $1 -Type A -Server $2 -ErrorAction SilentlyContinue) {return '1'}; return '0'" +UserParameter=dns.resolver5.available[*], powershell.exe -Command "if (Resolve-DnsName -Name $1 -Type A -Server $2 -ErrorAction SilentlyContinue) {return '1'}; return '0'" +"@ +$text | Out-File -Append "$env:ProgramFiles\Zabbix Agent\zabbix_agentd.conf" -Encoding "UTF8" +exit + +sc stop "Zabbix Agent" && sc start "Zabbix Agent" +``` diff --git a/templates/components/dns-availability/6.0/dns_availability_by_zabbix_agent.yaml b/templates/components/dns-availability/6.0/dns_availability_by_zabbix_agent.yaml new file mode 100644 index 0000000..44405e2 --- /dev/null +++ b/templates/components/dns-availability/6.0/dns_availability_by_zabbix_agent.yaml @@ -0,0 +1,265 @@ +zabbix_export: + version: '6.0' + date: '2024-05-31T00:00:00Z' + groups: + - + uuid: 57b7ae836ca64446ba2c296389c009b7 + name: Templates/Modules + templates: + - + uuid: dc56a9b915614419a6a0778029bbe4d9 + template: 'DNS availability by Zabbix agent' + name: 'DNS availability by Zabbix agent' + groups: + - + name: Templates/Modules + items: + - + uuid: a1f3e964152d489bae4a5cf68bee8dfa + name: 'DNS request' + type: CALCULATED + key: dns.request + trends: '0' + value_type: TEXT + params: '{$REQUEST}' + tags: + - + tag: component + value: dns + - + uuid: 3958093ad1954ad58fd83b8a71199dac + name: 'DNS resolver 1 address' + type: CALCULATED + key: dns.resolver1.address + trends: '0' + value_type: TEXT + params: '{$RESOLVER1}' + tags: + - + tag: component + value: dns + - + uuid: a241bc10b4794540afccbc744816a145 + name: 'DNS resolver 1 available' + key: 'dns.resolver1.available[{$REQUEST},{$RESOLVER1}]' + preprocessing: + - + type: CHECK_REGEX_ERROR + parameters: + - 'not found' + - '0' + error_handler: CUSTOM_VALUE + error_handler_params: '0' + tags: + - + tag: component + value: dns + - + uuid: 3d21807ac5c1417bb231a57fd10ea7ef + name: 'DNS resolver 2 address' + type: CALCULATED + key: dns.resolver2.address + trends: '0' + value_type: TEXT + params: '{$RESOLVER2}' + tags: + - + tag: component + value: dns + - + uuid: 69400921e3f54340b60315213e71c63f + name: 'DNS resolver 2 available' + key: 'dns.resolver2.available[{$REQUEST},{$RESOLVER2}]' + preprocessing: + - + type: CHECK_REGEX_ERROR + parameters: + - 'not found' + - '0' + error_handler: CUSTOM_VALUE + error_handler_params: '0' + tags: + - + tag: component + value: dns + - + uuid: 55db5ac1866a4b7491996b18f8eafbeb + name: 'DNS resolver 3 address' + type: CALCULATED + key: dns.resolver3.address + trends: '0' + value_type: TEXT + params: '{$RESOLVER3}' + tags: + - + tag: component + value: dns + - + uuid: 4473bbf60fa144c9b06d6efc48569136 + name: 'DNS resolver 3 available' + key: 'dns.resolver3.available[{$REQUEST},{$RESOLVER3}]' + preprocessing: + - + type: CHECK_REGEX_ERROR + parameters: + - 'not found' + - '0' + error_handler: CUSTOM_VALUE + error_handler_params: '0' + tags: + - + tag: component + value: dns + - + uuid: 0530f72294f5483985492d29045062cc + name: 'DNS resolver 4 address' + type: CALCULATED + key: dns.resolver4.address + trends: '0' + value_type: TEXT + params: '{$RESOLVER4}' + tags: + - + tag: component + value: dns + - + uuid: 5cb0869d357943eb8f68a4162e612c21 + name: 'DNS resolver 4 available' + key: 'dns.resolver4.available[{$REQUEST},{$RESOLVER4}]' + preprocessing: + - + type: CHECK_REGEX_ERROR + parameters: + - 'not found' + - '0' + error_handler: CUSTOM_VALUE + error_handler_params: '0' + tags: + - + tag: component + value: dns + - + uuid: 4efe4f6ca3a04fb79611569e0a5430de + name: 'DNS resolver 5 address' + type: CALCULATED + key: dns.resolver5.address + trends: '0' + value_type: TEXT + params: '{$RESOLVER5}' + tags: + - + tag: component + value: dns + - + uuid: 83cbd80d7969426fa25f77f5a667ecd2 + name: 'DNS resolver 5 available' + key: 'dns.resolver5.available[{$REQUEST},{$RESOLVER5}]' + preprocessing: + - + type: CHECK_REGEX_ERROR + parameters: + - 'not found' + - '0' + error_handler: CUSTOM_VALUE + error_handler_params: '0' + tags: + - + tag: component + value: dns + macros: + - + macro: '{$REQUEST}' + value: google.com + - + macro: '{$RESOLVER1}' + value: ns3-l2.nic.ru + - + macro: '{$RESOLVER2}' + value: ns4-l2.nic.ru + - + macro: '{$RESOLVER3}' + value: ns8-l2.nic.ru + - + macro: '{$RESOLVER4}' + value: ns4-cloud.nic.ru + - + macro: '{$RESOLVER5}' + value: ns8-cloud.nic.ru + triggers: + - + uuid: 91bc458eac464bd38709e1de596ea047 + expression: 'length(last(/DNS availability by Zabbix agent/dns.request))>0 and last(/DNS availability by Zabbix agent/dns.resolver1.available[{$REQUEST},{$RESOLVER1}],#1)<>1 and last(/DNS availability by Zabbix agent/dns.resolver2.available[{$REQUEST},{$RESOLVER2}],#1)<>1 and last(/DNS availability by Zabbix agent/dns.resolver3.available[{$REQUEST},{$RESOLVER3}],#1)<>1 and last(/DNS availability by Zabbix agent/dns.resolver4.available[{$REQUEST},{$RESOLVER4}],#1)<>1 and last(/DNS availability by Zabbix agent/dns.resolver5.available[{$REQUEST},{$RESOLVER5}],#1)<>1' + name: '{ITEM.VALUE1} not resolved by any DNS' + opdata: '{$REQUEST}, {$RESOLVER1}, {$RESOLVER2}, {$RESOLVER3}, {$RESOLVER4}, {$RESOLVER5}' + priority: HIGH + - + uuid: 372ac457598f46b4944cb26061037b24 + expression: 'length(last(/DNS availability by Zabbix agent/dns.request))>0 and length(last(/DNS availability by Zabbix agent/dns.resolver1.address))>0 and last(/DNS availability by Zabbix agent/dns.resolver1.available[{$REQUEST},{$RESOLVER1}],#1)<>1' + name: '{ITEM.VALUE1} not resolved by {ITEM.VALUE2}' + opdata: '{$REQUEST}, {$RESOLVER1}' + priority: AVERAGE + - + uuid: 91f4fbb34bc04e9e80e420075d092ab3 + expression: 'length(last(/DNS availability by Zabbix agent/dns.request))>0 and length(last(/DNS availability by Zabbix agent/dns.resolver2.address))>0 and last(/DNS availability by Zabbix agent/dns.resolver2.available[{$REQUEST},{$RESOLVER2}],#1)<>1' + name: '{ITEM.VALUE1} not resolved by {ITEM.VALUE2}' + opdata: '{$REQUEST}, {$RESOLVER2}' + priority: AVERAGE + - + uuid: 4cffdf0bddb043d89a9ba6cdec815856 + expression: 'length(last(/DNS availability by Zabbix agent/dns.request))>0 and length(last(/DNS availability by Zabbix agent/dns.resolver3.address))>0 and last(/DNS availability by Zabbix agent/dns.resolver3.available[{$REQUEST},{$RESOLVER3}],#1)<>1' + name: '{ITEM.VALUE1} not resolved by {ITEM.VALUE2}' + opdata: '{$REQUEST}, {$RESOLVER3}' + priority: AVERAGE + - + uuid: 06baf3ea932f472ea9b2f320728cadee + expression: 'length(last(/DNS availability by Zabbix agent/dns.request))>0 and length(last(/DNS availability by Zabbix agent/dns.resolver4.address))>0 and last(/DNS availability by Zabbix agent/dns.resolver4.available[{$REQUEST},{$RESOLVER4}],#1)<>1' + name: '{ITEM.VALUE1} not resolved by {ITEM.VALUE2}' + opdata: '{$REQUEST}, {$RESOLVER4}' + priority: AVERAGE + - + uuid: d1dd1aa7f9e1428c801160b1997b70e5 + expression: 'length(last(/DNS availability by Zabbix agent/dns.request))>0 and length(last(/DNS availability by Zabbix agent/dns.resolver5.address))>0 and last(/DNS availability by Zabbix agent/dns.resolver5.available[{$REQUEST},{$RESOLVER5}],#1)<>1' + name: '{ITEM.VALUE2} not resolved by {ITEM.VALUE1}' + opdata: '{$REQUEST}, {$RESOLVER5}' + priority: AVERAGE + graphs: + - + uuid: f455326ebf3a4aaabe7395665f965840 + name: 'DNS resolvers availability' + show_triggers: 'NO' + ymin_type_1: FIXED + graph_items: + - + drawtype: GRADIENT_LINE + color: FF0000 + item: + host: 'DNS availability by Zabbix agent' + key: 'dns.resolver1.available[{$REQUEST},{$RESOLVER1}]' + - + sortorder: '1' + drawtype: GRADIENT_LINE + color: FFFF00 + item: + host: 'DNS availability by Zabbix agent' + key: 'dns.resolver2.available[{$REQUEST},{$RESOLVER2}]' + - + sortorder: '2' + drawtype: GRADIENT_LINE + color: 00FF00 + item: + host: 'DNS availability by Zabbix agent' + key: 'dns.resolver3.available[{$REQUEST},{$RESOLVER3}]' + - + sortorder: '3' + drawtype: GRADIENT_LINE + color: 0080FF + item: + host: 'DNS availability by Zabbix agent' + key: 'dns.resolver4.available[{$REQUEST},{$RESOLVER4}]' + - + sortorder: '4' + drawtype: GRADIENT_LINE + color: BF00FF + item: + host: 'DNS availability by Zabbix agent' + key: 'dns.resolver5.available[{$REQUEST},{$RESOLVER5}]'