Ad blocker detected: Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker on our website.
I woud like to count connected RDP sessions to windows boxes. Therfore, I found similar perl script somewhere on this forum, did some modifications and got this at the end:
$in_hostname = $ARGV[0] if defined $ARGV[0];
$in_version = $ARGV[1] if defined $ARGV[1];
$in_community = $ARGV[2] if defined $ARGV[2];
$in_port = $ARGV[3] if defined $ARGV[3];
$in_timeout = $ARGV[4] if defined $ARGV[4];
if ($in_version eq "2")
{
$in_version = "2c";
}
my $_cmd = "snmpnetstat -v $in_version -c $in_community -t $in_timeout -Cn -Cp tcp $in_hostname:$in_port | find \".3389\"";
# usage notes
if (
( ! defined $in_hostname ) ||
( ! defined $in_version ) ||
( ! defined $in_community ) ||
( ! defined $in_port ) ||
( ! defined $in_timeout )
) {
print "usage:\n\n
$0 <host> <snmp version> <snmp community> <snmp port> <snmp timeout>\n\n";
exit;
}
my @_output = `$_cmd`;
my $_estab = 0;
foreach ( @_output ) {
#print $_;
$_estab++ if /ESTABLISHED/;
}
print "established:$_estab";
So, as you can see, I tried to read all TCP connections to the box and then filter them by the port number. RDP uses port 3389 so therefore script works really fine and I got the actual number that I need.
Well something in the script is obviously hanging up... Ideally, you should find out where in the code thats happening. You might consider throwing in some additional logic that will kill the script if it runs for X seconds. You'll have to look on google for some examples.
Otherwise, since the script runs fine most of the time, not much else you can do.
yay for PS! however, I'd suggest a slight change so that the function accepts the computer name so it could be passed from Cacti... and you're going to need to work on the formatting of the results returned be correctly parsed by the poller.