diff --git a/Dockerfile b/Dockerfile index dfaf337..b8beda9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM lsiobase/alpine:3.7 +# copy tcpping script +COPY tcpping /defaults/ + # set version label ARG BUILD_DATE ARG VERSION @@ -16,11 +19,19 @@ RUN \ smokeping \ ssmtp \ sudo \ + tcptraceroute \ ttf-dejavu && \ - echo "**** give abc sudo access to traceroute ****" && \ - echo "abc ALL=(ALL) NOPASSWD: /usr/bin/traceroute" >> /etc/sudoers.d/traceroute && \ + echo "**** give abc sudo access to traceroute & tcptraceroute ****" && \ + echo \ + "abc ALL=(ALL) NOPASSWD: /usr/bin/traceroute" >> \ + /etc/sudoers.d/traceroute && \ + echo \ + "abc ALL=(ALL) NOPASSWD: /usr/bin/tcptraceroute" >> \ + /etc/sudoers.d/tcptraceroute && \ echo "**** fix path to cropper.js ****" && \ sed -i 's#src="/cropper/#/src="cropper/#' /etc/smokeping/basepage.html && \ + echo "**** install tcping script ****" && \ + install -m755 -D /defaults/tcpping /usr/bin/ && \ echo "**** remove default apache conf ****" && \ rm -f /etc/apache2/httpd.conf diff --git a/README.md b/README.md index 5e24fb8..eb6ed5c 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ To monitor the logs of the container in realtime `docker logs -f smokeping`. ## Versions ++ **08.04.18:** Add tccping script and tcptraceroute package (thanks rcarmo). + **13.12.17:** Expose httpd_conf to /config. + **13.12.17:** Rebase to alpine 3.7. + **24.07.17:** Add :unraid tag for hosts without ipv6. diff --git a/tcpping b/tcpping new file mode 100644 index 0000000..05366ac --- /dev/null +++ b/tcpping @@ -0,0 +1,144 @@ +#!/bin/sh +# +# tcpping: test response times using TCP SYN packets +# URL: http://www.vdberg.org/~richard/tcpping.html +# +# uses tcptraceroute from http://michael.toren.net/code/tcptraceroute/ +# +# (c) 2002-2005 Richard van den Berg under the GPL +# http://www.gnu.org/copyleft/gpl.html +# +# 2002/12/20 v1.0 initial version +# 2003/01/25 v1.1 added -c and -r options +# now accepting all other tcptraceroute options +# 2003/01/30 v1.2 removed double quotes around backquotes +# 2003/03/25 v1.3 added -x option, courtesy of Alvin Austin +# 2005/03/31 v1.4 added -C option, courtesy of Norman Rasmussen +# 2007/01/11 v1.5 catch bad destination addresses +# 2007/01/19 v1.6 catch non-root tcptraceroute +# 2008/02/10 v1.7 make -C work when reverse lookup fails, courtesy of Fabrice Le Dorze + + +ver="v1.7" +format="%Y%m%d%H%M%S" +d="no" +c="no" +C="no" +ttl=255 +seq=0 +q=1 +r=1 +w=3 +topts="" + +usage () { + name=`basename $0` + echo "tcpping $ver Richard van den Berg " + echo + echo "Usage: $name [-d] [-c] [-C] [-w sec] [-q num] [-x count] ipaddress [port]" + echo + echo " -d print timestamp before every result" + echo " -c print a columned result line" + echo " -C print in the same format as fping's -C option" + echo " -w wait time in seconds (defaults to 3)" + echo " -r repeat every n seconds (defaults to 1)" + echo " -x repeat n times (defaults to unlimited)" + echo + echo "See also: man tcptraceroute" + echo +} + +_checksite() { + ttr=`tcptraceroute -f ${ttl} -m ${ttl} -q ${q} -w ${w} $* 2>&1` + if echo "${ttr}" | egrep -i "(bad destination|got roo)" >/dev/null 2>&1; then + echo "${ttr}" + exit + fi +} + +_testsite() { + myseq="${1}" + shift + [ "${c}" = "yes" ] && nows=`date +${format}` + [ "${d}" = "yes" ] && nowd=`date` + ttr=`tcptraceroute -f ${ttl} -m ${ttl} -q ${q} -w ${w} $* 2>/dev/null` + host=`echo "${ttr}" | awk '{print $2 " " $3}'` + rtt=`echo "${ttr}" | sed 's/.*] //' | awk '{print $1}'` + not=`echo "${rtt}" | tr -d ".0123456789"` + [ "${d}" = "yes" ] && echo "$nowd" + if [ "${c}" = "yes" ]; then + if [ "x${rtt}" != "x" -a "x${not}" = "x" ]; then + echo "$myseq $nows $rtt $host" + else + echo "$myseq $nows $max $host" + fi + elif [ "${C}" = "yes" ]; then + if [ "$myseq" = "0" ]; then + echo -n "$1 :" + fi + if [ "x${rtt}" != "x" -a "x${not}" = "x" ]; then + echo -n " $rtt" + else + echo -n " -" + fi + if [ "$x" = "1" ]; then + echo + fi + else + echo "${ttr}" | sed -e "s/^.*\*.*$/seq $myseq: no response (timeout)/" -e "s/^$ttl /seq $myseq: tcp response from/" + fi +# echo "${ttr}" +} + +while getopts dhq:w:cr:nNFSAEi:f:l:m:p:s:x:C opt ; do + case "$opt" in + d|c|C) eval $opt="yes" ;; + q|w|r|x) eval $opt="$OPTARG" ;; + n|N|F|S|A|E) topt="$topt -$opt" ;; + i|l|p|s) topt="$topt -$opt $OPTARG" ;; + f|m) ttl="$OPTARG" ;; + ?) usage; exit ;; + esac +done + +shift `expr $OPTIND - 1` + +if [ "x$1" = "x" ]; then + usage + exit +fi + +max=`echo "${w} * 1000" | bc` + +if [ `date +%s` != "%s" ]; then + format="%s" +fi + +_checksite ${topt} $* + +if [ "$x" = "" ]; then + while [ 1 ] ; do + _testsite ${seq} ${topt} $* & + pid=$! + if [ "${C}" = "yes" ]; then + wait $pid + fi + seq=`expr $seq + 1` + sleep ${r} + done +else + while [ "$x" -gt 0 ] ; do + _testsite ${seq} ${topt} $* & + pid=$! + if [ "${C}" = "yes" ]; then + wait $pid + fi + seq=`expr $seq + 1` + x=`expr $x - 1` + if [ "$x" -gt 0 ]; then + sleep ${r} + fi + done +fi + +exit