jablonka.czprosek.czf

netmap

Subversion Repositories:
[/] [work/] [calstats-0.1.2/] [calstats/] [gen_stats] - Rev 14 Go to most recent revision

Compare with Previous - Blame - Download


#!/bin/sh

# (c)2003 by Jan Krupa (krupaj@mobilnews.cz)
# http://www.mobilnews.cz/honza/

# -- Configuration ---------------------------------------------------
# CaLStats directory and data paths
STATS_PATH=/usr/local/calstats
STATS_PATH_DATA=$STATS_PATH/data
STATS_PATH_OUT=$STATS_PATH/out
STATS_PATH_TMP=$STATS_PATH/tmp

# Program paths
PHP_PATH=/usr/bin/php4
PING_PATH=ping
NMAP_PATH=nmap
FPING_PATH=fping

# STATS_TYPE - ping, fping or nmap
STATS_TYPE=ping

# Don't change anything bellow this line if you are not sure what
# you are doing ;)
# --------------------------------------------------------------------

for LINE in `ls -1 $STATS_PATH_DATA | grep .config`; do
    a_file=`echo $LINE | awk -F. '{ printf "%s", $1 }'`

    file_comp=$STATS_PATH_DATA/$a_file.comp
    file_state=$STATS_PATH_DATA/$a_file.state

    # Get computer states
    if [ $STATS_TYPE = "fping" ]; then
        ping_host_all=""

        for LINE in `cat $file_comp`; do
            ping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $2 }'`
            ping_host_all="${ping_host_all} ${ping_host}"
        done
        $FPING_PATH -e $ping_host_all | awk -F\  '{ printf "%s;", $1; if ($3=="alive") printf "1;%s;\n", substr($4, 2, (length($4)-1)); else printf "0;0;\n"; }' > $file_state
    fi

    if [ $STATS_TYPE = "ping" ]; then
        for LINE in `cat $file_comp`; do
            ping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $2 }'`;

            ping_lat=\;`$PING_PATH -c 1 -w 2 $ping_host | grep rtt | awk -F\  '{ printf "%s", $4 }' | awk -F\/ ' { printf "%s", $2 }'`;
            if [ "$ping_lat" = ";" ]; then
                ping_lat=\;`$PING_PATH -c 1 -w 2 $ping_host | grep rtt | awk -F\  '{ printf "%s", $4 }' | awk -F\/ ' { printf "%s", $2 }'`;
            fi

            if [ "$ping_lat" = ";" ]; then
                echo $ping_host\;0\;0\;; > $file_state
            else
                echo $ping_host\;1$ping_lat\;; > $file_state
            fi
        done
    fi

    if [ $STATS_TYPE = "nmap" ]; then
        ping_host_all=""

        for LINE in `cat $file_comp`; do
            ping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $2 }'`
            ping_host_all="${ping_host_all} ${ping_host}"
        done

        $NMAP_PATH -vnsP $ping_host_all | awk -F\  '{ if ($1=="Host") { if (match($2, /\(/) == 0) { printf "%s;", $2; } else { printf "%s;", substr($2, 2, (length($2)-2)); } if ($6=="up.") printf "1;0;\n"; else printf "0;0;\n"; } }' > $file_state
    fi    

    # Create picture to temporary location
    $PHP_PATH -q $STATS_PATH/calstats.php $STATS_PATH_DATA/$a_file > $STATS_PATH_TMP/$a_file.png

    # Move picture to output location
    mv -f $STATS_PATH_TMP/$a_file.png $STATS_PATH_OUT
done

Powered by WebSVN 2.2.1