termuser

Author Galen Johnson
Compatibility Xymon 4.2
Requirements Perl, Windows
Download None
Last Update 2007-06-30

termusers.pl is an external script that is run by the Big Brother client on a Windows Terminal Servers. It counts the number of users and determines how many are active or disconnected users. It can be used to track multiple customers on a shared terminal server with minor modification.

Client side

  1. Add to BBWin.cfg in externals
       <load value="C:\perl\bin\perl 'C:\Program Files\BBWin\ext\termusers.pl'" />

    This may work as well

       <load value="C:\perl\bin\perl ..\ext\termusers.pl" />

Server side

  1. Add 'termusers=ncv' to TEST2RRD in hobbitserver.cfg
  2. Add
    NCV_termusers="ActiveSessions:GAUGE,DisconnectedSessions:GAUGE,*:NONE"

    to hobbitserver.cfg.

  3. Add 'termusers' to the GRAPHS definitions in hobbitserver.cfg.
  4. Update hobbitgraph.cfg with:
    [termusers]
            TITLE Terminal Server Users
            YAXIS #
            DEF:active=termusers.rrd:ActiveSessions:AVERAGE
            DEF:disc=termusers.rrd:DisconnectedSessions:AVERAGE
            LINE1:active#00CCCC:Active Users
            LINE2:disc#FF0000:Disconnected Users
            COMMENT:\n
            GPRINT:active:LAST:Active Users        \: %5.1lf%s (cur)
            GPRINT:active:MAX: \: %5.1lf%s (max)
            GPRINT:active:MIN: \: %5.1lf%s (min)
            GPRINT:active:AVERAGE: \: %5.1lf%s (avg)\n
            GPRINT:disc:LAST:Disconnected Users  \: %5.1lf%s (cur)
            GPRINT:disc:MAX: \: %5.1lf%s (max)
            GPRINT:disc:MIN: \: %5.1lf%s (min)
            GPRINT:disc:AVERAGE: \: %5.1lf%s (avg)\n
    

termusers.pl

Show Code ⇲

Hide Code ⇱

######################################################################## 
# Name: 	termusers.pl
# Version: 	1.0
# Author: 	Brandon Kitchen
# Purpose: 	termusers.pl is an external script that is run by the Big
#               Brother client on a Windows Terminal Servers. It counts
#               the number of users and determines how many are active
#               and disconnected users.
# 
# Changelog:
#     10-13-2006: Updated to work with Xymon (GMJ)
#                 Removed laard-grapher.cgi links
######################################################################## 
 
use strict;
use Sys::Hostname;
 
# Constants
use constant RED_ALERT    => 45;
use constant YELLOW_ALERT => 25;
use constant DEBUG        => 0;
 
# Globals
use vars qw($total_users);
use vars qw($active_users $disc_users);
use vars qw($computer $service $line $userattr $bblogs);
use vars qw(@userinfo @query);
 
# This is the name of the column in the BB display.
$service  = "termusers";
$bblogs   = "c:\\Program Files\\BBWin\\tmp";
 
# Get the local system name.
$computer = hostname();
 
# Setup where output goes.
if ( DEBUG ) {
	open(STATUS, ">$service") || die "$!: file $service";
} else {
	open(STATUS, ">$bblogs\\$service") || die "$!: file $bblogs\\$service";
}
 
# Get the list of terminal users.
@query = `query user`;
 
# Setup the counters.
$total_users 	= 0;
$active_users 	= 0;
$disc_users 	= 0;
 
# Go through the list of users looking for different types (ie group1 vs group2)
for $line (@query) {
	# Discard the header line.
	next if $line =~ /USERNAME|^\s*$/;
 
	$total_users++;
	print "Total: $total_users\n" if DEBUG;
 
	# Get rid of whitespace at the start of the line. Also fix 
	# the special case user (console) that starts with <.
	if ( $line =~ /^\s+/ )  { $line =~ s/^\s+//g; }
	if ( $line =~ /^\>/  )  { $line =~ s/^\>//g;  }
 
	# Split the line into tokens and start counting special users.
	@userinfo = split /\s+/, $line;
	if ($line =~ /Active/) {
		$active_users++;
	} elsif ($line =~ /Disc/) {
		$disc_users++;
	}
}
 
# Check the total_users count and alert as appropriate. Also alert red if
# any users in the Revoked OU have sessions on the system.
if ($total_users <= YELLOW_ALERT) {
	print STATUS "green\n";
} elsif ($total_users <= RED_ALERT) {
	print STATUS "yellow\n";
} else {
	print STATUS "red\n";
}
print STATUS qq/There are $total_users terminal users on $computer.\n
Of the $total_users total users:\n
\t      Active Sessions:\t$active_users
\tDisconnected Sessions:\t$disc_users
 
/;
 
# Send the list of users.
print STATUS "\n\n@query\n";
 
# All done now. 
close(STATUS);
  • No known bugs.
  • Provide instructions for tracking disparate customers.
  • Brandon Kitchen - I took it over because I know he isn't going to want to support it.
  • 2007-06-30
    • Initial release
  • monitors/termuser.txt
  • Last modified: 2010/01/21 02:58
  • (external edit)