ping-response/0042755000000000000000000000000007401221576012357 5ustar rootrootping-response/gencfg.sh0100755000000000000000000001551507401221576014151 0ustar rootroot#!/bin/sh HOSTNAME="myHost (myIP)" WORKDIR="/usr/local/mrtg/net" WEBDIR="$WORKDIR/net-stat-html" FPING="/usr/sbin/fping" ICONDIR="/mrtg/" INTERVAL=5 HOST_TIMEOUT=500 MRTG_EXEC="/usr/bin/mrtg" MAINTAINER="Dan Podeanu" function usage () { echo "Usage: $0 : .." exit } if [ "$1" = "" ]; then usage fi echo "Generating config files:" echo echo "Configuring with workdir: $WORKDIR" echo "Configuring with webdir: $WEBDIR" echo "Configuring with fping: $FPING" echo "Configuring with icondir: $ICONDIR" echo "Configuring with refresh interval: $INTERVAL" echo "Configuring with host timeout: $HOST_TIMEOUT" echo ".. don't forget to update corresponding values in $WORKDIR/net.sh" echo if [ ! -x $FPING ]; then echo "Please modify this script and set FPING to the path to fping." echo "(or look into the README file)" exit fi if [ -s $WORKDIR/mrtg-run.sh ]; then echo "Creating backup of mrtg-run file into $WORKDIR/mrtg-run.sh.old" mv -f $WORKDIR/mrtg-run.sh $WORKDIR/mrtg-run.sh.old chmod -x $WORKDIR/mrtg-run.sh.old fi rm -f $WORKDIR/mrtg-run.sh if [ -s $WORKDIR/add-hosts.sh ]; then echo "Creating backup of add hosts file into $WORKDIR/add-hosts.sh.old" mv -f $WORKDIR/add-hosts.sh $WORKDIR/add-hosts.sh.old chmod -x $WORKDIR/add-hosts.sh.old fi rm -f $WORKDIR/add-hosts.sh if [ -s $WEBDIR/index.html ]; then echo "Creating backup of index file into $WEBDIR/index.html.old" mv -f $WEBDIR/index.html $WEBDIR/index.html.old fi rm -f $WEBDIR/index.html if [ ! -d $WEBDIR ]; then echo "Creating web directory $WEBDIR" mkdir -p $WEBDIR fi echo "" >> $WEBDIR/index.html echo " " >> $WEBDIR/index.html echo " Network statistics " >> $WEBDIR/index.html echo " " >> $WEBDIR/index.html echo " " >> $WEBDIR/index.html echo "

" >> $WEBDIR/index.html echo "


" >> $WEBDIR/index.html echo >> $WEBDIR/index.html echo " Network statistics for $HOSTNAME" >> $WEBDIR/index.html echo "

" >> $WEBDIR/index.html echo >> $WEBDIR/index.html echo "#!/bin/sh" >> $WORKDIR/add-hosts.sh echo >> $WORKDIR/add-hosts.sh echo "#" >> $WORKDIR/add-hosts.sh echo "# Automatically generated file that rebuilds the MRTG configuration" >> $WORKDIR/add-hosts.sh echo "# as it was entered at `date`" >> $WORKDIR/add-hosts.sh echo "#" >> $WORKDIR/add-hosts.sh echo "# If you edit this, please remove this comment aswell." >> $WORKDIR/add-hosts.sh echo "#" >> $WORKDIR/add-hosts.sh echo >> $WORKDIR/add-hosts.sh echo -n "$0" >> $WORKDIR/add-hosts.sh echo echo "---------- GENERATING MRTG CONFIG FILES ----------" _count=0 while [ ! "$1" = "" ]; do echo if [ `echo $1` = `echo $1 | tr -d :` ]; then echo "Invalid format specification: $1" usage fi _hostname=`echo $1 | cut -f1 -d:` _hostip=`echo $1 | cut -f2 -d:` if [ "$_hostname" = "" -o "$_hostip" = "" ]; then echo "Invalid format specification: $1" usage exit fi echo " \\" >> $WORKDIR/add-hosts.sh echo -n " $1" >> $WORKDIR/add-hosts.sh echo "Adding host $_hostname with IP $_hostip:" if [ -s $WORKDIR/mrtg-gen-$_hostname.cfg ]; then echo "Creating backup of old config file into $WORKDIR/mrtg-gen-$_hostname.cfg.old" mv -f $WORKDIR/mrtg-gen-$_hostname.cfg $WORKDIR/mrtg-gen-$_hostname.cfg.old fi rm -f $WORKDIR/mrtg-gen-$_hostname.cfg echo "Creating directory $WEBDIR/$_hostname" mkdir -p $WEBDIR/$_hostname echo "# MRTG config file automatically generated by $0" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "# Please try to not modify it manually. If you do, do not send" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "# bug reports to pdan@extreme.ro, as you normally should do." >> $WORKDIR/mrtg-gen-$_hostname.cfg echo >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "WorkDir: $WEBDIR/$_hostname" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "IconDir: $ICONDIR" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "Interval: $INTERVAL" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "Title[$_hostname]: $_hostname ($_hostip)" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "PageTop[$_hostname]:

