public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Trace
data/Dockerfiles/watchdog/check_dns.sh
Trace helps you understand code history line by line. See who changed each line, when it changed, and which commit introduced it.
Author
Date
Commit
Line
Code
1
#!/bin/sh
3
while getopts "H:s:" opt; do
4
case "$opt" in
5
H) HOST="$OPTARG" ;;
6
s) SERVER="$OPTARG" ;;
7
*) echo "Usage: $0 -H host -s server"; exit 3 ;;
8
esac
9
done
11
if [ -z "$SERVER" ]; then
12
echo "No DNS Server provided"
13
exit 3
14
fi
16
if [ -z "$HOST" ]; then
17
echo "No host to test provided"
18
exit 3
19
fi
21
# run dig and measure the time it takes to run
22
START_TIME=$(perl -MTime::HiRes -e 'print Time::HiRes::time')
23
dig_output=$(dig +short +timeout=2 +tries=1 "$HOST" @"$SERVER" 2>/dev/null)
24
dig_rc=$?
25
END_TIME=$(perl -MTime::HiRes -e 'print Time::HiRes::time')
26
dig_output_ips=$(echo "$dig_output" | grep -E '^[0-9.]+$' | sort | paste -sd ',' -)
27
ELAPSED_TIME=$(perl -e "printf('%.3f', $END_TIME - $START_TIME)")
29
# validate and perform nagios like output and exit codes
30
if [ $dig_rc -ne 0 ] || [ -z "$dig_output" ]; then
31
echo "Domain $HOST was not found by the server"
32
exit 2
33
elif [ $dig_rc -eq 0 ]; then
34
echo "DNS OK: $ELAPSED_TIME seconds response time. $HOST returns $dig_output_ips"
35
exit 0
36
else
37
echo "Unknown error"
38
exit 3
39
fi