From bbad51d9ca931dafbead8e6c12f7946ebbb6615a Mon Sep 17 00:00:00 2001 From: Frederik Lindenaar <frederik@lindenaar.nl> Date: Tue, 9 Mar 2021 23:30:46 +0100 Subject: [PATCH] 2 optimizations: - got rid of unnecessary read commands to set variables - de-duplicate the list of nameservers to check before checking --- plugins/check_dns_replication | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/check_dns_replication b/plugins/check_dns_replication index 56e54d7..4b70fb4 100755 --- a/plugins/check_dns_replication +++ b/plugins/check_dns_replication @@ -56,8 +56,8 @@ NAGIOS_RESULT=0 NAGIOS_DETAILS= for DNS_ZONE in $DNS_ZONES; do - read AUTH_NAMESERVER <<<$(host -t soa $DNS_ZONE ${DNS_SERVERS// .*/} | tail -1 | cut -d\ -f5 | sed "s/.$//") - [ -n "$AUTH_NAMESERVER" ] && read AUTH_SOA_SERIAL <<<$(host -t soa $DNS_ZONE $AUTH_NAMESERVER | tail -1 | cut -d\ -f7) + AUTH_NAMESERVER=$(host -t soa $DNS_ZONE ${DNS_SERVERS// .*/} | tail -1 | cut -d\ -f5 | sed "s/.$//") + [ -n "$AUTH_NAMESERVER" ] && AUTH_SOA_SERIAL=$(host -t soa $DNS_ZONE $AUTH_NAMESERVER | tail -1 | cut -d\ -f7) if [ -z "$AUTH_SOA_SERIAL" ]; then NAGIOS_STATE=CRITICAL NAGIOS_RESULT=2 @@ -69,8 +69,9 @@ for DNS_ZONE in $DNS_ZONES; do NAMESERVER_EMPTY= NAMESERVERS=$DNS_SERVERS if [ -z "$DNS_SERVERS" -o "$DNS_SERVER_LOOKUP" == '-n' -o "$DNS_SERVERS" == "$AUTH_NAMESERVER" ]; then - NAMESERVERS="$NAMESERVERS $(host -t ns $DNS_ZONE $AUTH_NAMESERVER | fgrep -v : | sed "s/.* //;s/\.$//")" + NAMESERVERS="$NAMESERVERS $(host -t ns $DNS_ZONE $AUTH_NAMESERVER | fgrep -v : | sed "s/.* //;s/\.$//")" fi + NAMESERVERS=$(echo $NAMESERVERS | tr ' ' '\n' | sort -u) for NAMESERVER in $NAMESERVERS; do if [ "$NAMESERVER" != "$AUTH_NAMESERVER" ]; then SOA_SERIAL=$(host -t soa $DNS_ZONE $NAMESERVER | tail -1 | cut -d\ -f 7) -- libgit2 0.22.2