Skip to content

Commit

Permalink
[enhancement] Add verbose_mode for easy debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
devkapilbansal committed Jul 15, 2021
1 parent cb2c854 commit d860640
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Configuration options
UCI configuration options must go in ``/etc/config/monitoring``.

- ``monitored_interfaces``: interfaces that needs to be monitored, defaults to ``*`` for all interfaces.
- ``interval``: time after which device data should be sent to server, defaults to ``300``
- ``interval``: time after which device data should be sent to server, defaults to ``300``.
- ``verbose_mode``: can be used to get verbose output in case of error for easy `debugging <#debugging>`__, defaults to 0.

Compiling openwrt-openwisp-monitoring
-------------------------------------
Expand Down
15 changes: 9 additions & 6 deletions openwrt-openwisp-monitoring/files/monitoring.agent
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ while [ -n "$1" ]; do
--verify_ssl) export verify_ssl="$2"; shift;;
--interval) export INTERVAL="$2"; shift;;
--monitored_interfaces) export MONITORED_INTERFACES=$2; shift;;
--verbose_mode) export verbose_mode=$2; shift;;
-*)
echo "Invalid option: $1"
exit 1
Expand All @@ -25,13 +26,12 @@ if [ "$VERSION" -eq "1" ]; then
exit 0
fi

CURL_COMMAND="curl -s -w "%{http_code}""
if [ "$verify_ssl" = 0 ]; then
CURL_COMMAND="$CURL_COMMAND -k"
fi

URL="$BASE_URL/api/v1/monitoring/device/$UUID/?key=$KEY"

CURL_COMMAND="curl -s -w "%{http_code}""
[ "$verify_ssl" = "0" ] && CURL_COMMAND="$CURL_COMMAND -k"
[ "$verbose_mode" = "1" ] && CURL_COMMAND="$CURL_COMMAND -v"

collect_data(){
n=0
logger -s "Collecting NetJSON Monitoring data" \
Expand Down Expand Up @@ -64,7 +64,10 @@ do
-t monitoring \
-p daemon.info
else
logger -s "Data not sent successfully. Response code is $response_code" \
logger -s "Data not sent successfully. Response code is $response_code." \
-t monitoring \
-p daemon.err
logger -s "Run with verbose mode to find more." \
-t monitoring \
-p daemon.err
fi
Expand Down
1 change: 1 addition & 0 deletions openwrt-openwisp-monitoring/files/monitoring.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
config monitoring 'monitoring'
option monitored_interfaces '"*"'
option interval '300'
option verbose_mode '0'
6 changes: 4 additions & 2 deletions openwrt-openwisp-monitoring/files/monitoring.init
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ start_service() {
config_load openwisp_monitoring
config_get monitored_interfaces monitoring monitored_interfaces "'*'"
config_get interval monitoring interval "300"
config_get_bool verbose_mode monitoring verbose_mode "1"

interval="$(time_to_seconds "$interval")"
if [ "$interval" -lt 1 ]; then
Expand All @@ -50,11 +51,12 @@ start_service() {
fi
interval="--interval $interval"
monitored_interfaces="--monitored_interfaces $monitored_interfaces"
verbose="--verbose_mode $verbose_mode"

procd_open_instance "openwisp_monitoring_monitoring"
procd_set_param command $PROG $base_url $uuid $key $verify_ssl $interval $monitored_interfaces
procd_set_param command $PROG $base_url $uuid $key $verify_ssl $interval $monitored_interfaces $verbose
procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
procd_set_param stderr 1
[ "$verbose_mode" = "1" ] && procd_set_param stderr 1
procd_close_instance
logger -s "$PROG_NAME started" \
-t monitoring \
Expand Down

0 comments on commit d860640

Please sign in to comment.