1 | 1 | unreal | #!/bin/sh |
2 | | | |
3 | | | # (c)2003 by Jan Krupa (krupaj@mobilnews.cz) |
4 | | | # http://www.mobilnews.cz/honza/ |
5 | | | # Changes by Jirka Klir (Unreal][) for Mapstats v3.0 AJAX. http://www.jklir.net |
6 | | | |
7 | | | # -- Configuration --------------------------------------------------- |
8 | | | # Mapstats directory |
9 | | | STATS_PATH=/var/www/www.kobylisy.czf/mapstats |
10 | | | |
11 | | | # Program paths |
12 | | | PING_PATH=ping |
13 | | | NMAP_PATH=nmap |
14 | | | FPING_PATH=fping |
15 | | | |
16 | | | # STATS_TYPE - ping, fping or nmap |
17 | | | STATS_TYPE=ping |
18 | | | |
19 | 9 | unreal | # -------------------------------------------------------------------- |
20 | 1 | unreal | # Don't change anything bellow this line if you are not sure what |
21 | | | # you are doing ;) |
22 | | | # -------------------------------------------------------------------- |
23 | | | |
24 | 9 | unreal | cd $STATS_PATH |
25 | | | |
26 | | | for LINE in `ls -1 $STATS_PATH | grep .nodes`; do |
27 | 1 | unreal | a_file=`echo $LINE | awk -F. '{ printf "%s", $1 }'` |
28 | | | |
29 | | | file_comp=$STATS_PATH/$a_file.nodes |
30 | | | file_state=$STATS_PATH/$a_file.state |
31 | | | |
32 | | | printf "" > $file_state |
33 | | | # Get computer states |
34 | | | if [ $STATS_TYPE = "fping" ]; then |
35 | | | ping_host_all="" |
36 | | | |
37 | | | for LINE in `cat $file_comp`; do |
38 | | | ping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $5 }'` |
39 | | | ping_host_all="${ping_host_all} ${ping_host}" |
40 | | | done |
41 | | | $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 |
42 | | | fi |
43 | | | |
44 | | | if [ $STATS_TYPE = "ping" ]; then |
45 | | | for LINE in `cat $file_comp`; do |
46 | | | ping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $5 }'`; |
47 | | | |
48 | | | ping_lat=\;`$PING_PATH -c 1 -w 2 $ping_host | grep rtt | awk -F\ '{ printf "%s", $4 }' | awk -F\/ ' { printf "%s", $2 }'`; |
49 | | | if [ "$ping_lat" = ";" ]; then |
50 | | | ping_lat=\;`$PING_PATH -c 1 -w 2 $ping_host | grep rtt | awk -F\ '{ printf "%s", $4 }' | awk -F\/ ' { printf "%s", $2 }'`; |
51 | | | fi |
52 | | | |
53 | | | if [ "$ping_lat" = ";" ]; then |
54 | | | echo "$ping_host;0;0" >> $file_state |
55 | | | else |
56 | | | echo "$ping_host;1$ping_lat" >> $file_state |
57 | | | fi |
58 | | | done |
59 | | | |
60 | | | fi |
61 | | | |
62 | | | if [ $STATS_TYPE = "nmap" ]; then |
63 | | | ping_host_all="" |
64 | | | |
65 | | | for LINE in `cat $file_comp`; do |
66 | | | ping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $5 }'` |
67 | | | ping_host_all="${ping_host_all} ${ping_host}" |
68 | | | done |
69 | | | |
70 | | | $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;-\n"; else printf ";0;-\n"; } }' > $file_state |
71 | | | fi |
72 | | | |
73 | | | done |