Input is from the Portmaster syslog output. It depends on the log file
being old enough to have a connection record for every port currently
in use; otherwise, ports will show up as empty that actually have a user
on them. Also note that syslog information is unreliable, so the displayed
port status may not match actual port status for various reasons. That
said, I have found it to be completely accurate whenever I checked it.
Two output modes are availabe... a short form with the following display:
14:12:56
mty0 ******-**-*********-***X***********************X
mty1 *******************-***X******-****************X
mty2 *******************--**X*********************--X
The portmaster name is on the left; * is a port in use, - is an empty
port, and X is a non-existant port (we use PRI).
"Full mode" generates a display as follows:
14:16:49
mty0 |drakwil |peggyg |garym |bifla |kevinf |cstudio | |mshp3
|beanbag | |bhre2 |alikatz |taurusrx|dli4 |hlebasko|jackson
|buttsmtr|mryerson|dli18 |clump |screamer|jdwachs |tuflhnd |--------
|dth |doc |jazzed |rgray |kvillars|speck |marikou |patricia
|wyvern |hebard |miner |bestloan|boris |djanakes|jenvic |rsb
|dgiannak|adina |thea |hadoken |dhoover |damien |rotary |--------
mty1 |dmyoung |chip |kristin |ambag |dli15 |richeson|number1 |candrews
|penrods |metals |carmelif|rose |wss |jgl |bdormody|mmeyer
|go |jt148 |pghs49 |taren |nickell |bertsch |rdmorgan|--------
|brooks |fw |erik |jhwarch |lonewolf|meharry |wsmpg |bhre7
|hoped |vgl |mpeppler|sycamore|briggs |retread |slipper |jremynse
|esalen | |mfs |harvey | |apmf |edward |--------
Portmaster name is on the left, a blank space is an empty port, and a
"--------" is a non-existant port. This mode requires an 80 column screen,
and 6 lines per PM (an xterm with a small font works nicely for this).
There are a number of things that could be added; if there is enough demand,
I'll work on it some more.
This is highly biased toward a PM3 on a T1... the number of ports displayed
is currently fixed. If there is enough demand, this could be fixed.
---- Cut Here ----
#!/usr/local/bin/perl5
# disports.pl version 0.1 - Copyright 1998 Stefan Hudson <hudson@mbay.net>
# Distrubition unlimited, but please give credit where due.
# Fullmode shows the usernames. Otherwise, it just shows the status of
# each port (and saves a lot of screen space )
$FULLMODE = 1;
# Comment out this line if you use CT1
$NOPORT[23]=1; $NOPORT[47]=1;
# Regex to match Portmasters to display
$PMLIST= '.';
# Enter the path to the syslog file containing Portmaster output.
$LOGFILE = "/var/log/modems";
# change the path to tput if necessary...
$thome = `/usr/bin/tput home`;
$tclear = `/usr/bin/tput clear`;
# You shouldn't need to modify anything below...
open(LOG, $LOGFILE) || die("Error opening $LOGFILE: $!\n");
printf("Reading history...\n");
while(1) {
if(eof(LOG)) {
if(!$print) {
print $tclear;
&printports;
}
$print=1;
sleep 1;
} else {
$_=<LOG>;
if(/^\w\w\w \d+ (\d\d:\d\d:\d\d) (\S+) \w+: port S(\d+) (.+)/) {
$time=$1; $pm=$2; $port=$3; $str=$4;
next if($pm !~ $PMLIST);
if($str=~/^(\w+)\.?\w* succeeded dest/) {
next if($1 eq "PPP");
next if($1 eq "connection");
$ports{$pm}[$port]=$1;
} elsif($str=~/terminated/) {
next if(!$ports{$pm}[$port]);
undef($ports{$pm}[$port]);
} else {
next;
}
&printports($pm, $port) if($print);
}
}
}
sub printports {
local($pm, $port)=@_;
print $thome;
print ("$time\n");
foreach(sort(keys(%ports))) {
$cpm=$_;
if($FULLMODE) {
if(!$pm || $pm eq $cpm ) {
foreach(0..47) {
if($_/8 == int($_/8)) {
if($_==0) {
printf("%-8s", $cpm);
} else {
printf("\n ");
}
}
if($NOPORT[$_]) {
printf("|--------");
} else {
printf("|%-8s", $ports{$cpm}[$_]);
}
}
print("\n");
} else {
print("\n"*6);
}
} else {
printf("%-8s", $cpm);
if(!$pm || $pm eq $cpm ) {
foreach(0..47) {
if($NOPORT[$_]) {
print("X");
} else {
print($ports{$cpm}[$_]?"*":"-");
}
}
}
print("\n");
}
}
}
----- Cut Here -----
-- /// Stefan Hudson <hudson@mbay.net> __ /// Senior Network Administrator - Monterey Bay Internet \\\/// http://www.mbay.net/ - Email: info@mbay.net \XX/ Voice: 408-642-6100 Fax: 408-642-6101 Modem: 408-642-6102 - To unsubscribe, email 'majordomo@livingston.com' with 'unsubscribe portmaster-users' in the body of the message. Searchable list archive: <URL:http://www.livingston.com/Tech/archive/>