Ping response statistics for $_hostname ($_hostip)

" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "Target[$_hostname]: \`$WORKDIR/net.sh $_hostname:$_hostip\`" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "MaxBytes[$_hostname]: $HOST_TIMEOUT" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "Supress[$_hostname]: y" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "LegendI[$_hostname]: ping response time" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "LegendO[$_hostname]: ping response time" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "YLegend[$_hostname]: msec" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "ShortLegend[$_hostname]: msec" >> $WORKDIR/mrtg-gen-$_hostname.cfg # echo "Options[$_hostname]: gauge,unknaszero,nopercent" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "Options[$_hostname]: gauge,nopercent" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "Legend1[$_hostname]: first ping response time" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "Legend2[$_hostname]: second ping response time" >> $WORKDIR/mrtg-gen-$_hostname.cfg echo "Generated config file: $WORKDIR/mrtg-gen-$_hostname.cfg" echo "$MRTG_EXEC $WORKDIR/mrtg-gen-$_hostname.cfg &" >> $WORKDIR/mrtg-run.sh _count=$[$_count + 1] _l_name=`echo $_hostname | awk '{ print tolower($1) }'` echo " Statistics for $_hostname" >> $WEBDIR/index.html echo "
" >> $WEBDIR/index.html echo >> $WEBDIR/index.html shift done echo >> $WORKDIR/add-hosts.sh echo "


" >> $WEBDIR/index.html echo "
" >> $WEBDIR/index.html echo " Page maintained by: $MAINTAINER" >> $WEBDIR/index.html echo " " >> $WEBDIR/index.html echo "" >> $WEBDIR/index.html chmod +x $WORKDIR/mrtg-run.sh chmod +x $WORKDIR/add-hosts.sh echo echo "---------- GENERATION COMPLETED ----------" echo echo "Generated mrtg-run file $WORKDIR/mrtg-run.sh" echo echo "Generated add hosts file $WORKDIR/add-hosts.sh, edit/add it to add more hosts to" echo "the current configuration (and run it, of course)." echo echo "Generated html file $WEBDIR/index.html" echo echo "Link $WEBDIR someplace in your html structure and add a link to $WEBDIR/index.html" echo echo "Copy the MRTG icon files (mrtg/lib/*.png) into a /mrtg/icons/ in your html root directory" echo echo "Add the following line in your crontab '*/$INTERVAL * * * * $WORKDIR/mrtg-run.sh'" echo "(or ensure that $WORKDIR/mrtg-run.sh is ran every $INTERVAL minutes, if your crontab format differs" echo echo ".. don't forget to update corresponding values in $WORKDIR/net.sh" echo echo "Done adding $_count host(s)." ping-response/net.sh0100755000000000000000000000161607401221462013475 0ustar rootroot#!/bin/sh # # MRTG: generate statistics for the given IP # MRTG: the format is: : WORKDIR="/usr/local/mrtg/net" FPING="/usr/sbin/fping" HOST_TIMEOUT=500 if [ "$1" = "" ]; then echo 0 echo 0 echo "invalid number of parameters for script call" echo "invalid number of parameters for script call" exit fi _line=$1 _hostname=`echo $_line | cut -f1 -d:` _hostip=`echo $_line | cut -f2 -d:` _result=`$FPING -C 2 -q -p $HOST_TIMEOUT $_hostip 2>&1 | tail -1` _ip=`echo $_result | cut -f1 -d: | awk '{ print $1 }'` _res1=`echo $_result | cut -f2 -d: | awk '{ print $1 }'` _res2=`echo $_result | cut -f2 -d: | awk '{ print $2 }'` if [ "$_res1" = "-" ]; then _res1="$HOST_TIMEOUT"; # _res1="0"; fi if [ $_res2 = "-" ]; then _res2="$HOST_TIMEOUT"; # _res2="0"; fi #_res1=$[$_res1 * $MULTIPLY] #_res2=$[$_res2 * $MULTIPLY] echo $_res1 echo $_res2 echo "quite some time" echo "$_hostname ($_ip)" ping-response/README0100644000000000000000000000742607401221462013235 0ustar rootroot This is a mrtg config file generator for pinging servers and parsing the output through MRTG. [ PROVIDED FILES ] (if you just plan to install this, skip to BASIC STEPS TO INSTALL topic below) Contents: ### net.sh: The actual script that pings the servers is net.sh. It relies on fping being available. Quote from 'man 8 fping' AUTHORS Roland J. Schemers III, Stanford University, concept and versions 1.x RL "Bob" Morgan, Stanford University, versions 2.x ZeroHype Technologies Inc. (http://www.zerohype.com), versions 2.3x and up, fping website: http://www.fping.com The script accepts as parameter a : pair (with ':' as delimiter), but normally you should not be interested in this, as it is called only internally by MRTG. ---- You MUST edit it and change as following: set WORKDIR to the root of your ping statistics (normally, this dir). set FPING to the path of your fping program (normally, /usr/sbin/fping) set HOST_TIMEOUT to the maximum ping delay before fping decides that the host is unreachable (I have it set to 500 msec) ### gencfg.sh This scripts generates the required mrtg config files, aswell as other various files. It accepts as paramters as string of one or more pairs :, corresponding to the hosts you want pinged. ---- You MUST edit it and change as following: set HOSTNAME to your hostname, to be used when reporting the statistics. This can be anything. set WORKDIR to the root of your ping statistics (normally, this dir). set WEBDIR to the dir where MRTG will generate the statistics. set FPING to the path of your fping program (normally, /usr/sbin/fping). set ICONDIR to the path where you plan copying MRTG's .png files. set INTERVAL to the number of minutes between calling MRTG (normally, 5). set HOST_TIMEOUT to the maximum ping delay before fping decides that the host is unreachable (I have it set to 500 msec) set MRTG_EXEC to the path to MRTG's executable. set MAINTAINER to a html string describing the maintainer of the page. You can now run ./gencfg.sh with a number of parameters. Example: ./gencfg.sh dns.ripe.net:193.0.0.193 www.extreme.ro:212.93.159.195 This will generate several files: - MRTG config files are in mrtg-gen-.cfg - The script that calls MRTG on the config files is in ./mrtg-run.sh - The web directory will be created, with a directory inside it for each host that is watched. - Inside the web directory you will find a file named 'index.html' that contains links to the hosts' MRTG files. - The ./add-hosts.sh file will be generated. By running it as it is, you will duplicate the effect of the command you're running (ie. re-build the upper mentioned files). If you want to add more hosts to watch, simply edit it and add one more line with its : pair. ### clean.sh This script will remove all generated files, except for add-hosts.sh file (in case you want to generate/move the MRTG statistics to another host), or change your mind. [ BASIC STEPS TO INSTALL ] - Uncompress this into a directory of your choice. - Modify gencfg.sh and set HOSTNAME, WORKDIR, WEBDIR, FPING and MAINTAINER accordingly (and/or the other options aswell). - Modify net.sh and set WORKDIR and FPING accordingly (and/or the other options aswell). - Run ./gencfg.sh : : .. - Link WEBDIR someplace in your apache html structure, add a link somewhere among your html files. - Copy the MRTG .png files (that can be found in mrtg/lib/mrtg) into your ICONDIR (usually defined as /mrtg/icons/, with the root your apache html root directory) - Add mrtg-run.sh with full path to your crontab, running every INTERVAL minutes (usually 5 minutes). You should be done now. --------------------------- Written by Dan Podeanu, pdan@extreme.ro, distributed under GNU. ping-response/clean.sh0100755000000000000000000000045507401221462013771 0ustar rootroot#!/bin/sh # # Completely removes existing configuration (but does not reset add-hosts.sh, if any). # echo "Cleaning up..." rm -rf *.old mrtg-gen* net-stat-html echo "#!/bin/sh" > mrtg-run.sh if [ -s add-hosts.sh ]; then echo "You can rebuild your previous configuration by running ./add-hosts.sh" fi ping-response/add-hosts.sh0100755000000000000000000000132007401221462014565 0ustar rootroot#!/bin/sh # # Automatically generated file that rebuilds the MRTG configuration # as it was entered at Wed Nov 28 05:22:35 EET 2001 # # If you edit this, please remove this comment aswell. # ./gencfg.sh \ LocalRDSNet--rds-Bucharest-HFC-eth2-12-10M.rdsnet.ro:212.93.133.1 \ FrankfurtRDSNet--401.ATM1-0.gw7.Frankfurt1.de.alter.net:139.4.42.217 \ FXNet--E0-0.lex.buc.fxnet.ro:193.231.209.1 \ RoEduNet--ns1.roedu.net:192.129.4.1 \ KappaNet--k-docsis.iex.ro:194.102.255.233 \ RNC--webvir.rnc.ro:193.230.31.221 \ RIPE--dns.ripe.net:193.0.0.193 \ PBTECH--core.m20-ams01.level3.trueserver.nl:213.244.164.246 \ XXXCAM--www.xxxcam.com:213.239.149.43 \ YAHOO--www.yahoo.com:64.58.76.227 \ STAR--ravnos.org:24.93.58.62 ping-response/mrtg-run.sh0100755000000000000000000000001207401221470014446 0ustar rootroot#!/bin/sh