Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


[perl] TCP Connection Status
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates
Author Message
gandalf
Developer


Joined: 02 Dec 2004
Posts: 12604
Location: Muenster, Germany

PostPosted: Sat Apr 01, 2006 9:18 am    Post subject: [perl] TCP Connection Status Reply with quote

This work is based on the nice tcp connections script from jbrooks. It is based on the snmpnetstat command producing output like
Code:
 snmpnetstat -v 1  -c xxx -an -P tcp <target>
Active Internet (tcp) Connections (including servers)
Proto Local Address                Foreign Address              (state)
tcp    *.443                        *.*                          LISTEN
...
tcp    127.0.0.1.80                 *.*                          LISTEN
tcp    127.0.0.1.1024               *.*                          LISTEN
tcp    127.0.0.1.1024               127.0.0.1.4327               ESTABLISHED
tcp    127.0.0.1.1024               127.0.0.1.4329               ESTABLISHED
tcp    127.0.0.1.1024               127.0.0.1.4331               ESTABLISHED
tcp    127.0.0.1.1024               127.0.0.1.4332               ESTABLISHED
tcp    127.0.0.1.4312               127.0.0.1.8989               ESTABLISHED
tcp    127.0.0.1.4324               127.0.0.1.8989               ESTABLISHED
tcp    127.0.0.1.4325               127.0.0.1.8989               ESTABLISHED
tcp    127.0.0.1.4327               127.0.0.1.1024               ESTABLISHED
tcp    127.0.0.1.4329               127.0.0.1.1024               ESTABLISHED
tcp    127.0.0.1.4331               127.0.0.1.1024               ESTABLISHED
tcp    127.0.0.1.4332               127.0.0.1.1024               ESTABLISHED
tcp    127.0.0.1.4532               *.*                          LISTEN
tcp    127.0.0.1.8989               *.*                          LISTEN
tcp    127.0.0.1.8989               127.0.0.1.4312               ESTABLISHED
tcp    127.0.0.1.8989               127.0.0.1.4324               ESTABLISHED
tcp    127.0.0.1.8989               127.0.0.1.4325               ESTABLISHED
tcp    127.0.0.1.18196              *.*                          LISTEN
tcp    127.0.0.1.18281              *.*                          LISTEN
tcp    127.0.0.1.65535              *.*                          LISTEN
I've rewritten this shell script with perl to make it usable for windows guys as well. It will not use any temporary file.
Please put the script into <path_cacti>/scripts and import the XML as usual. Exporting was done using cacti 0.8.6g; you'll need that version at minimum when importing.
Attention! Please check your RRA definitions after importing! I'm currently using non-standard RRAs!
Attention! On busy servers, this perl script will run for "some" time. I decided to upper the Settings->Poller->Script and Script Server Timeout Value to 50 seconds

happy cactiing
Reinhard



lvm_netstat_tcp.pl.txt
 Description:
the perl script
Please remove extension ".txt"
Corrected Issue with SNMP V2c

Download
 Filename:  lvm_netstat_tcp.pl.txt
 Filesize:  1.64 KB
 Downloaded:  2201 Time(s)


cacti_graph_template_snmp_get_tcp_connection_status.xml
 Description:
the XML templates

Download
 Filename:  cacti_graph_template_snmp_get_tcp_connection_status.xml
 Filesize:  36.66 KB
 Downloaded:  2873 Time(s)



Last edited by gandalf on Tue Apr 03, 2007 7:35 am; edited 3 times in total
Back to top
gandalf
Developer


Joined: 02 Dec 2004
Posts: 12604
Location: Muenster, Germany

PostPosted: Tue Apr 18, 2006 9:22 am    Post subject: Reply with quote

Attention
On some busy server, I noticed that the execution of snmpnetstat will take considerable time. This may required changes of some Settings -> Poller items (Script and Script Server Timeouts). As I'm not aware of the internals of snmpnetstat on the remote host, this may require your attention.
Reinhard
Back to top
dust2k
Cacti User


