OpenVPN connections

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

Moderators: Developers, Moderators

Post Reply
User avatar
dk10tlx
Posts: 19
Joined: Sat Aug 04, 2007 8:10 am
Location: Tirol / Austria
Contact:

OpenVPN connections

Post by dk10tlx »

Hi all,

after searching for some hours I've come to ask here for your help. I'd need a template to monitor the number of open/active OpenVPN connections.
Is there a known way to do this with cacti? Has anyone already a solution for this issue?

I do not even know how to "count the open connections" on the commandline, so any kind of help or suggestions are welcome :)

Many thanks in advance
Daniel


PS: Best of all solutions would be a way to provide the stats through snmp, e.g. as we do this with exim-stats or pfoftp-stats.
regards
Daniel

[size=67]
[b]cacti [color=red]0.8.6j[/color] - cactid [color=red]0.8.6i[/color]
Debian GNU/Linux lenny/sid[/b]
Apache2 - PHP5 - MySQL5[/size]
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

What is providing the VPN connections? A hardware firewall, a windows box, a linux box?
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: OpenVPN connections

Post by gandalf »

dk10tlx wrote:I do not even know how to "count the open connections" on the commandline, so any kind of help or suggestions are welcome :)
That's the real problem. You may want to ask for this on an opneVPN forum/mailing list. If you have the command, if have the walkthrough (at the first link of my signature)
Reinhard
User avatar
dk10tlx
Posts: 19
Joined: Sat Aug 04, 2007 8:10 am
Location: Tirol / Austria
Contact:

Post by dk10tlx »

The VPN connections are created on a Linux-box with openvpn-server installed. Therefor I use Debian GNU/Linux with the openvpn-2.0.9-8 package. The used IP ranges are 10.0.10.2 to 10.0.10.200 for the clients. The server itself uses 10.0.10.1 an 10.0.10.2 as the tunnel endpoint/router address.

It seems really to be the most important part to find out how to track the connection with openvpn. Maybe there's someone on the forums who has already had this situation and knows a solution?

At the moment I'm searching around (google etc) for a method to track the connections under linux. I'll post anything I'll find accordingly. :wink:
regards
Daniel

[size=67]
[b]cacti [color=red]0.8.6j[/color] - cactid [color=red]0.8.6i[/color]
Debian GNU/Linux lenny/sid[/b]
Apache2 - PHP5 - MySQL5[/size]
matias
Posts: 2
Joined: Fri Dec 15, 2006 7:39 am

Post by matias »

You can grep this from your openvpn status log.
khufure
Cacti User
Posts: 203
Joined: Wed Oct 24, 2007 5:47 pm
Location: San Francisco, CA
Contact:

Post by khufure »

matias wrote:You can grep this from your openvpn status log.
Better to use the management port.
<conf>
management localhost 7505
</>
# telnet localhost 7505
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
>INFO:OpenVPN Management Interface Version 1 -- type 'help' for more info
status
OpenVPN CLIENT LIST
Updated,Thu Jan 10 10:59:34 2008
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
client1,client.public.ip.here:1045,1287132,13668445,Thu Jan 10 08:23:06 2008
client1,client.public.ip.here:4739,905971,964649,Wed Jan 9 01:53:45 2008
extremoburo
Posts: 1
Joined: Wed Mar 12, 2008 9:51 am

Solution

Post by extremoburo »

Hi. I created this python script which telnets the OpenVpn management interface. Hope it will help you.

import getpass
import sys
import telnetlib
import string
import re

counter = 0

def getInfo():
HOST = "OpenVPN_SERVER_IP"

tn = telnetlib.Telnet(HOST , 7505)

tn.read_until("info")
tn.write("status" + "\n")
string = tn.read_until("END")
tn.write("exit" + "\n")
return string

# parse the output
regex = re.compile("[a-zA-Z0-9]*\,[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}").match
lines = string.split(getInfo(),"\n")

# regex matching for each line, set the total number of occurrences
for line in lines:
if regex(line):
counter += 1

print counter
mox87
Posts: 1
Joined: Fri Mar 02, 2012 2:47 am

Re: OpenVPN connections

Post by mox87 »

Here is the perl script

Code: Select all

#!/usr/bin/perl

use Net::Telnet;

$telnet = new Net::Telnet ( Timeout=>10,
Port=>7505,
Errmode=>'die');

$telnet->open('localhost');

$telnet->waitfor('/>INFO:OpenVPN Management Interface.*$/i');
$telnet->print('status');

($prematch) = $telnet->waitfor('/END$/');

@str = split /\n/, $prematch;
foreach $s (@str) {
        $users++ if $s =~ m/^[a-zA-Z0-9_.-]*\,([0-9]{1,3}\.){3}[0-9]{1,3}:/;
}

print "$users";
2 extremoburo: you have forgotten ^ in your regexp
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests