Install sntop on a Mac

From CoreInfo
Revision as of 13:48, 21 November 2011 by Admin (talk | contribs) (→‎Setup a log file)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
sntop running on a Mac inside Terminal

How to install sntop on Mac OS X Lion

sntop (simple network top)

What is sntop?

This is a port of sntop, a curses-based utility that uses fping (ping can be used as well) to determine connectivity of remote network hosts on a regular interval. Features include HTML generation and a secure terminal.

sntop is a CLI *nix based tool which will ping several sites continuously to check if it gives a ping response (if it's up or down). It's also helpful to see if your computer has internet connectivity, for those who have flaky internet.

Pre-Install tasks

  1. Download and install MacPorts
  2. Once installed check it's up to date
    sudo port selfupdate
  3. Install any updates
    sudo port upgrade
  4. Install fping, which is needed by sntop
    sudo port install fping

Install sntop

  1. Download sntop (Direct Link to 1.4.3 as of 20/10/2011)
  2. Extract the downloaded file tar.gz
    tar -zxvf sntop-1.4.3.tar.gz
  3. Go into the extracted directory
    cd sntop-1.4.3
  4. Configure it with the --prefix switch set to your ports directory
    ./configure --prefix=/opt/local/
  • Note: Do a make clean before continuing if you tried to make it without the --prefix option and it failed.
  1. make
  2. sudo make install
  3. If all went ok without any errors you should now be able to run
    sntop

Configuration

  • To add sites for it to monitor edit this file
mate /opt/local/etc/sntoprc

Setup a log file

  1. Start sntop and execute an .sh script when ever a service goes up or down
    sntop -r 30 -l ~/alarm.sh
  2. Use the sample script that came with sntop (I changed the below a bit), save it to to ~/alarm.sh
    #! /bin/sh
    # alarm.sh - Sample script for use with sntop's alarm/log mode
    # rml, 20001022
    
    # sntop supports two-modes, alarm and log, set via:
    #  -a <file>, --alarm=file
    #  -l <file>, --log=file
    # In alarm mode, whenever a site goes DOWN <file> is executed
    # In log mode, <file> is executed on any change in status
    # <file> is given three arguments: the display hostname, the
    #  actual hostname or IP address, and the new status (UP or DOWN)
    
    # This script will log to OUTFILE the time and date, the display
    #  name, and the status of the passed host.  If the host is DOWN
    #  (always the case in alarm mode), an e-mail is sent to root
    
    OUTFILE=$HOME/sntop.log
    
    if [ $3 = "DOWN" ]; then
            echo "sntop detected at `date` that $1 [$2] went $3" | mail -s "[sntop] Host Down!" root
    fi
    
    echo "sntop: `date`: $1 went $3" >> ${OUTFILE}
    
    # EOF
    
  3. Run the following in another terminal window to see when something goes down.
    tail -f  ~/sntop.log