Joined: 04 Dec 2005
Posts: 85

PostPosted: Tue Apr 18, 2006 10:40 pm    Post subject: Reply with quote

There is the problem in template, after import the template, I found the running command is

D:\Perl\bin\perl G:/ROOT/WEB/home.ausmis.com/cacti/scripts/lvm_netstat_tcp.pl 192.168.1.10 2 public 161 500

and I got error like this :

Invalid version: 2
Usage: snmpnetstat [options...] hostname [interval]
NET-SNMP version: 5.2
-v [1 | 2c ] SNMP version
-V display version number
-c community specify community name
-t timeout SNMP packet timeout (seconds)
-i show interfaces with packet counters
-o show interfaces with octet counters
-r show routing table
-s show general statistics
-n show IP addresses, not names
-a show sockets in LISTEN mode too
-P proto show only details for this protocol
-I interface show only this interface
-d dump packets
-Ddebugspec
established:0 listen:0 timewait:0 timeclose:0 finwait1:0 finwait2:0 synsent:0 synrecv:0 closewait:0

once I change the data input method by fix value or add 'c', then it's works...
Back to top
anuraganuj
Cacti User


Joined: 21 Feb 2006
Posts: 70

PostPosted: Wed Apr 19, 2006 12:21 am    Post subject: polling is slow Reply with quote

i have used this script in windows 2000k cacti server and i m using cmd.php as poller.i could add this for few servers where no of connections was low but when i create graph for big servers poller almost hangs. what should i do??
Back to top
gandalf
Developer


Joined: 02 Dec 2004
Posts: 12604
Location: Muenster, Germany

PostPosted: Wed Apr 19, 2006 4:17 am    Post subject: Reply with quote

dust2k wrote:
There is the problem in template, after import the template, I found the running command is

D:\Perl\bin\perl G:/ROOT/WEB/home.ausmis.com/cacti/scripts/lvm_netstat_tcp.pl 192.168.1.10 2 public 161 500

and I got error like this :

Invalid version: 2
This will require some investigation, as snmp_version is a cacti built-in variable, that should yield 2c when choosing SNMP Version 2 from dropdown.
Reinhard
Back to top
gandalf
Developer


Joined: 02 Dec 2004
Posts: 12604
Location: Muenster, Germany

PostPosted: Wed Apr 19, 2006 4:18 am    Post subject: Re: polling is slow Reply with quote

anuraganuj wrote:
i have used this script in windows 2000k cacti server and i m using cmd.php as poller.i could add this for few servers where no of connections was low but when i create graph for big servers poller almost hangs. what should i do??
Please run the snmpnetstat from command line. I suppose, this will take a lot of time as I stated above. I'm not aware of any fact that would make it faster. Supression of DNS name lookup (option: -n) is already given.
Reinhard
Back to top
dust2k
Cacti User


Joined: 04 Dec 2005
Posts: 85

PostPosted: Fri Apr 21, 2006 1:48 am    Post subject: Reply with quote

lvm wrote:
This will require some investigation, as snmp_version is a cacti built-in variable, that should yield 2c when choosing SNMP Version 2 from dropdown.
Reinhard


I guess so, but don't know the value is 2 not 2c, but anyway, so far my script is running alright. thanks for your great work.
Back to top
anuraganuj
Cacti User


Joined: 21 Feb 2006
Posts: 70

PostPosted: Fri Apr 21, 2006 5:52 am    Post subject: problem with poller Reply with quote

i am able to create graph for my squid server which is not busy. i m using cmd.php as poller in win2k but when i use this graph some time poller gives error which is attached . also graphs starts cutting in between.
poller doesnt run properly.pls help i want this graph badly



error.jpg
 Description:
 Filesize:  41.12 KB
 Viewed:  29685 Time(s)

error.jpg


Back to top
anuraganuj
Cacti User


Joined: 21 Feb 2006
Posts: 70

PostPosted: Fri Apr 21, 2006 7:31 am    Post subject: problem with cactid also Reply with quote

