Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Tue Sep 25, 2018 8:18 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 58 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: [perl] TCP Connection Status
PostPosted: Sat Apr 01, 2006 9:18 am 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
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


Attachments:
File comment: the perl script
Please remove extension &quot;.txt&quot;
Corrected Issue with SNMP V2c

lvm_netstat_tcp.pl.txt [1.64 KiB]
Downloaded 8044 times
File comment: the XML templates
cacti_graph_template_snmp_get_tcp_connection_status.xml [36.66 KiB]
Downloaded 8136 times

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Last edited by gandalf on Tue Apr 03, 2007 7:35 am, edited 3 times in total.
Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 9:22 am 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
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

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 10:40 pm 
Offline
Cacti User
User avatar

Joined: Sun Dec 04, 2005 3:14 am
Posts: 101
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...


Top
 Profile  
 
 Post subject: polling is slow
PostPosted: Wed Apr 19, 2006 12:21 am 
Offline
Cacti User

Joined: Tue Feb 21, 2006 9:50 am
Posts: 70
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??


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 4:17 am 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
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

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject: Re: polling is slow
PostPosted: Wed Apr 19, 2006 4:18 am 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
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

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 1:48 am 
Offline
Cacti User
User avatar

Joined: Sun Dec 04, 2005 3:14 am
Posts: 101
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.


Top
 Profile  
 
 Post subject: problem with poller
PostPosted: Fri Apr 21, 2006 5:52 am 
Offline
Cacti User

Joined: Tue Feb 21, 2006 9:50 am
Posts: 70
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 :(


Attachments:
error.jpg
error.jpg [ 41.12 KiB | Viewed 85886 times ]
Top
 Profile  
 
 Post subject: problem with cactid also
PostPosted: Fri Apr 21, 2006 7:31 am 
Offline
Cacti User

Joined: Tue Feb 21, 2006 9:50 am
Posts: 70
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 23, 2006 2:07 pm 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
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

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 31, 2006 5:33 am 
Offline

Joined: Fri Jul 28, 2006 7:00 am
Posts: 4
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 9:50 pm 
Offline

Joined: Fri Jul 28, 2006 7:00 am
Posts: 4
the above question hs been resolved . I guess it only occurs in localhost when using snmpwalk.
now another question :oops: , 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 ~ :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 9:47 am 
Offline
Cacti Guru User

Joined: Mon Oct 16, 2006 5:57 am
Posts: 1876
Location: United Kingdom
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

_________________
Quote:
Cacti Version 0.8.8b
Cacti OS Ubuntu LTS
RRDTool Version RRDTool 1.4.7
Poller Information
Type SPINE 0.8.8b


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 11:20 am 
Offline

Joined: Sun Jul 09, 2006 1:51 am
Posts: 42
Location: detroit'ish
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! :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 5:55 am 
Offline
Cacti Guru User

Joined: Mon Oct 16, 2006 5:57 am
Posts: 1876
Location: United Kingdom
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

_________________
Quote:
Cacti Version 0.8.8b
Cacti OS Ubuntu LTS
RRDTool Version RRDTool 1.4.7
Poller Information
Type SPINE 0.8.8b


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 58 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group