Loading

Netsplit detector

  1. ; Netsplit detector
  2. ; By Joshua
  3. ; Detects a netsplit. Writes a little notification in status and in a custom window
  4.  
  5. ; Setup initialization
  6. on *:start: {
  7.   .hmake NetSplits 1000
  8.   if ($isfile(netsplits.hsh)) { .hload NetSplits netsplits.hsh }
  9.   if (!$hget(NetSplits,$+($network,.start))) { .hadd -m NetSplits $+($network,.start) $ctime }
  10.   if (!$hget(NetSplits,$+($network,.people))) { .hadd -m NetSplits $+($network,.people) 0 }
  11.   if (!$hget(NetSplits,$+($network,.last))) { .hadd -m NetSplits $+($network,.last) $ctime }
  12.   if (!$hget(NetSplits,$+($network,.netsplits))) { .hadd -m NetSplits $+($network,.netsplits) 0 }
  13. }
  14. on *:disconnect: { .hsave NetSplits netsplits.hsh }
  15. on *:exit: { .hsave NetSplits netsplits.hsh }
  16.  
  17. ; Monitor netsplits
  18. on ^*:QUIT: {
  19.   if (Quit: !isin $1-) {
  20.     if ($1 == *.net) && ($2 == *.split) || (*.*.* iswm $1 && *.*.* iswm $2) {
  21.       if (!%netsplit) {
  22.         echo 9 -tg [NETSPLIT] Netsplit detected between $1 and $2
  23.         if (!$window(@NetSplit)) { window -xnthez @NetSplit }
  24.         aline -pa @NetSplit $timestamp $+($chr(91),NETSPLIT - $network,$chr(93)) $+($1,$chr(32),$chr(60),$chr(45),$chr(62),$2)
  25.         .hinc -m NetSplits $+($network,.netsplits) 1
  26.         .set -u60 %netsplit 1
  27.         .hadd -m NetSplits $+($network,.last) $ctime
  28.       }
  29.       elseif (%netsplit) {
  30.         .hinc -m NetSplits $+($network,.people) 1
  31.       }
  32.     }
  33.   }
  34. }
  35.  
  36. alias netsplit {
  37.   if ($1 == -p) {
  38.     msg $active $logo(NetSplits) I have seen $cc2($bytes($hget(NetSplits,$+($network,.netsplits)),bd)) netsplits on $cc2($network) $+ . $cc2($bytes($hget(NetSplits,$+($network,.people)),bd)) people affected, with the last split being on $cc2($asctime($hget(NetSplits,$+($network,.last))))
  39.   }
  40.   else {
  41.     echo 14 -ga $logo(NetSplits) I have seen $cc2($bytes($hget(NetSplits,$+($network,.netsplits)),bd)) netsplits on $cc2($network) $+ . $cc2($bytes($hget(NetSplits,$+($network,.people)),bd)) people affected, with the last split being on $cc2($asctime($hget(NetSplits,$+($network,.last))))
  42.   }
  43. }
  44.  
  45. ;Required identifiers
  46. ;alias cc1 { return $+($chr(03),13,$chr(02),$1-,$chr(15)) }
  47. ;alias cc2 { return $+($chr(03),10,$1-,$chr(03)) }
  48. ;alias logo { return $+($chr(03),14,$chr(91),$chr(03),11,$1-,$chr(93),$chr(03)) }

Comments