| monitor.rc - monitor - monitor script | |
| git clone git://git.suckless.org/monitor | |
| Log | |
| Files | |
| Refs | |
| LICENSE | |
| --- | |
| monitor.rc (2199B) | |
| --- | |
| 1 #!/usr/local/plan9/bin/rc | |
| 2 # | |
| 3 # requires | |
| 4 # - 9base | |
| 5 # - ping | |
| 6 # - curl | |
| 7 # - netcat (nc) | |
| 8 # - dig | |
| 9 # | |
| 10 PATH=/usr/local/plan9/bin:$PATH | |
| 11 | |
| 12 hosts=(\ | |
| 13 suckless.org:88.99.169.165:[email protected]:1:1:1:1\ | |
| 14 sta.li:88.99.169.165:[email protected]:1:1:0.0\ | |
| 15 garbe.us:94.130.56.76:[email protected]:1:1:1:1\ | |
| 16 flycyg.com:35.156.38.103:[email protected]:0:1:1:1\ | |
| 17 ) | |
| 18 | |
| 19 fn ok { | |
| 20 line=$line^' 1' | |
| 21 html=$html^'<td class="ok">OK</td>' | |
| 22 } | |
| 23 | |
| 24 fn fail { | |
| 25 line=$line^' 0' | |
| 26 if(~ $1 '1') { | |
| 27 html=$html^'<td class="fail">FAIL</td>' | |
| 28 failtext=$failtext^'['^$2^': FAIL]' | |
| 29 } | |
| 30 if not | |
| 31 html=$html^'<td class="na">NA</td>' | |
| 32 } | |
| 33 | |
| 34 fn check_host { | |
| 35 ifs=(':') { pair=`{echo -n $1} } | |
| 36 host=$pair(1) | |
| 37 ip=$pair(2) | |
| 38 contact=$pair(3) | |
| 39 icmp_required=$pair(4) | |
| 40 http_required=$pair(5) | |
| 41 dns_required=$pair(6) | |
| 42 smtp_required=$pair(7) | |
| 43 failtext='' | |
| 44 line=`{date -n} | |
| 45 now=`{date -u} | |
| 46 html='<tr><td>'^$"now^'</td>' | |
| 47 # ICMP | |
| 48 if(ping -c 1 $host >/dev/null >[2]/dev/null) | |
| 49 ok | |
| 50 if not { | |
| 51 sleep 5 | |
| 52 if(ping -c 1 $host >/dev/null >[2]/dev/null) | |
| 53 ok | |
| 54 if not | |
| 55 fail $icmp_required 'ICMP' | |
| 56 } | |
| 57 # HTTP | |
| 58 if(curl -I 'http://'^$host --connect-timeout 10 >/dev/null >[2]/… | |
| 59 ok | |
| 60 if not { | |
| 61 sleep 5 | |
| 62 if(curl -I 'http://'^$host --connect-timeout 10 >/dev/nu… | |
| 63 ok | |
| 64 if not | |
| 65 fail $http_required 'HTTP' | |
| 66 } | |
| 67 # DNS | |
| 68 if(dig $host | grep -v '^;' | grep A | grep $ip >/dev/null >[2]/… | |
| 69 ok | |
| 70 if not { | |
| 71 sleep 5 | |
| 72 if(dig $host | grep -v '^;' | grep A | grep $ip >/dev/nu… | |
| 73 ok | |
| 74 if not | |
| 75 fail $dns_required 'DNS' | |
| 76 } | |
| 77 # SMTP | |
| 78 if(nc -z -w 5 $host 25 >/dev/null >[2]/dev/null) | |
| 79 ok | |
| 80 if not { | |
| 81 sleep 5 | |
| 82 if(nc -z -w 5 $host 25 >/dev/null >[2]/dev/null) | |
| 83 ok | |
| 84 if not | |
| 85 fail $smtp_required 'SMTP' | |
| 86 } | |
| 87 echo $line >> '/data/'^$host^'.dat' | |
| 88 gnuplot '/data/'^$host^'.gnu' > '/var/www/static/monitor.garbe.u… | |
| 89 html=$html^'<td><img src="'^$host^'.png"/></td></tr>' | |
| 90 echo $html >> /var/www/static/monitor.garbe.us/index.html | |
| 91 if(~ $failtext '') | |
| 92 ; | |
| 93 if not | |
| 94 echo $failtext | mail -s $host $contact | |
| 95 } | |
| 96 | |
| 97 cat /var/www/static/monitor.garbe.us/head.tpl > /var/www/static/monitor.… | |
| 98 for(i in $hosts) | |
| 99 check_host $i | |
| 100 cat /var/www/static/monitor.garbe.us/foot.tpl >> /var/www/static/monitor… |