#!/bin/sh
#
# NetJSON Monitoring

show_help() {
	printf "Usage:\n"
	printf "  netjson-monitoring [OPTIONS...]\n"
	printf "\n"
	printf "Use Netjson Monitoring to get current device metrics data.\n"
	printf "\n"
	printf "Options:\n"
	printf "  -h, --help\t\t\t\t: Show this help text\n"
	printf "  -v, --version\t\t\t\t: Shows version of the agent.\n"
	printf "  --dump \"<interfaces>\"\t\t\t: Dump device metrics data.\n"
	printf "\t\"<interfaces>\" is a space separated list of interfaces from which traffic stats"
	printf " will be collected.\n "
	printf "\tPassing a quoted asterisk (eg: \"*\") will extract traffic statistics from all interfaces.\n"
	exit 0
}

show_version() {
	VERSION=$(cat /etc/openwisp-monitoring/VERSION)
	echo "$(basename "$0") $VERSION"
	exit 0
}

main() {
	# parse options
	while [ -n "$1" ]; do
		case "$1" in
			--version | -v)
				show_version
				;;
			--help | -h)
				show_help
				;;
			--dump)
				shift
				/usr/libexec/netjson-monitoring "$@"
				exit 0
				;;
			-*)
				echo "Invalid option: $1"
				;;
			*) break ;;
		esac
		shift
	done

	show_help
	exit 0
}

main "$@"
