Skip to content

Commit

Permalink
Set hostname to uname -n if DB is on localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhq committed Jan 16, 2020
1 parent 805b50f commit 27a105e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions zabbix-dump
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,17 @@ esac
# Log file for errors
ERRORLOG=$(mktemp)

# Host name: try reverse lookup if IP is given
DBHOSTNAME="$DBHOST"
# Host name
if [[ -z "$DBHOST" || "$DBHOST" == "127.0.0.1" || "$DBHOST" == "127.0.0.1" ]]; then
DBHOSTNAME="$(uname -n)"
else
DBHOSTNAME="$DBHOST"
fi

# Try reverse lookup if IP is given
command -v dig >/dev/null 2>&1
FIND_DIG=$?
if [ "$REVERSELOOKUP" == "yes" ] && [ $FIND_DIG -eq 0 ] && [ -n "$DBHOST" ]; then
if [[ "$REVERSELOOKUP" == "yes" && $FIND_DIG -eq 0 && -n "$DBHOST" ]]; then
# Try resolving a given host ip
newHostname=$(dig +noall +answer -x "${DBHOST}" | sed -r 's/((\S+)\s+)+([^\.]+)\..*/\3/')
test \! -z "$newHostname" && DBHOSTNAME="$newHostname"
Expand Down

0 comments on commit 27a105e

Please sign in to comment.