[perl] TCP Connection Status

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

I've corrected the issue with SNMP V2c and it works for me. I did not change the Data Input Method
Reinhard
mcutting
Cacti Guru User
Posts: 1884
Joined: Mon Oct 16, 2006 5:57 am
Location: United Kingdom
Contact:

Post by mcutting »

Hi Reinhard,

What did you change ?

Thanks
Cacti Version 0.8.8b
Cacti OS Ubuntu LTS
RRDTool Version RRDTool 1.4.7
Poller Information
Type SPINE 0.8.8b
sllywhtboy
Posts: 42
Joined: Sun Jul 09, 2006 1:51 am
Location: detroit'ish
Contact:

Post by sllywhtboy »

gandalf wrote:I've corrected the issue with SNMP V2c and it works for me. I did not change the Data Input Method
Reinhard
i changed the data input method to point to my installation of perl.

Code: Select all

nick@sllywhtboy:~$ which perl
/usr/bin/perl
sllywhtboy
Posts: 42
Joined: Sun Jul 09, 2006 1:51 am
Location: detroit'ish
Contact:

Post by sllywhtboy »

sllywhtboy wrote:
gandalf wrote:I've corrected the issue with SNMP V2c and it works for me. I did not change the Data Input Method
Reinhard
i changed the data input method to point to my installation of perl.

Code: Select all

nick@sllywhtboy:~$ which perl
/usr/bin/perl
mcutting wrote:Hi Reinhard,

What did you change ?

Thanks
looks like he implemented my if statement.
super-hornet
Cacti User
Posts: 175
Joined: Sun May 27, 2007 5:42 pm

Post by super-hornet »

Hi all

I found a few bugs in the scripts. I know this script is for Windows but if it is going to use in Linux, use this script instead.
Take note that for some net-snmp (or snmpnetstat), the parameters is different

Also take note that the "perl" path in the XML file is hard coded to /usr/local/bin.
For some Linux (openSUSE), it is at /usr/bin instead. Alternate is that u can just use perl.
e.g.
perl <path_cacti>/scripts/lvm_netstat_tcp.pl <host> <snmp_version> <snmp_community> <snmp_port> <snmp_timeout>
----------------------------------- Start of script -----------------------
#!/usr/bin/perl -w

# --------------------------------------------------
# ARGV[0] = <hostname> required
# ARGV[1] = <snmp version> required
# ARGV[2] = <snmp community> required
# ARGV[3] = <snmp port> required
# ARGV[4] = <snmp timeout> required
# --------------------------------------------------
$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 == 2)
#{
# $in_version = "2c";
#}

if ($in_version eq "2")
{
$in_version = "2c";
}

### my $_cmd = "snmpnetstat -v $in_version -c $in_community -t $in_timeout -n -P tcp $in_hostname:$in_port";
my $_cmd = "snmpnetstat -v $in_version -c $in_community -t $in_timeout -Cn -Cp tcp $in_hostname:$in_port";

# 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;
my $_listen = 0;
my $_timewait = 0;
my $_timeclose = 0;
my $_finwait1 = 0;
my $_finwait2 = 0;
my $_synsent = 0;
my $_synrecv = 0;
my $_closewait = 0;

#print "$_output\n";

foreach ( @_output ) {
#print $_;
$_estab++ if /ESTABLISHED/;
$_listen++ if /LISTEN/;
$_timewait++ if /TIMEWAIT/;
$_timeclose++ if /TIMECLOSE/;
$_finwait1++ if /FINWAIT1/;
$_finwait2++ if /FINWAIT2/;
$_synsent++ if /SYNSENT/;
$_synrecv++ if /SYNRECV/;
$_closewait++ if /CLOSEWAIT/;
}

#
print "established:$_estab listen:$_listen timewait:$_timewait timeclose:$_timeclose finwait1:$_finwait1 finwait2:$_finwait2 synsent:$_synsent synrecv:$_synrecv closewait:$_closewait";

--------------------- End of Script ---------------------------
amendez
Posts: 1
Joined: Tue Jul 31, 2007 11:35 am

SNMP - Get TCP Connection Status the script not running

Post by amendez »

Hi All:

I have a problem with the lvm_netstat_tcp.pl script, I can run the script on the comand line but when it is call by Cacti I an receiving the following error:

07/31/2007 11:27:17 AM - CMDPHP: Poller[0] Host[32] DS[162] CMD: /usr/local/bin/perl /var/www/html/cacti/scripts/lvm_netstat_tcp.pl bvcacom002 2 20net1Sec 161 500, output: U
07/31/2007 11:27:17 AM - CMDPHP: Poller[0] Host[32] DS[162] WARNING: Result from CMD not valid. Partial Result:

And The graphic is not showing anything.

Can I get some help?

Thanks,
Antonio
changsung
Posts: 17
Joined: Wed Feb 21, 2007 10:26 am
Contact:

snmpnetstat is returning only 22 line.

Post by changsung »

When I run "netstat -na |wc", I see 21620 lines but script retuns only 22 line. Also "netstat -v 1 -c xxx -an -P tcp host |wc" return 22 lines.
-------------------------------------------------------------------------------
How can I get all the connectionlist?
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

