Commit 8413b737 authored by Yuanle Song's avatar Yuanle Song
Browse files

use user.err when logging error message.

parent bee89d8f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -35,3 +35,7 @@ it does not report errors.
* TODO split config from source code.
  config variables should be set in /etc/ddclient-http.conf
  and it can be sourced by the source code.

  move username, password, domain name, update URL to $HOME/.ddclient-httprc

  then source that at run time.
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ install: install-dependence
	install -m 644 etc/rsyslog-filter /etc/rsyslog.d/ddclient-http.conf
	install -m 644 etc/crontab /etc/cron.d/ddclient-http
# log file must be created before restarting rsyslog.
	install -m 640 -o root -g adm /dev/null /var/log/ddclient-http.log
	test -e /var/log/ddclient-http.log || install -m 640 -o root -g adm /dev/null /var/log/ddclient-http.log
# note: reload will not work. a full restart is required.
	/etc/init.d/rsyslog restart
install-dependence:
+17 −12
Original line number Diff line number Diff line
@@ -26,6 +26,11 @@ log() {
	logger -t ddclient_http "$@"
}

# Usage: err [MESSAGE..]
err() {
	logger -t ddclient_http -p user.err "$@"
}

# set MYIP variable to my internet IP address.
# Returns true on success, false on failure.
get_myip() {
@@ -34,7 +39,7 @@ get_myip() {
	if [ "$CURL_EXIT_CODE" -eq 0 ]; then
		return 0
	else
		log "get_myip() failed. curl exit code is $CURL_EXIT_CODE."
		err "get_myip() failed. curl exit code is $CURL_EXIT_CODE."
		exit $GET_MYIP_FAILED
	fi
}
@@ -47,7 +52,7 @@ require_update() {
	#
	# dig always return 0! if no A record is found, OLDIP will be empty.
	if [ -z "$OLDIP" ]; then
		log "Can't get current binding IP. dig failed."
		err "Can't get current binding IP. dig failed."
		exit $DIG_FAILED
	fi
	if [ "$OLDIP" = "$MYIP" ]; then
@@ -67,10 +72,10 @@ do_update() {
	CURL_EXIT_CODE=$?
	case $CURL_EXIT_CODE in
		0) log "curl ok." ;;
		6) log "curl error: Couldn't resolve host." ;;
		7) log "curl error: Failed to connect to host." ;;
		28) log "curl error: Operation timeout." ;;
		*) log "curl error: exit code $CURL_EXIT_CODE.";;
		6) err "curl error: Couldn't resolve host." ;;
		7) err "curl error: Failed to connect to host." ;;
		28) err "curl error: Operation timeout." ;;
		*) err "curl error: exit code $CURL_EXIT_CODE.";;
	esac
	if  [ $CURL_EXIT_CODE -ne 0 ]; then
		exit $UPDATE_REQUEST_FAILED
@@ -80,12 +85,12 @@ do_update() {
	case "$HTTP_RESPONSE" in
		good) log "good: update accepted."
			return 0 ;;
		nochg) log "nochg: IP not changed." ;;
		badauth) log "badauth: user or password incorrect." ;;
		abuse) log "abuse: hostname is blocked for update abuse." ;;
		dnserr) log "dnserr: DNS error encountered." ;;
		911) log "911: server problem." ;;
		*) log "Error: return code is ${HTTP_RESPONSE}." ;;
		nochg) err "nochg: IP not changed." ;;
		badauth) err "badauth: user or password incorrect." ;;
		abuse) err "abuse: hostname is blocked for update abuse." ;;
		dnserr) err "dnserr: DNS error encountered." ;;
		911) err "911: server problem." ;;
		*) err "Error: return code is ${HTTP_RESPONSE}." ;;
	esac
	exit $UPDATE_REJECTED
}
+3 −2
Original line number Diff line number Diff line
# /etc/rsyslog.d/ddclient-http
# :msg, contains, "iptablesfw DROP: "    -/var/log/ddclient-http.log
# & ~

# TODO alert root via email.
if $syslogseverity-text == 'err' and $app-name == 'ddclient_http' then root,sylecn

:app-name, isequal, "ddclient_http"    -/var/log/ddclient-http.log
& ~