Skip to content

Commit

Permalink
Feature.20171130 (#31)
Browse files Browse the repository at this point in the history
* Added command line switches to change the default DB step and ping count

* Added command line switches to change the default DB step and ping count
  • Loading branch information
vhsjwp01 authored and David Personette committed Dec 3, 2017
1 parent 73c03eb commit 737bf89
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ at the '/smokeping/smokeping.cgi' URI.
Usage: smokeping.sh [-opt] [command]
Options (fields in '[]' are optional, '<>' are required):
-h This help
-c "<count>" Configure the default ping count
possible arg: \"[integer]\" - ping count
-g "<user;pass>" Configure ssmtp so that email alerts can be sent
required arg: "<user>" - your gmail username
required arg: "<pass>" - your gmail password of app password
Expand All @@ -39,6 +41,8 @@ at the '/smokeping/smokeping.cgi' URI.
required arg: "<email>" - your email address
-o "<name>" Configure name of the owner of smokeping
required arg: "<name>" - your name
-s "<step>" Configure the time step for DB entries
possible arg: \"[integer]\" - time step in seconds
-t "<site;name;target>[;alert]" Configure smokeping targets
required arg: "<site>" - name for site of tests
required arg: "<name>" - name for check
Expand All @@ -58,6 +62,8 @@ ENVIRONMENT VARIABLES (only available with `docker run`)
* `SSMTP_GMAIL` As above configure ssmtp for gmail, set to `user;pass`
* `EMAIL` - As above, your email address as the owner `[email protected]`
* `OWNER` - As above, your name as the owner `Bob Hope`
* `PING` - As above, the number of pings to try
* `STEP` - As above, the time step for DB entries
* `TARGET` - As above a target to check, set to `site;name;target[;alert]`
* `TZ` - As above, configure the zoneinfo timezone, IE `EST5EDT`
* `USERID` - Set the UID for the app user
Expand Down
26 changes: 25 additions & 1 deletion smokeping.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ owner() { local name="$1" file=/etc/smokeping/config.d/General
sed -i "s|^\(owner = \).*|\\1$name|" $file
}

### pingcount: Configure the ping count
# Arguments:
# ping_count) ping count
# Return: setup ping count in /etc/smokeping/config.d/Database
pingcount() { local ping_count="$1" file=/etc/smokeping/config.d/Database
sed -i "s|^\(pings.*=\).*$|\1 $ping_count|g" $file
}

### dbstep: Configure the default DB Step interval
# Arguments:
# step_time) DB step time in seconds
# Return: setup DB step time in /etc/smokeping/config.d/Database
dbstep() { local step_time="$1" file=/etc/smokeping/config.d/Database
sed -i "s|^\(step.*=\).*$|\1 $step_time|g" $file
}

### target: Configure a smokeping target
# Arguments:
# site) name for site of tests
Expand Down Expand Up @@ -133,6 +149,8 @@ usage() { local RC=${1:-0}
echo "Usage: ${0##*/} [-opt] [command]
Options (fields in '[]' are optional, '<>' are required):
-h This help
-c \"<count>\" Configure the default ping count
possible arg: \"[integer]\" - ping count
-e \"<email>\" Configure email address for owner of smokeping
required arg: \"<email>\" - your email address
-o \"<name>\" Configure name of the owner of smokeping
Expand All @@ -141,6 +159,8 @@ Options (fields in '[]' are optional, '<>' are required):
required arg: \"<user>\" - your gmail username
required arg: \"<pass>\" - your gmail password of app password
These are only set in your docker container
-s \"<step>\" Configure the time step for DB entries
possible arg: \"[integer]\" - time step in seconds
-t \"<site;name;target>[;alert]\" Configure smokeping targets
required arg: \"<site>\" - name for site of tests
required arg: \"<name>\" - name for check
Expand All @@ -156,12 +176,14 @@ The 'command' (if provided and valid) will be run instead of smokeping
exit $RC
}

while getopts ":hg:e:o:t:T:w" opt; do
while getopts ":hg:e:o:c:s:t:T:w" opt; do
case "$opt" in
h) usage ;;
c) pingcount "$OPTARG" ;;
g) eval gmail $(sed 's/^\|$/"/g; s/;/" "/g' <<< $OPTARG) ;;
e) email "$OPTARG" ;;
o) owner "$OPTARG" ;;
s) dbstep "$OPTARG" ;;
t) eval target $(sed 's/^\|$/"/g; s/;/" "/g' <<< $OPTARG) ;;
T) timezone "$OPTARG" ;;
w) wipe ;;
Expand All @@ -176,6 +198,8 @@ shift $(( OPTIND - 1 ))
$SSMTP_GMAIL)
[[ "${EMAIL:-""}" ]] && email "$EMAIL"
[[ "${OWNER:-""}" ]] && owner "$OWNER"
[[ "${PING:-""}" ]] && pingcount "$PING"
[[ "${STEP:-""}" ]] && dbstep "$STEP"
[[ "${TARGET:-""}" ]] && eval target $(sed 's/^\|$/"/g; s/;/" "/g' <<< $TARGET)
[[ "${TZ:-""}" ]] && timezone "$TZ"
[[ "${USERID:-""}" =~ ^[0-9]+$ ]] && usermod -u $USERID -o smokeping
Expand Down

0 comments on commit 737bf89

Please sign in to comment.