Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F31689386
raw.txt
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
Volans
Mar 18 2020, 11:58 AM
2020-03-18 11:58:37 (UTC+0)
Size
3 KB
Referenced Files
None
Subscribers
None
raw.txt
View Options
#!/bin/bash
function parse_wmnet() {
local origin=""
local skip=0
echo "Processing zonefile wmnet"
while read -r line; do
if [[ "${line}" =~ ^\; ]]; then
continue
elif [[ "${line}" =~ ^\$ORIGIN\ ]]; then
origin="$(echo "${line}" | cut -d " " -f2)"
if [[ "${origin:0:5}" != "mgmt." ]]; then
echo "Skipping origin ${origin}"
skip=1
else
echo "Found origin ${origin}"
skip=0
fi
continue
fi
if [[ -z "${origin}" || "${skip}" -eq "1" ]]; then
continue
fi
git grep -iq "$(echo "$line" | sed -E 's/ +/ */g')" "${origin::${#origin}-1}" || echo "Missing line: ${line}"
done < "${1}/wmnet"
}
function parse_forward_snippet() {
local file="${1}"
local snippet=$(basename ${file})
local zone="wmnet"
if [[ "${snippet}" == "wikimedia.org" ]]; then
zone="wikimedia.org"
fi
echo "Processing snippet ${snippet} against zonefile ${zone}"
while read -r line; do
git grep -iq "$(echo "$line" | sed -E 's/ +/ */g')" "${zone}" || echo "Missing line: ${line}"
done < "${file}"
}
function parse_reverse_zonefile() {
local file="${1}"
local ext="${2}"
local origin=""
local skip=0
local zone
zone="$(echo "${file##*/}" | rev | cut -d"." -f3- | rev)"
echo "Processing zone ${zone} in zonefile ${file##*/}"
while read -r line; do
if [[ "${line}" =~ ^\; ]]; then
continue
elif [[ "${line}" =~ ^\$ORIGIN\ ]]; then
origin="$(echo "${line}" | cut -d " " -f2 | sed "s/@Z/${zone}/")"
if [[ "${origin}" == "{{" ]]; then
echo "Skipping dynamically generated origin (k8s most likely)"
skip=1
elif [[ ! -f "${origin}${ext}" ]]; then
echo "Skipping origin ${origin} due to missing zonefile ${origin}${ext}"
skip=1
else
echo "Found origin ${origin}"
skip=0
fi
continue
fi
if [[ -z "${origin}" || "${skip}" -eq "1" ]]; then
continue
fi
git grep -iq "$(echo "$line" | sed -E 's/ +/ */g')" "${origin}${ext}" || echo "Missing line: ${line}"
done < "${file}"
}
if [[ -z "${1}" ]]; then
echo "Usage: ${0} PATH_TO_OTHER_REPO_ZONEFILES"
echo "Run from within the repo to check against the other repo"
echo "Example: ./consistency_check.sh ops/dns/templates"
echo "Example: ./consistency_check.sh netbod/dns"
exit 1
fi
if [[ -e "${1}/wmnet" ]]; then
echo "Checking all ops/dns repo records are present here"
for file in "${1}"/*.in-addr.arpa; do
parse_reverse_zonefile "${file}" ".in-addr.arpa"
done
for file in "${1}"/*.ip6.arpa; do
parse_reverse_zonefile "${file}" ".ip6.arpa"
done
parse_wmnet "${1}"
else
echo "Checking all netbox generated records are present in the ops/dns repo"
for file in "${1}"/*; do
if [[ "${file}" =~ \.in-addr\.arpa$ ]]; then
parse_reverse_zonefile "${file}" ".in-addr.arpa"
elif [[ "${file}" =~ \.ip6\.arpa$ ]]; then
parse_reverse_zonefile "${file}" ".ip6.arpa"
else
parse_forward_snippet "${file}"
fi
done
fi
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
8355151
Default Alt Text
raw.txt (3 KB)
Attached To
Mode
P10716 Script to compare Netbox-generated DNS snippets and the operations/dns templates (T233183)
Attached
Detach File
Event Timeline
Log In to Comment