[perl] TCP Connection Status
Moderators: Developers, Moderators
-
- Posts: 42
- Joined: Sun Jul 09, 2006 1:51 am
- Location: detroit'ish
- Contact:
i changed the data input method to point to my installation of perl.gandalf wrote:I've corrected the issue with SNMP V2c and it works for me. I did not change the Data Input Method
Reinhard
Code: Select all
nick@sllywhtboy:~$ which perl
/usr/bin/perl
-
- Posts: 42
- Joined: Sun Jul 09, 2006 1:51 am
- Location: detroit'ish
- Contact:
sllywhtboy wrote:i changed the data input method to point to my installation of perl.gandalf wrote:I've corrected the issue with SNMP V2c and it works for me. I did not change the Data Input Method
ReinhardCode: Select all
nick@sllywhtboy:~$ which perl /usr/bin/perl
looks like he implemented my if statement.mcutting wrote:Hi Reinhard,
What did you change ?
Thanks
-
- Cacti User
- Posts: 175
- Joined: Sun May 27, 2007 5:42 pm
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 ---------------------------
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 ---------------------------
SNMP - Get TCP Connection Status the script not running
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
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
snmpnetstat is returning only 22 line.
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?
-------------------------------------------------------------------------------
How can I get all the connectionlist?
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
#
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
#
bug in lvm_netstat_tcp.pl
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:
to
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];
Code: Select all
$in_timeout = $ARGV[4]/1000 if defined $ARGV[4];
Problems with IPv6 enabled hosts
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:
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
Who is online
Users browsing this forum: No registered users and 2 guests