Description: Simple script to replace as-* cli from AWS
 The AWS Cloud Watch tools include an array of command-line tools which are
 chain on each other. To reduce the maintenance burden, the as-* commands are
 replaced with as symlinks to /usr/bin/moncli. moncli uses the arg zero to
 determine which application called it and then directly invokes the Java JVM.
 The advantage with this approach is that the invocation and maintenance is
 very straight forward.
 .
 moncli (1.0.61.0-0ubuntu1) UNRELEASED; urgency=low
 .
   * New upstream release.
Author: Ben Howard <ben.howard@ubuntu.com>

--- /dev/null
+++ b/moncli
@@ -0,0 +1,135 @@
+#!/bin/bash
+#
+## Copyright 2012, Ben Howard <ben.howard@ubuntu.com>
+##
+## This program is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+## This is a simple wrapper around the AWS Cloud Watch JAR files. This
+## script replaces all the Cloud Watch scripts and makes it easy to
+## both maintain and add new features.
+
+# Find out what command are we running
+link_cmd="${0##*/}"
+
+usage() {
+	echo "${0##*/} is a wrapper script for invoking Cloud Watch commands"
+	echo "Usage:"
+	echo "   --desc <name>   : Shows help for a single Cloud Watch Command"
+	echo "   --commands      : Shows available command line programs"
+	echo "   --help          : Shows this menu"
+	echo "   <COMMAND> <OPT> : Run Cloud Watch commands directly"
+}
+
+
+# Set home paths
+export AWS_CLOUDWATCH_HOME=${AWS_CLOUDWATCH_HOME:-"/usr/share/moncli"}
+export jshared=${AWS_AUTO_SCALING_JAVA_SHARED_CLASSPATH:-"/usr/share/java/activation.jar:/usr/share/java/commons-cli.jar:/usr/share/java/commons-codec.jar:/usr/share/java/commons-discovery.jar:/usr/share/java/commons-httpclient.jar:/usr/share/java/commons-logging.jar:/usr/share/java/commons-logging-api.jar:/usr/share/java/jdom1.jar:/usr/share/java/joda-time.jar:/usr/share/java/log4j-1.2.jar:/usr/share/java/serializer.jar:/usr/share/java/stax-api.jar:/usr/share/java/wsdl4j.jar:/usr/share/java/wss4j.jar:/usr/share/java/xalan2.jar"}
+
+# Discover service home for jar file discovery
+[ -d "${AWS_CLOUDWATCH_HOME}/lib" ] && LIBDIR="${AWS_CLOUDWATCH_HOME}/lib" ||
+   LIBDIR="${AWS_CLOUDWATCH_HOME}"
+
+# Preserve classpaths an
+for j in "${LIBDIR}"/*.jar; do cp="${cp:+${cp}:}${j}"; done
+[ -n "${CLASSPATH%:}" ] && cp="${CLASSPATH%:}:${cp}"
+[ "${jshared#@@}" != "${jshared}" ] || cp="${cp}:${jshared}"
+
+
+# Check AWS_CLOUDWATCH_HOME
+if [ -z "${AWS_CLOUDWATCH_HOME}" ]; then
+        echo AWS_CLOUDWATCH_HOME is not set
+        exit 1
+fi
+
+# Construct a list of the valid commands
+valid_cmds=( "mon-delete-alarms"
+	"mon-describe-alarm-history"
+	"mon-describe-alarms"
+	"mon-describe-alarms-for-metric"
+	"mon-disable-alarm-actions"
+	"mon-enable-alarm-actions"
+	"mon-get-stats"
+	"mon-list-metrics"
+	"mon-put-data"
+	"mon-put-metric-alarm"
+	"mon-set-alarm-state"
+        "mon-version"
+)
+
+JAVA_CMD="${JAVA_COMMAND:-`which java`} ${AWS_CLOUDWATCH_JVM_ARGS} -classpath ${cp} com.amazon.webservices.Cli"
+ld=${AWS_CLOUDWATCH_HOME:-/usr/share/moncli}
+
+[ "${link_cmd}" == "mon-version" ] && exec ${JAVA_CMD} version
+
+# Execute the command
+for cmd in ${valid_cmds[@]}
+do
+	if [ "${link_cmd}" = "${cmd}" ]; then
+		exec ${JAVA_CMD} "${cmd}" "${@}"
+	fi
+done
+
+# Check if moncli was executed directly
+if [ "${link_cmd}" == "moncli" ]; then
+	if [ "${1}" == "--commands" ]; then
+
+		# Show valid commands
+		for cmd in "${valid_cmds[@]}"; do echo "$cmd"; done
+		exit 0
+
+	elif [ "${1}" == "--desc" ]; then
+
+		if [ "${2}" == "Command" ]; then
+			# If no command is defined, show all
+			exec ${JAVA_CMD}
+
+		elif [ "${2}" == "moncli" ]; then
+			usage
+			exit 0
+
+		else
+			# Describe individual command
+			exec ${JAVA_CMD} "${2}" "--help"
+		fi
+
+	elif [ "${1}" == "--version" ]; then
+
+		# Get the version
+		exec ${JAVA_CMD} version
+
+	elif [ "${1}" == "--help" -o "${1}" == "-h" ]; then
+
+		usage
+		exit 0
+
+	elif [[ "${1}" =~ "as-" ]]; then
+
+		# Direct execution of command, by passing link
+		exec ${JAVA_CMD} "${@}"
+
+	else
+
+		# Otherwise command is invalid
+		ver=$($JAVA_CMD version)
+		echo "${ver}"
+		echo "${0} is a simple wrapper script used for executing AWS Cloud Watch"
+		echo "commands. Please see --help or --commands determine what commands"
+		echo "are available"
+		exit 1
+
+	fi
+fi
+
+echo "${link_cmd} is an invalid command!"
+exit 1
--- /dev/null
+++ b/moncli.1
@@ -0,0 +1,44 @@
+.TH ASCLI "1" "1.0.61.0 api=" "Cloud Watch command line tools" "User Commands"
+.SH NAME
+.B moncli
+\- Cloud Watch command line tool wrapper.
+.SH SYNOPSIS
+moncli [--help|--desc|<COMMAND>]
+.br
+.SH OPTIONS
+.TP
+.B --help
+Show the usage information
+.TP
+.B --desc
+Describe an Cloud Watch command's help.
+.TP
+.B [COMMAND] [ARGS]
+Invoke Cloud Watch command
+.SH DESCRIPTION
+moncli is a wrapper script around the AWS Cloud Watch Commands. Its usual invocation is as a symbolic link via the direct name of the Cloud Watch command intended to be used. moncli replaces the stacked scripts provided by AWS with a single script.
+.br
+.SH EXAMPLES
+Example 1:  moncli describe-alarms --region us-east-1
+.br
+Show Cloud Watch groups in us-east-1
+.P
+Example 2:  moncli --help
+.br
+Show the help page
+.P
+.SH VERSION
+This documentation describes
+.B moncli
+version 1.0.61.0
+.SH "SEE ALSO"
+
+.br
+.I http://docs.amazonwebservices.com/CloudWatch/DeveloperGuide/
+.br
+.I http://docs.amazonwebservices.com/CloudWatch/latest/DeveloperGuide/
+.SH AUTHOR
+.br
+.B Ben Howard
+.br
+.I \<ben.howard@canonical.com\>
