Skip to content

Commit

Permalink
Improved syslog facility and level (eg: daemon.info) #12
Browse files Browse the repository at this point in the history
Closes #12
  • Loading branch information
nemesifier committed Feb 12, 2016
1 parent b0e1d6d commit 7b94d09
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
64 changes: 32 additions & 32 deletions openwisp-config/files/openwisp.agent
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ done

if [ -z "$URL" ]; then
logger -s "missing required --url option" \
-t "openwisp" \
-p 3
-t openwisp \
-p daemon.err
exit 2
fi

if ([ -z "$UUID" ] || [ -z "$KEY" ]) && [ -z "$SHARED_SECRET" ]; then
logger -s "you must either specify --uuid and --key, or --shared-secret" \
-t "openwisp" \
-p 3
-t openwisp \
-p daemon.err
exit 3
fi

Expand Down Expand Up @@ -66,17 +66,17 @@ check_header(){
local is_controller=$(grep -c "X-Openwisp-Controller: true" $1)
if [ $is_controller -lt 1 ]; then
logger -s "Invalid url: missing X-Openwisp-Controller header" \
-t "openwisp" \
-p 3
-t openwisp \
-p daemon.err
exit 4
fi
}

# performs automatic registration
register() {
logger -s "Registering new device" \
-t "openwisp" \
-p 6
-t openwisp \
-p daemon.info
# gets the mac address of the first interface that shows in ifconfig
local name=$(ifconfig | grep -v lo | grep HWaddr | awk '/HWaddr/ { print $5 }' | head -n 1)
local backend="netjsonconfig.OpenWrt"
Expand All @@ -87,8 +87,8 @@ register() {
if [ $(head -n 1 $REGISTRATION_PARAMETERS | grep -c "201 Created") -lt 1 ]; then
local message=$(cat $REGISTRATION_PARAMETERS | grep "error:")
logger -s "Registration failed! $message" \
-t "openwisp" \
-p 3
-t openwisp \
-p daemon.err
exit 5
fi
# set configuration options and reload
Expand All @@ -101,8 +101,8 @@ register() {
uci commit openwisp
rm $REGISTRATION_PARAMETERS
logger -s "Device registered successfully as $name, id: $UUID" \
-t "openwisp" \
-p 6
-t openwisp \
-p daemon.info
}

# gets checksum from controller
Expand All @@ -112,16 +112,16 @@ get_checksum() {

if [ "$exit_code" != "0" ]; then
logger -s "Failed to connect to controller (checksum): curl exit code $exit_code" \
-t "openwisp" \
-p 3
-t openwisp \
-p daemon.err
return 2
fi

if [ $(head -n 1 $1 | grep -c "200 OK") -lt 1 ]; then
local status=$(head -n 1 $1)
logger -s "Failed to retrieve checksum: $status" \
-t "openwisp" \
-p 3
-t openwisp \
-p daemon.err
return 3
fi
check_header $1
Expand All @@ -141,8 +141,8 @@ configuration_changed() {

if [ "$CURRENT_CHECKSUM" != "$REMOTE_CHECKSUM" ]; then
logger -s "Configuration in controller has changed" \
-t "openwisp" \
-p 6
-t openwisp \
-p daemon.info
return 1
fi

Expand All @@ -159,8 +159,8 @@ apply_configuration() {

if [ "$exit_code" != "0" ]; then
logger -s "Could not restore configuration: sysupgrade exit code $exit_code" \
-t "openwisp" \
-p 2
-t openwisp \
-p daemon.crit
return 1
fi
# merge default config (if enabled)
Expand All @@ -177,16 +177,16 @@ report_status() {

if [ "$exit_code" != "0" ]; then
logger -s "Failed to connect to controller (report-status): curl exit code $exit_code" \
-t "openwisp" \
-p 3
-t openwisp \
-p daemon.err
return 2
fi

if [ $(head -n 1 $STATUS_REPORT | grep -c "200 OK") -lt 1 ]; then
local status=$(head -n 1 $STATUS_REPORT)
logger -s "Failed to report status: $status" \
-t "openwisp" \
-p 3
-t openwisp \
-p daemon.err
return 3
fi
check_header $STATUS_REPORT
Expand All @@ -210,8 +210,8 @@ test_configuration() {

if [ $test_ret -gt 0 ]; then
logger -s "Configuration test failed! Restoring previous backup" \
-t "openwisp" \
-p 3
-t openwisp \
-p daemon.err
apply_configuration $CONFIGURATION_BACKUP
report_status "error"
local ret=1
Expand Down Expand Up @@ -243,8 +243,8 @@ store_default() {
fi
cp "/etc/config/$config" "$DEFAULT_DIR/$config"
logger -s "Stored $DEFAULT_DIR/$config" \
-t "openwisp" \
-p 6
-t openwisp \
-p daemon.info
fi
done
}
Expand Down Expand Up @@ -273,8 +273,8 @@ update_configuration() {

if [ "$exit_code" != "0" ]; then
logger -s "Failed to connect to controller (download configuration): curl exit code $exit_code" \
-t "openwisp" \
-p 3
-t openwisp \
-p daemon.err
return 3
fi

Expand All @@ -286,8 +286,8 @@ update_configuration() {

if [ "$?" == "0" ]; then
logger -s "Configuration applied" \
-t "openwisp" \
-p 6
-t openwisp \
-p daemon.info
fi
}

Expand Down
16 changes: 8 additions & 8 deletions openwisp-config/files/openwisp.init
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ start_service() {

if [ -z "$url" ]; then
logger -s "url is not set, please add it in /etc/config/openwisp" \
-t "openwisp" \
-p 3
-t openwisp \
-p daemon.err
exit 1
fi

if ([ -z "$uuid" ] || [ -z "$key" ]) && [ -z "$shared_secret" ]; then
logger -s "you must either set uuid and key, or shared_secret in /etc/config/openwisp" \
-t "openwisp" \
-p 3
-t openwisp \
-p daemon.err
exit 1
fi

Expand All @@ -52,8 +52,8 @@ start_service() {
procd_set_param respawn
procd_close_instance
logger -s "$PROG_NAME started" \
-t "openwisp" \
-p 6
-t openwisp \
-p daemon.info
}

service_triggers() {
Expand All @@ -62,6 +62,6 @@ service_triggers() {

stop_service() {
logger -s "$PROG_NAME stopping" \
-t "openwisp" \
-p 6
-t openwisp \
-p daemon.info
}

0 comments on commit 7b94d09

Please sign in to comment.