reports:who.sh

who.sh

Author Richard Finegold
Compatibility Xymon 4.2
Requirements who column status from BBWin clients
Download None
Last Update 2012-05-03

This gathers all of the logins on monitored hosts into one listing. Quickly see if you left yourself logged into machines!

  • Copy the script into your $BBEXT directory.
  • Change the KNOWNCONSOLE and KNOWNCONSOLEDESC values to match your network's setup; many monitored hosts won't have a perpetual console logon.
  • Try running it directly, see if it gives any output.
  • Call it from a launcher line; send output to www/who.html, for example.
  • Add resulting file to your menu.js.

Show Code ⇲

Hide Code ⇱

# "who" report, for bbwin clients in Xymon/Hobbit/Big Brother
COLUMN=who
KNOWNCONSOLE=15 #If expected console logons, sum here and describe below
KNOWNCONSOLEDESC="user@example, 14× xxx-dept@xxx-host"
 
[ "$BBHOME" ] || { BBHOME=..; . ../etc/hobbitserver.cfg; BB=echo; }
LOGFILE=/tmp/$COLUMN.$$.log
#Filter out some totals
echo "<html><head><title>Who's on What</title>
<style type=\"text/css\">
        pre {margin-top:0;margin-bottom:0;}
</style>
<script src=\"menu/sorttable.js\"></script></head><body>
<h1>Who's on What</h1>
<div style=\"float:left\"><table class=sortable border=1>
<caption><i>Grouped by host</i></caption><tr><th>Host<th>
<pre>SESSIONNAME       USERNAME                 ID  STATE   TYPE </pre></tr>"
 
FILTER='
                /console  *[0-4]  /d
                /                                        0  Disc    rdpwd/d
                /^[0-9]  Idle      /d
                /^[0-9]  Down      /d
                /^rdp-tcp  *6553[67]  Listen  rdpwd/d
                /^ica-tcp  *6553[67]  Listen  wdica/d
                #Server 2008 adds a couple more
                /^rdp-tcp  *65536  Listen  *$/d
                /^.\+services  *0  Disc  *$/d
'
#http://support.microsoft.com/kb/186592
#  Other possibilities than Idle|Listen|Active|Disc: Conn, ConnQ, Shadow, Down, Init.
Servers=0
Conns=0
Console=0
Disc=0
Idle=0
icatcp=0
rdptcp=0
 
for S in `$BBHOME/bin/bb localhost "hobbitdboard test=$COLUMN" | sed 's/|.*//'`; do
#The output of this is essentially identical to what one would get if `cat`-ing the $BBLOGS if
# "hobbitd_filestore --status" was launched.
        $BBHOME/bin/bb localhost "hobbitdlog $S.$COLUMN" | tail -n +2 | sed "1,2d
        $FILTER" | sed '
                #align all text flush right on a 76-column width, from sed1line
                #resulting columns: 1/19/44/48/56 (or 0/18/43/47/55, or 18|25|4|8|6
                :a
                s/^.\{1,75\}$/ &/
                ta
        ' | sed 's/^.//;s/>/\&gt;/g' > $LOGFILE
        #Last sed: strip off first character and trailing spaces, HTML entity for >
        if [ ! -s $LOGFILE ]; then
                continue
        fi
        #sed 's/^\(.\{17\}\) \(.\{24\}\) \(.\{3\}\) \(.\{7\}\) \(.\{5\}\)/<td>\1<td>\2<td>\3<td>\4<td>\5/'      > $LOGFILE
#http://support.microsoft.com/kb/186592
        Servers=$(($Servers + 1))
        Conns=$(($Conns + `wc -l < $LOGFILE`))
        Disc=$(($Disc + `sed '/  Disc  /!d' < $LOGFILE | wc -l`))
        #Disc=$(($Disc + `sed '/  Disc$/!d' < $LOGFILE | wc -l`))
        Idle=$(($Idle + `sed '/  Idle/!d' < $LOGFILE | wc -l`))
        Console=$(($Console + `sed '/^console /!d' < $LOGFILE | wc -l`))
        icatcp=$(($icatcp + `sed '/^ica-tcp/!d' < $LOGFILE | wc -l`))
        rdptcp=$(($rdptcp + `sed '/^rdp-tcp/!d' < $LOGFILE | wc -l`))
        [ "`echo $S | sed /-lic/d`" ] || { Lics=$(($Lics + 1)); }
        #echo $S        $L $M | sed 's/^/<tr><td>/;s/ /<td>/g;s/$/<\/tr>/'
        echo "<tr rowspan=`echo $LOGFILE | wc -l`><th>$S<td><pre>
`sed 's/ *$//' < $LOGFILE`
</pre></td></tr>"
        cat $LOGFILE | sed "s/^\(.\{17\}\) \(.\{24\}\) \(.\{3\}\) \(.\{7\}\) \(.*\)/<tr><td>$S<td>\1<td>\2<td>\3<td>\4<td>\5/" >> $LOGFILE.$$
done
echo "</table></div>"
rm $LOGFILE     #This file never gets big because it's continually overwritten with each status log
 
echo "<div style=\"float:right\">"
echo "<table class=sortable border=1><caption><i>Fully sortable</i></caption>
<tr><th>Host<th>SessionName       <th>UserName                 <th>ID  <th>State   <th>Type </tr>"
cat $LOGFILE.$$
echo "</table></div><br clear=all><br>"
rm $LOGFILE.$$
unknowns=$(($Conns - $Disc - $Idle - $Console - $icatcp - $rdptcp))
if [ "0" -eq $Idle ]; then Idle=""; else Idle=", $idle idle"; fi
if [ 0 -eq $unknowns ]; then unknowns=""; else unknowns=", <b>$unknowns unknown</b>"; fi
Console=$(($Console - $KNOWNCONSOLE))
echo "<p>$Servers hosts have $Conns user connections ($Disc disconnected$Idle, <span title=\"$KNOWNCONSOLEDESC\">$KNOWNCONSOLE</span>+$Console console, $rdptcp rdp-tcp, $icatcp ica-tcp$unknowns) as of `date`</p>"
#echo "<p>As of `date`</p>"
echo "<!-- To replicate results:  QUERY SESSION [/SERVER:servername] -->"
echo "<!-- Excluded (via sed) to avoid accountless connections: $FILTER -->"
echo "</body></html>"

Probably needs translation from Xymon 4.2 to Xymon 4.3.

  • 2012-05-03
    • Initial release
  • reports/who.sh.txt
  • Last modified: 2012/05/04 09:01
  • by 127.0.0.1