tcp connections script

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

Moderators: Moderators, Developers

Post Reply
Author
Message
jbrooks
Posts: 5
Joined: Thu Mar 30, 2006 1:37 pm

tcp connections script

#1 Post by jbrooks » Thu Mar 30, 2006 1:42 pm

hi,

just put this quick hack of a script together so i can monitor the state of tcp connections.

it's quick n' dirty.

J
Attachments
tcp-connections.zip
graph template
bash script
sample graph
(53.09 KiB) Downloaded 9556 times
tcp_connections.png
sample graph
tcp_connections.png (50.13 KiB) Viewed 47752 times

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

#2 Post by gandalf » Thu Mar 30, 2006 1:57 pm

Am I right assuming this one works for localhost only?
Reinhard

jbrooks
Posts: 5
Joined: Thu Mar 30, 2006 1:37 pm

#3 Post by jbrooks » Thu Mar 30, 2006 2:01 pm

hi,

actually, it will do remote hosts too.

it uses snmpnetstat from the net-snmp package to get netstat-like output on a remote host via snmp - a very cool tool.

J

qwertz
Cacti User
Posts: 98
Joined: Thu Feb 16, 2006 9:20 am

#4 Post by qwertz » Fri Mar 31, 2006 7:18 am

On which snmp devices is it working ?

Cisco? Unix?

Thanks

Qwertz

User avatar
fmangeant
Cacti Guru User
Posts: 2326
Joined: Fri Sep 19, 2003 8:36 am
Location: Sophia-Antipolis, France
Contact:

#5 Post by fmangeant » Fri Mar 31, 2006 8:16 am

Hi

I assumed it works only with Ucd/Net-SNMP, available for Unix & Win32.

However, testing it with a Cisco 2700 router gives an anwser :

Code: Select all

$ snmpnetstat -v 1 -c yyyyyy xxx.xxx.xxx.xxx  -an -P tcp
Active Internet (tcp) Connections (including servers)
Proto Local Address                Foreign Address              (state)
tcp    xxx.xxx.xxx.xxx.179            xxx.xxx.xxx.xxx.63919           ESTABLISHED
Active Internet (udp) Connections
Proto Local Address
udp    xxx.xxx.xxx.xxx.161
udp    xxx.xxx.68.10.49
udp    xxx.xxx.68.10.67
udp    xxx.xxx.68.10.123
udp    xxx.xxx.68.10.162
udp    xxx.xxx.68.10.1967
udp    xxx.xxx.68.10.49862
udp    xxx.xxx.68.10.50414
udp    xxx.xxx.68.10.55884
[size=84]
[color=green]HOWTOs[/color] :
[list][*][url=http://forums.cacti.net/viewtopic.php?t=15353]Install and configure the Net-SNMP agent for Unix[/url]
[*][url=http://forums.cacti.net/viewtopic.php?t=26151]Install and configure the Net-SNMP agent for Windows[/url]
[*][url=http://forums.cacti.net/viewtopic.php?t=28175]Graph multiple servers using an SNMP proxy[/url][/list]
[color=green]Templates[/color] :
[list][*][url=http://forums.cacti.net/viewtopic.php?t=15412]Multiple CPU usage for Linux[/url]
[*][url=http://forums.cacti.net/viewtopic.php?p=125152]Memory & swap usage for Unix[/url][/list][/size]

jbrooks
Posts: 5
Joined: Thu Mar 30, 2006 1:37 pm

#6 Post by jbrooks » Fri Mar 31, 2006 9:28 am

it should work for any snmp-capable device.

i haven't tested on any network equipment specifically, but it works against net-snmp (linux), MS SNMP (windows xp, windows 2003).

from the output of the previous post, it should work on cisco too.

I will try to clean up the script a little so it's more dynamic (accpets snmp version for example).

feel free to post results (success/failure) of devices in your environment.

J

anuraganuj
Cacti User
Posts: 70
Joined: Tue Feb 21, 2006 9:50 am

not getting output

#7 Post by anuraganuj » Tue Apr 18, 2006 7:18 am

hi

i am a windows CACTI user.I downloaded this script and installed bash shell for windows
I can see tmp file in tmp directory getting data from snmpnetstat very well
I have grep,wc for windows in place.
but the graph shows -1 for all variables pls help

jbrooks
Posts: 5
Joined: Thu Mar 30, 2006 1:37 pm

#8 Post by jbrooks » Tue Apr 18, 2006 7:30 am

Hi,

there's a new (better) version of this script here:

http://forums.cacti.net/about12787.html

it's written in perl and does not generate any tmp files.

if you want to use my (hacky) shell version, it sounds like you're missing the snmpnetstat tool, or that it's not in your path or something. make sure you have snmpnetstat.exe, and that it's in your path, or edit the script to point directly at it.

i.e., edit this line:

snmpnetstat -v 2c -c $2 -Can -Cp tcp $1 > $TMPDIR/$1

to something like:

/path/to/snmpnetstat -v 2c -c $2 -Can -Cp tcp $1 > $TMPDIR/$1


thx,

J

anuraganuj
Cacti User
Posts: 70
Joined: Tue Feb 21, 2006 9:50 am

Cacti log

#9 Post by anuraganuj » Tue Apr 18, 2006 7:57 am

i can see files getting generated snmpnetstat is executing properly

Cacti log file says

CMDPHP: Poller[0] Host[161] DS[583] WARNING: Result from CMD not
valid. Partial Result: established: 29 list

jbrooks
Posts: 5
Joined: Thu Mar 30, 2006 1:37 pm

#10 Post by jbrooks » Tue Apr 18, 2006 7:58 am

what happens when you run the script by hand?

ntenzpunishment
Posts: 14
Joined: Tue Jun 30, 2009 4:00 am

#11 Post by ntenzpunishment » Fri Jul 02, 2010 4:34 am

Hi there,

First of all very usefull for me except the fact that it dosent graph tcp6.

get_connection_stats.pl -H xxx -c xxx
closed:0 closing:0 timeWait:0 deleteTCB:0 listen:3 synSent:0 synReceived:0 established:6 finWait1:0 finWait2:0 closeWait:0 lastAck:0


When I look at the server with a netstat -an I see lots more:

tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5432 127.0.0.1:50992 ESTABLISHED
tcp 0 0 127.0.0.1:5432 127.0.0.1:45245 ESTABLISHED
tcp 0 0 127.0.0.1:5432 127.0.0.1:46596 ESTABLISHED
tcp 0 0 127.0.0.1:5432 127.0.0.1:54418 ESTABLISHED
tcp 0 0 127.0.0.1:5432 127.0.0.1:48768 ESTABLISHED
tcp 0 0 127.0.0.1:5432 127.0.0.1:50234 ESTABLISHED
tcp6 0 0 :::42436 :::* LISTEN
tcp6 0 0 :::2575 :::* LISTEN
tcp6 0 0 :::8080 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 :::5432 :::* LISTEN
tcp6 0 0 :::40281 :::* LISTEN
tcp6 0 0 :::34972 :::* LISTEN
tcp6 0 0 :::7676 :::* LISTEN
tcp6 0 0 ::ffff:127.0.0.1:58409 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:39943 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:48792 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:54811 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:56832 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:33332 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:33888 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:39943 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:58409 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:59213 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:54811 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:35770 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:33332 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:42275 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:50234 ::ffff:127.0.0.1:5432 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:57238 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:48768 ::ffff:127.0.0.1:5432 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:48792 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:54418 ::ffff:127.0.0.1:5432 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:57519 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:44880 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:56038 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:59213 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:46926 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:57377 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:35203 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:35203 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:33888 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:35770 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:57519 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:57377 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:50992 ::ffff:127.0.0.1:5432 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:57238 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:44880 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:56832 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:56038 ESTABLISHED
tcp6 0 0 ::ffff:10.145.1.38:22 ::ffff:10.152.10.:57388 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:47411 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:47411 ::ffff:127.0.0.1:40281 ESTABLISHED
tcp6 0 792 ::ffff:10.145.1.38:22 ::ffff:10.200.11.1:3887 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:46596 ::ffff:127.0.0.1:5432 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:40281 ::ffff:127.0.0.1:46926 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:45245 ::ffff:127.0.0.1:5432 ESTABLISHED
tcp6 0 0 ::ffff:127.0.0.1:42275 ::ffff:127.0.0.1:40281 ESTABLISHED
udp 0 0 127.0.0.1:32768 127.0.0.1:32768 ESTABLISHED

flw521521
Posts: 6
Joined: Thu Dec 01, 2011 9:18 am

Re: tcp connections script

#12 Post by flw521521 » Thu Dec 01, 2011 9:22 am

thank you so much , it was working well

ewheel
Posts: 1
Joined: Mon Feb 13, 2012 8:09 pm

Re: tcp connections script

#13 Post by ewheel » Thu Mar 15, 2012 11:26 pm

Howto use this script & template ?
I put script into scripts directory, change path in the template
where i must change host & community ?

Post Reply