Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Sun Apr 21, 2019 9:25 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Active FTP/SSH/Telnet/Samba Connections - Uses SNMP+BASH
PostPosted: Tue Aug 30, 2005 4:21 am 
Offline

Joined: Tue Aug 23, 2005 9:16 am
Posts: 12
I could not find this anywhere so I did it myself.

Please feel free to provide feedback here.

Installation Instructions

1) Put tcp_conns.sh in your cacti scripts directory - /usr/local/cacti/scripts on mine.
2) Edit tcp_conns.sh: Change "public" to whatever your snmp community name is.
2) Import the graph xml files using the Cacti console.
3) Create the graphs and when you do this you shall have to enter

IP address of interface of the tcp connection
IP address of target device to query
Local port number of the tcp connection

For FTP it will obviously be local port number 21.

The data templates for each graph all use the data input method "SNMP - Get TCP Connections By IP And Port Number Of Remote Machine" which is passed the above 3 parameters. This data input method is the tcp_conns.sh script which executes the net-snmp command "snmpwalk" and returns the number of matching connections given your parameters.

tcp_conns.sh :
Code:
#!/bin/sh

conns=`snmpwalk -On -c public -v 1 $3 .1.3.6.1.2.1.6.13.1.3.$1.$2 | wc -l`

echo $conns


Simple huh?

Example graphs from my system:


Attachments:
active_telnet_conns.JPG
active_telnet_conns.JPG [ 29.53 KiB | Viewed 56583 times ]
active_ssh_conns.JPG
active_ssh_conns.JPG [ 28.01 KiB | Viewed 56583 times ]
active_samba_conns.JPG
active_samba_conns.JPG [ 27.18 KiB | Viewed 56583 times ]
Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 4:23 am 
Offline

Joined: Tue Aug 23, 2005 9:16 am
Posts: 12
XML templates/script are attached.


Attachments:
active_tcp_conns.zip [8.64 KiB]
Downloaded 4738 times
Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 11:18 am 
Offline

Joined: Thu Nov 24, 2005 11:13 am
Posts: 4
hm, got some problem with this, result in cacti always 0

when I run script manually, as it should be by poller (call string from view poller cache), all ok. when I manualy return number - all ok (echo 100 in tcp_conns.sh). what wrong?
Tried manually as root, as cactiuser, all ok, from poller - always 0

net-snmp-5.2.1.2 - ports collection
cacti 0.8.6g - ports collection
FreeBSD 4.11-S

PS: SOLVED! hint: PATH (/usr/local/bin/snmpwalk)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 15, 2005 5:39 am 
Offline
User avatar

Joined: Mon Dec 05, 2005 8:18 am
Posts: 14
I have the same issues as tigra. And for sure the paths are correct.

Any tips and pointers ?

Quote:
#!/bin/sh

conns=`snmpwalk -On -c public -v 1 $3 .1.3.6.1.2.1.6.13.1.3.$1.$2 | wc -l`

echo $conns


Can some one explain what i should enter for the variables:

$1 => host ?
$2 => port ?
$3 => ??


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 4:44 am 
Offline

Joined: Wed Dec 14, 2005 3:45 am
Posts: 12
rhamburg wrote:
I have the same issues as tigra. And for sure the paths are correct.

Any tips and pointers ?

Quote:
#!/bin/sh

conns=`snmpwalk -On -c public -v 1 $3 .1.3.6.1.2.1.6.13.1.3.$1.$2 | wc -l`

echo $conns


Can some one explain what i should enter for the variables:

$1 => host ?
$2 => port ?
$3 => ??

#snmpwalk -On -c public -v XXX.XXX.XXX.XXX .1.3.6.1.2.1.6.13.1.3.$1.$2 | wc -l
display a number.i tounght $3 maybe is host_ip,i didn't know $1,$2 mening.
i try find it by google,but no presentation:(,plaease tell me


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 5:11 am 
Offline
Cacti User

Joined: Thu Oct 06, 2005 5:03 am
Posts: 402
i think:

$3 host ip

port has nothimg to do with snmp ;)

i am not sure for the rest

_________________
cacti rulez!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 11:31 am 
Offline

Joined: Tue Dec 20, 2005 11:22 am
Posts: 2
I made some modifications on the script and on the graph_template..

Now, you need only to choose what interface to check the connections and the port.

The graph title may be modified (this is important if you have more than one IP per host to check, like me..)

The community and the IP of the server (where the snmpwalk will query) are derived from the host configuration..


Attachments:
active_http_connections.zip [2.5 KiB]
Downloaded 2893 times
Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 8:30 pm 
Offline

Joined: Wed Dec 14, 2005 3:45 am
Posts: 12
acacioas wrote:
I made some modifications on the script and on the graph_template..

Now, you need only to choose what interface to check the connections and the port.

The graph title may be modified (this is important if you have more than one IP per host to check, like me..)

The community and the IP of the server (where the snmpwalk will query) are derived from the host configuration..

remove old tcp_conns.sh,i used your way do it.in the data template ,i can see "SNMP - Active HTTP Connections",i added query community force.add date sources,
this is my data source debug
Quote:
/usr/local/rrdtool/bin/rrdtool create \
/www/htdocs/cacti/rra/219_235_226_34www_http_conns_60.rrd \
--step 300 \
DS:http_conns:GAUGE:600:0:1000 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MIN:0.5:1:600 \
RRA:MIN:0.5:6:700 \
RRA:MIN:0.5:24:775 \
RRA:MIN:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797 \
RRA:LAST:0.5:1:600 \
RRA:LAST:0.5:6:700 \
RRA:LAST:0.5:24:775 \
RRA:LAST:0.5:288:797 \


but in graph data also is 0,why?
i can't find any tools to test this proess,so i do not know where are matter?


Attachments:
cacti.gif
cacti.gif [ 10.78 KiB | Viewed 55375 times ]
Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 1:21 pm 
Offline

Joined: Tue Dec 20, 2005 11:22 am
Posts: 2
muraping wrote:
acacioas wrote:
I made some modifications on the script and on the graph_template..

Now, you need only to choose what interface to check the connections and the port.

The graph title may be modified (this is important if you have more than one IP per host to check, like me..)

The community and the IP of the server (where the snmpwalk will query) are derived from the host configuration..

remove old tcp_conns.sh,i used your way do it.in the data template ,i can see "SNMP - Active HTTP Connections",i added query community force.add date sources,
this is my data source debug
Quote:
/usr/local/rrdtool/bin/rrdtool create \
/www/htdocs/cacti/rra/219_235_226_34www_http_conns_60.rrd \
--step 300 \
DS:http_conns:GAUGE:600:0:1000 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MIN:0.5:1:600 \
RRA:MIN:0.5:6:700 \
RRA:MIN:0.5:24:775 \
RRA:MIN:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797 \
RRA:LAST:0.5:1:600 \
RRA:LAST:0.5:6:700 \
RRA:LAST:0.5:24:775 \
RRA:LAST:0.5:288:797 \


but in graph data also is 0,why?
i can't find any tools to test this proess,so i do not know where are matter?


You can test the script in a shell..
./tcp_conns.sh <ip> <port> <host> <community>

Have you removed the old graphic and added this new one, or just changed the graph_template?

This worked fine for me in three different hosts (remove the old and add a new one) ..


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 1:33 am 
Offline

Joined: Thu Dec 22, 2005 10:19 pm
Posts: 4
I got the SAME PROBLEM! I run sh tcp_conns.sh and got corrent result.

muraping wrote:
acacioas wrote:
I made some modifications on the script and on the graph_template..

Now, you need only to choose what interface to check the connections and the port.

The graph title may be modified (this is important if you have more than one IP per host to check, like me..)

The community and the IP of the server (where the snmpwalk will query) are derived from the host configuration..

remove old tcp_conns.sh,i used your way do it.in the data template ,i can see "SNMP - Active HTTP Connections",i added query community force.add date sources,
this is my data source debug
Quote:
/usr/local/rrdtool/bin/rrdtool create \
/www/htdocs/cacti/rra/219_235_226_34www_http_conns_60.rrd \
--step 300 \
DS:http_conns:GAUGE:600:0:1000 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MIN:0.5:1:600 \
RRA:MIN:0.5:6:700 \
RRA:MIN:0.5:24:775 \
RRA:MIN:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797 \
RRA:LAST:0.5:1:600 \
RRA:LAST:0.5:6:700 \
RRA:LAST:0.5:24:775 \
RRA:LAST:0.5:288:797 \


but in graph data also is 0,why?
i can't find any tools to test this proess,so i do not know where are matter?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 9:34 am 
Offline

Joined: Fri Oct 06, 2006 7:36 am
Posts: 42
For anyone that's using the script above I've updated it;

Code:
#!/bin/bash
# Code updated by Gavin Conway
# [email protected]

#------- User customisation area --------------#
SNMPWALKBINARY=/usr/bin/snmpwalk
ECHOBINARY=/bin/echo
WCBINARY=/usr/bin/wc
#-------- Do not edit below this line ----------#


SYSTEMNAME=$1
PORT=$2
IPADDRESS=$3
COMMUNITY=$4


if [[ -z $SYSTEMNAME || -z $PORT || -z $IPADDRESS || -z $COMMUNITY ]]
then
        echo "Usage: tcp_conns.sh hostname port ipaddress community"
fi

CONNECTIONS=`$SNMPWALKBINARY -On -c $COMMUNITY -v1 $IPADDRESS .1.3.6.1.2.1.6.13.1.3.$SYSTEMNAME.$PORT | $WCBINARY -l`

let "CONNECTIONS = $CONNECTIONS -1"
$ECHOBINARY $CONNECTIONS


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 07, 2007 4:46 am 
Offline
Cacti User

Joined: Sun May 27, 2007 5:42 pm
Posts: 175
Hi UKS-Gavin

Thanks for this new bash script.... but I think the above graph template need to modify also. The reason is that, previously, the community name is hardcoded in the tcp_connection.sh script. Now, your new script get the community script from cacti...and it is not supply by cacti.

SH

UKS-Gavin wrote:
For anyone that's using the script above I've updated it;

Code:
#!/bin/bash
# Code updated by Gavin Conway
# [email protected]

#------- User customisation area --------------#
SNMPWALKBINARY=/usr/bin/snmpwalk
ECHOBINARY=/bin/echo
WCBINARY=/usr/bin/wc
#-------- Do not edit below this line ----------#


SYSTEMNAME=$1
PORT=$2
IPADDRESS=$3
COMMUNITY=$4


if [[ -z $SYSTEMNAME || -z $PORT || -z $IPADDRESS || -z $COMMUNITY ]]
then
        echo "Usage: tcp_conns.sh hostname port ipaddress community"
fi

CONNECTIONS=`$SNMPWALKBINARY -On -c $COMMUNITY -v1 $IPADDRESS .1.3.6.1.2.1.6.13.1.3.$SYSTEMNAME.$PORT | $WCBINARY -l`

let "CONNECTIONS = $CONNECTIONS -1"
$ECHOBINARY $CONNECTIONS


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 1:52 pm 
Offline
Cacti User
User avatar

Joined: Mon Nov 04, 2002 9:15 am
Posts: 110
Location: ACEH
got "0" result from all above script. any update?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 15, 2008 8:11 am 
Offline

Joined: Fri Oct 06, 2006 7:36 am
Posts: 42
Change the script to be like this instead;

Code:
#!/bin/bash
# Code updated by Gavin Conway
# [email protected]

#------- User customisation area --------------#
SNMPWALKBINARY=/usr/bin/snmpwalk
ECHOBINARY=/bin/echo
WCBINARY=/usr/bin/wc
#-------- Do not edit below this line ----------#


SYSTEMNAME=$1
PORT=$2
IPADDRESS=$3
COMMUNITY=PUTYOURCOMMUNITYNAMEHEREIFYOUWANTTHISTOWORK!!!!!!!


if [[ -z $SYSTEMNAME || -z $PORT || -z $IPADDRESS || -z $COMMUNITY ]]
then
        echo "Usage: tcp_conns.sh hostname port ipaddress community"
fi

CONNECTIONS=`$SNMPWALKBINARY -On -c $COMMUNITY -v1 $IPADDRESS .1.3.6.1.2.1.6.13.1.3.$SYSTEMNAME.$PORT | $WCBINARY -l`

let "CONNECTIONS = $CONNECTIONS -1"
$ECHOBINARY $CONNECTIONS
[/quote][/quote]

_________________
www.uksolutions.co.uk
www.ukshells.co.uk


Top
 Profile  
 
 Post subject: stats
PostPosted: Sun Apr 13, 2008 11:29 pm 
Offline

Joined: Sun Apr 13, 2008 11:25 pm
Posts: 1
Hello, I have tried all the scripts, but no matter what I do they only return 0 or -1 respectively, even if i have many HTTP connections to the server.
Did anyone ever find a solution for this?

Thanks,

Brian


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

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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