i switched to CACTID but in log it says
04/21/2006 05:59:15 PM - CACTID: Poller[0] Host[122]

ERROR: Empty result [221.171.85.228]: 'c:/perl/perl C:/cacti/scripts/lvm_netstat_tcp.pl
host 1 test 161 4000'

pls help
Back to top
gandalf
Developer


Joined: 02 Dec 2004
Posts: 12604
Location: Muenster, Germany

PostPosted: Sun Apr 23, 2006 2:07 pm    Post subject: Reply with quote

I'm quite sure this is related to the runtime problem I stated above. Please allow for a longer runtime of the poller as given above
Reinhard
Back to top
stlaw



Joined: 28 Jul 2006
Posts: 4

PostPosted: Mon Jul 31, 2006 5:33 am    Post subject: Reply with quote

I used this perl scripts, but I cant get the ESTABLISTHED connections.
snmpnetstat -v 1 -c public -t 500 -an -P tcp 127.0.0.1:161
Active Internet (tcp) Connections (including servers)
Proto Local Address Foreign Address (state)
tcp *.111 *.* LISTEN
tcp *.199 *.* LISTEN
tcp *.3306 *.* LISTEN
tcp *.32768 *.* LISTEN
tcp 127.0.0.1.25 *.* LISTEN
tcp 127.0.0.1.631 *.* LISTEN

at Net-SNMP site, http://www.net-snmp.org/docs/man/snmpnetstat.html
it said
"-a normally sockets used by server processes are not shown."
I wonder how can get these sockets info.

thanks
Back to top
stlaw



Joined: 28 Jul 2006
Posts: 4

PostPosted: Thu Aug 24, 2006 9:50 pm    Post subject: Reply with quote

the above question hs been resolved . I guess it only occurs in localhost when using snmpwalk.
now another question , how can get connection information from IPV6?
some program such as ssh and apache will make its listening port showed with IPV6 format.
tcp 0 0 :::80 :::* LISTEN 2527/httpd
tcp 0 0 :::22 :::* LISTEN 1983/sshd

such infos cant be gotten from normal snmpnetstat.
I searched how to get these infos through snmpnetstat, but I failed.
if someone can get it, please show yr methods, thanks ~
Back to top
mcutting
Cacti Guru User


Joined: 16 Oct 2006
Posts: 1007

PostPosted: Fri Dec 15, 2006 9:47 am    Post subject: Reply with quote

I had exactly the same problem as dust2k. The snmp_value is actually "2" in the log, and not "2c" as it should be. Changing this value in the script seems to rectify this issue, although now I'm not able to poll data from SNMP 1 hosts.

Does anyone have any idea as to why this is ?

Thanks
Back to top
sllywhtboy



Joined: 09 Jul 2006
Posts: 29
Location: detroit'ish

PostPosted: Fri Mar 30, 2007 11:20 am    Post subject: Reply with quote

i added/inserted the following lines below the initial "set statements" (line 16)

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


I also updated the "Data Input Method" input string.

Code:
/usr/bin/perl <path_cacti>/scripts/lvm_netstat_tcp.pl <host> <snmp_version> <snmp_community> <snmp_port> <snmp_timeout>



once i did that, my "SNMP V2" hosts worked! thanks for the template!
Back to top
mcutting
Cacti Guru User


Joined: 16 Oct 2006
Posts: 1007

PostPosted: Tue Apr 03, 2007 5:55 am    Post subject: Reply with quote

Quote:
i added/inserted the following lines below the initial "set statements" (line 16)

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



I also updated the "Data Input Method" input string.

Code:
/usr/bin/perl <path_cacti>/scripts/lvm_netstat_tcp.pl <host> <snmp_version> <snmp_community> <snmp_port> <snmp_timeout>


Could you be a bit more specific about while files you changed to get this to work ?

Thanks
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates All times are GMT - 5 Hours
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 



Powered by phpBB © 2001, 2005 phpBB Group