The perl script in its published version filteres for specific patterns. You may either omit this filtering or extend it to your needs. But be aware, that 22,000 lines may kill your target system (our did not like such queries)
Reinhard
changsung
Posts: 17
Joined: Wed Feb 21, 2007 10:26 am
Contact:

Post by changsung »

snmpnetstat -v 1 -c public -an -P tcp testserver --> Same command as script and it returns same results.
Ans I have try with two differnet version of Net-Snmp (5.1.2 and 5.4.1)



# snmpnetstat -v 1 -c public -an -P tcp nj1-api1
Active Internet (tcp) Connections (including servers)
Proto Local Address Foreign Address (state)
tcp *.* *.* CLOSED
tcp *.22 *.* LISTEN
tcp *.514 *.* LISTEN
tcp *.11628 *.* LISTEN
tcp *.11629 *.* LISTEN
tcp 127.0.0.1.32777 *.* LISTEN
tcp 127.0.0.1.32781 *.* LISTEN
tcp 127.0.0.1.32795 *.* LISTEN
tcp 127.0.0.1.32806 *.* LISTEN
tcp 127.0.0.1.32808 *.* LISTEN
tcp 160.43.45.19.32816 172.17.142.10.7509 ESTABLISHED
tcp 199.105.176.67.8195 11.181.100.4.8219 ESTABLISHED
tcp 199.105.176.67.8195 11.181.112.6.8284 ESTABLISHED
tcp 199.105.176.67.8195 11.181.112.11.33500 ESTABLISHED
tcp 199.105.176.67.8195 11.196.216.2.54368 ESTABLISHED
tcp 199.105.176.67.8195 11.202.240.3.38453 ESTABLISHED
tcp 199.105.176.67.8195 11.203.88.5.31690 ESTABLISHED
tcp 199.105.176.67.8195 11.203.88.19.32015 ESTABLISHED
tcp 199.105.176.67.8195 11.208.16.2.9893 ESTABLISHED
tcp 199.105.176.67.8195 11.208.16.2.9953 ESTABLISHED
tcp 199.105.176.67.8195 11.208.16.17.16815 ESTABLISHED
tcp 199.105.176.67.8195 11.208.16.17.16875 ESTABLISHED
tcp 199.105.176.67.8195 11.208.16.17.16944 ESTABLISHED
tcp 199.105.176.67.8195 11.208.16.17.18314 ESTABLISHED
tcp 199.105.176.67.8195 11.208.16.17.18323 ESTABLISHED
tcp 199.105.176.67.8195 11.208.16.17.18470 ESTABLISHED
tcp 199.105.176.67.8195 11.208.16.17.18604 ESTABLISHED
tcp 199.105.176.67.8195 11.208.16.17.18805 ESTABLISHED
tcp 199.105.176.67.8195 11.208.16.17.18888 ESTABLISHED
#
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Ok, fine. But what are you going to tell me? You gave me some info, but which question should I answer now?
Reinhard
changsung
Posts: 17
Joined: Wed Feb 21, 2007 10:26 am
Contact:

Post by changsung »

I was wondering this is bug on snmpd or some kind of time out which it can be set in snmpd.conf.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Please grep the first lines of "netstat -an" to see the garbage you would be presented with in case you deactivate the filter. And as UDP is stateless, I was thinking it would be better not to select those
Reinhard
User avatar
fzurell
Posts: 2
Joined: Wed Sep 12, 2007 2:07 pm
Location: Berlin
Contact:

bug in lvm_netstat_tcp.pl

Post by fzurell »

Hello,

I set my SNMP-Timeout value in cacti very high. This breaks the TCP Connections as this value is simply passed to the snmpnetstat utility.
But Cacti measures the timeout in milliseconds and snmpnetstat ins seconds. So very large values will render an snmpnetstat error.

I just modified this line in the script to work around:

Code: Select all

$in_timeout     = $ARGV[4] if defined $ARGV[4];
to

Code: Select all

$in_timeout     = $ARGV[4]/1000 if defined $ARGV[4];
User avatar
fzurell
Posts: 2
Joined: Wed Sep 12, 2007 2:07 pm
Location: Berlin
Contact:

Problems with IPv6 enabled hosts

Post by fzurell »

I experiences problems with hosts where IPv6 is enabled. The snmpnetstat utility from the latest net-snmp packages seems to be unable to handle that. I can't parse the ipv6 related state informations.

The only way for me to fix the problem was to disable IPv6.

For Redhat ES/CentOS I did this:

Code: Select all

echo -e “alias net-pf-10 off\nalias ipv6 off“ >> /etc/modprobe.conf
chkconfig ip6tables off 
echo “NETWORKING_IPV6=no“ >> /etc/sysconfig/network 
for datei in `ls /etc/sysconfig/network-scripts/ifcfg-*`; do  echo “IPV6INIT=no“ >> $datei; done
Rael
Cacti User
Posts: 129
Joined: Thu Apr 05, 2007 9:28 am

Post by Rael »

Can't download the xml template? It displays in my browser instead of being a downloadable file for import?
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests