Created
September 4, 2012 13:52
-
-
Save lonefreak/3621335 to your computer and use it in GitHub Desktop.
Logster Wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
usage() { | |
cat <<EOF | |
USAGE: $0 -h HOSTNAME [-p PORT] -f LOGFILE [-d -r] | |
HOSTNAME - hostname or IP address for the graphite server | |
PORT - port where the graphite server listens | |
LOGFILE - the path for the logfile that will be parsed | |
d - debug mode on | |
r - dry-run mode on | |
EOF | |
} | |
# -------------------------------------------------------------------- | |
# DEFAULT VALUES | |
PORT=2003 | |
METRIC="MetricLogster" | |
DEBUG="" | |
DRYRUN="" | |
# -------------------------------------------------------------------- | |
# PARSE COMMAND LINE OPTIONS | |
while getopts "h:p:f:dr" OPT; do | |
case "$OPT" in | |
h) # hostname | |
SERVER="$OPTARG" | |
;; | |
p) # port | |
PORT="$OPTARG" | |
;; | |
f) # logfile | |
LOGFILE="$OPTARG" | |
;; | |
r) # dry-run | |
DRYRUN="--dry-run" | |
;; | |
d) #debug | |
DEBUG="--debug" | |
esac | |
done | |
# -------------------------------------------------------------------- | |
# REQUIRED PARAMETERS VALIDATION | |
if [ -z $SERVER ]; then | |
echo "You must specify the hostname" | |
usage >&2 | |
exit 1 | |
fi | |
if [ -z $LOGFILE ]; then | |
echo "You must specify the logfile" | |
usage >&2 | |
exit 1 | |
fi | |
# -------------------------------------------------------------------- | |
# LOGSTER EXECUTION | |
if [ -f $LOGFILE ]; then | |
SOCKET=`nc -z $SERVER $PORT` | |
if [ "$?" -ne 0 ]; then | |
echo "Connection to $SERVER on port $PORT failed" | |
exit 1 | |
else | |
echo "Connection to $SERVER on port $PORT succeeded" | |
logster $DEBUG $DRYRUN --output=graphite --graphite-host=$SERVER:$PORT $METRIC $LOGFILE | |
echo "Logster executed" | |
exit 0 | |
fi | |
else | |
echo "Logfile not found!" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment