1 | 1 | simandl | #!/bin/sh |
2 | | | |
3 | | | # (c)2003 by Jan Krupa (krupaj@mobilnews.cz) |
4 | | | # http://www.mobilnews.cz/honza/ |
5 | | | |
6 | | | # -- Configuration --------------------------------------------------- |
7 | | | # CaLStats directory and data paths |
8 | | | STATS_PATH=/usr/local/calstats |
9 | | | STATS_PATH_DATA=$STATS_PATH/data |
10 | | | STATS_PATH_OUT=$STATS_PATH/out |
11 | | | STATS_PATH_TMP=$STATS_PATH/tmp |
12 | | | |
13 | | | # Program paths |
14 | | | PHP_PATH=/usr/bin/php4 |
15 | | | PING_PATH=ping |
16 | | | NMAP_PATH=nmap |
17 | | | FPING_PATH=fping |
18 | | | |
19 | | | # STATS_TYPE - ping, fping or nmap |
20 | | | STATS_TYPE=ping |
21 | | | |
22 | | | # Don't change anything bellow this line if you are not sure what |
23 | | | # you are doing ;) |
24 | | | # -------------------------------------------------------------------- |
25 | | | |
26 | | | for LINE in `ls -1 $STATS_PATH_DATA | grep .config`; do |
27 | | | a_file=`echo $LINE | awk -F. '{ printf "%s", $1 }'` |
28 | | | |
29 | | | file_comp=$STATS_PATH_DATA/$a_file.comp |
30 | | | file_state=$STATS_PATH_DATA/$a_file.state |
31 | | | |
32 | | | # Get computer states |
33 | | | if [ $STATS_TYPE = "fping" ]; then |
34 | | | ping_host_all="" |
35 | | | |
36 | | | for LINE in `cat $file_comp`; do |
37 | | | ping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $2 }'` |
38 | | | ping_host_all="${ping_host_all} ${ping_host}" |
39 | | | done |
40 | | | $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 |
41 | | | fi |
42 | | | |
43 | | | if [ $STATS_TYPE = "ping" ]; then |
44 | | | for LINE in `cat $file_comp`; do |
45 | | | ping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $2 }'`; |
46 | | | |
47 | | | ping_lat=\;`$PING_PATH -c 1 -w 2 $ping_host | grep rtt | awk -F\ '{ printf "%s", $4 }' | awk -F\/ ' { printf "%s", $2 }'`; |
48 | | | if [ "$ping_lat" = ";" ]; then |
49 | | | ping_lat=\;`$PING_PATH -c 1 -w 2 $ping_host | grep rtt | awk -F\ '{ printf "%s", $4 }' | awk -F\/ ' { printf "%s", $2 }'`; |
50 | | | fi |
51 | | | |
52 | | | if [ "$ping_lat" = ";" ]; then |
53 | | | echo $ping_host\;0\;0\;; > $file_state |
54 | | | else |
55 | | | echo $ping_host\;1$ping_lat\;; > $file_state |
56 | | | fi |
57 | | | done |
58 | | | fi |
59 | | | |
60 | | | if [ $STATS_TYPE = "nmap" ]; then |
61 | | | ping_host_all="" |
62 | | | |
63 | | | for LINE in `cat $file_comp`; do |
64 | | | ping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $2 }'` |
65 | | | ping_host_all="${ping_host_all} ${ping_host}" |
66 | | | done |
67 | | | |
68 | | | $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 |
69 | | | fi |
70 | | | |
71 | | | # Create picture to temporary location |
72 | | | $PHP_PATH -q $STATS_PATH/calstats.php $STATS_PATH_DATA/$a_file > $STATS_PATH_TMP/$a_file.png |
73 | | | |
74 | | | # Move picture to output location |
75 | | | mv -f $STATS_PATH_TMP/$a_file.png $STATS_PATH_OUT |
76 | | | done |