ProFTP Users online

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:

ProFTP Users online

Post by dk10tlx »

Hi all,

Here's a quick 'n' dirty hack to monitor the count of ftp users online.

1) create a script

Code: Select all

#!/bin/bash
ftpwho -v -f /var/run/proftpd/proftpd.scoreboard | grep user | cut -d "-" -f2 | sed -e 's/ //g' -e 's/user.*$//g'
2) cron the script

Code: Select all

2,7,12,17,22,27,32,37,42,47,52,57 * * * * root /usr/local/sbin/proftpd.sh > /etc/snmp/proftpd.stats 2>/dev/null
3) let snmpd know about it

Code: Select all

exec .1.3.6.1.4.1.14464.21 proftpd /bin/cat /etc/snmp/proftpd.stats
Attachments
cacti_data_query_proftpd_user.xml
(1.83 KiB) Downloaded 734 times
cacti_data_template_ucdnet_proftpd_user.xml
(6.48 KiB) Downloaded 570 times
cacti_graph_template_proftp_user.xml
(12.1 KiB) Downloaded 716 times
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
dk10tlx
Posts: 19
Joined: Sat Aug 04, 2007 8:10 am
Location: Tirol / Austria
Contact:

Post by dk10tlx »

Has anyone tried it or is using it? Please let me know.
:D
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]
dexinou
Posts: 4
Joined: Mon Feb 11, 2008 3:19 am

Post by dexinou »

I want to try it but I'm using pure-ftpd.
:lol:
User avatar
cyrill
Cacti User
Posts: 271
Joined: Fri Jan 25, 2008 8:43 am
Location: California - USA

Post by cyrill »

my too but I use FileZilla xD
chronos
Posts: 5
Joined: Tue Feb 12, 2008 1:07 pm

Post by chronos »

I am not able to do the "exec" part on my FreeBSD machine. How is snmpd supposed to get the stats from "exec"?


Edit: Never mind, didn't know you had to add that line to your snmpd.conf file.

Thanks!
ephlin
Posts: 5
Joined: Mon Sep 17, 2007 12:20 am

Post by ephlin »

i can't run in solaris system

[#root@liwei-unix:/usr/local/sbin]#/usr/local/sbin/proftpd.sh
ftpwho: illegal option -- v
usage: ftpwho [-V]
torstenker
Posts: 1
Joined: Fri Feb 06, 2009 5:32 pm

Onother way

Post by torstenker »

Hi Guys
What I have done uncer freebsd 6x and 7x plus net-snmp, I have created a extend command in the snmpd.con in /usr/local/etc/snmp/snmpd.comf as follows:
extend .1.3.6.1.4.1.14464.21 proftpd /usr/local/etc/snmp/proftpd.sh

the proftpd.sh looks like this
************************
#!/bin/sh
ftpusers=`/usr/local/bin/ftpwho -v -f /var/run/proftpd/proftpd.scoreboard | grep user | cut -d "-" -f2 | sed -e 's/ //g' -e 's/user.*$//g'`
echo ${ftpusers}
************************

In cacti itself I created a graph using the SNMP - Generic OID Template
with values:
title: |host_description| - FTP USERS
Internal Data Source Name: ftp_users
Maximum Value: 10000
OID: .1.3.6.1.4.1.14464.21.4.1.2.7.112.114.111.102.116.112.100.1

That sorted it and works perfectly

All of the stuff above is (of course) from here and changed a bit to make it simple.

Same I did for the tomcat monitoring, I will try to post that later
Regrard and good luck
Torsten
asakawa
Posts: 2
Joined: Tue Jul 31, 2007 9:39 pm

proftpd 1.3.2-1.el5

Post by asakawa »

centos 5.# on proftpd 1.3.2-1.el5
The output name has been changed from this version.

/usr/local/sbin/proftpd.sh

Code: Select all

#!/bin/bash 
ftpwho -v -f /var/run/proftpd.score | grep user | cut -d "-" -f2 | sed -e 's/ //g' -e 's/user.*$//g'
dklima
Posts: 8
Joined: Wed Aug 13, 2008 5:15 pm

Post by dklima »

I´m getting this when using the template:

Code: Select all

+ Running data query [30].
+ Found type = '4 '[script query].
+ Found data query XML file at '/var/www/cacti/resource/'
+ Error parsing XML file into an array.
+ Found data query XML file at '/var/www/cacti/resource/'
+ Found data query XML file at '/var/www/cacti/resource/'
+ Found data query XML file at '/var/www/cacti/resource/'
Dyr
Posts: 23
Joined: Mon Sep 10, 2007 5:21 am

Post by Dyr »

I suggest something a little bit better. Script for counting selected client host (by DNS name or ip), selected server (by DNS name or ip) or selected client name.

Let's party begin!
Input:
ftpwho -v

Code: Select all

standalone FTP daemon [10049], up for  1 hr 53 min
13951 ftp      [ 0m17s]  0m17s idle
        client: sa-st-8.smartspb.net [217.119.16.26]
        server: 192.168.0.3:21 (dyr.ozerki.net)
        location: /

13953 ftp      [ 0m13s]  0m13s idle
        client: sa-st-8.smartspb.net [217.119.16.26]
        server: 192.168.0.3:21 (dyr.ozerki.net)
        location: /

13954 photosight [  0m9s]   0m8s idle
        client: sa-st-8.smartspb.net [217.119.16.26]
        server: 192.168.0.3:21 (dyr.ozerki.net)
        location: /

Service class                      -   3 users
Output:
/usr/local/share/cacti/plugins/scripts/unix_proftpd_who.pl --user photosight

Code: Select all

selected:1 total:3
/usr/local/share/cacti/plugins/scripts/unix_proftpd_who.pl --user ftp

Code: Select all

selected:2 total:3
/usr/local/share/cacti/plugins/scripts/unix_proftpd_who.pl --client sa-st-8.smartspb.net

Code: Select all

selected:3 total:3
/usr/local/share/cacti/plugins/scripts/unix_proftpd_who.pl --client 217.119.16.26

Code: Select all

selected:3 total:3
/usr/local/share/cacti/plugins/scripts/unix_proftpd_who.pl --client nonexistent.net

Code: Select all

selected:0 total:3
/usr/local/share/cacti/plugins/scripts/unix_proftpd_who.pl --server 192.168.0.3

Code: Select all

selected:3 total:3
/usr/local/share/cacti/plugins/scripts/unix_proftpd_who.pl --server 1.1.1.1

Code: Select all

selected:0 total:3
Script code (also attached below):

Code: Select all

#!/usr/bin/perl
#===============================================================================
#
#         FILE:  unix_proftpd_who.pl
#
#        USAGE:  ./unix_proftpd_who.pl [--user|--host|--server] parameter
#
#  DESCRIPTION: Print out user|client|server count and total users count for cacti use
#
#      OPTIONS:  ---
# REQUIREMENTS:  Installed and configured ProFTPD
#         BUGS:  ---
#        NOTES:  ---
#       AUTHOR:  Dennis Yusupoff (dyr), denissia@mail.ru
#      COMPANY:  Smart-Telecom ISP
#      VERSION:  1.0
#      CREATED:  04.06.2009 18:46:55
#     REVISION:  ---
#===============================================================================

use strict;
use warnings;
use Getopt::Long;

my $cmd =  "/usr/local/bin/ftpwho";
my $args = " -v -o oneline";

my (%hash,$user,$client,$server,$help);
my $total = 0;

GetOptions('user=s' => \$user,
        'client=s' => \$client,
        'server=s' => \$server,
        'help|?' => \$help);
&usage if $help;
&usage if ( $user ? ($client || $server) : ($client && $server) );  #Allow only one parameter
open(FH, "$cmd $args |") or die "Cannon execute command: $!\n";
while(<FH>) {
    if ($client) {
        if (/client:\s(.+)\s\[(\d+\.\d+\.\d+\.\d+)\]/){
            #$1 - client host name (ReverseDns)
            #$2 - client host ip
            $hash{$1}++;
            #Or by ip
            $hash{$2}++ unless ($1 eq $2);  #Prevent to duplicate ip if UseReverseDNS is Off in proftpd.conf
            $total++;
        }
    }elsif ($server) {
        if (/server:\s(\d+\.\d+\.\d+\.\d+):(\d+)\s\((.+)\)/){
            #$1 - server ip
            #$2 - server port
            #$3 - server name
            $hash{$1}++;
            $hash{$3}++ unless ($3 eq $1);  #Prevent to duplicate servername if it equal ip
            $total++;
        }
    }else  {
        if (/^\s*(\d+)\s(\w+)\s+.+client:\s(.+)\s\[(\d+\.\d+\.\d+\.\d+)\]/){
            #$1 - ID
            #$2 - username
            $hash{$2}++;
            $total++;
        }
    }
}
close(FH);

if ($server) {
    print "selected:".($hash{$server} || 0);
}elsif ($client) {
    print "selected:".($hash{$client} || 0);
}elsif ($user) {
    print "selected:".($hash{$user} || 0);
}else {
    print "selected:U";
}

print " total:$total\n";


sub usage {
    print "Usage: @_ [--user|--host|--server] parameter\n";
    exit 0;
}
Attachments
unix_proftpd_who.pl
(2.17 KiB) Downloaded 333 times
Stunty
Posts: 21
Joined: Sun Jun 08, 2008 11:32 am
Location: France

Post by Stunty »

I do not understand how to make of this perl script.
Can you explain where to put in the OS and how to add into Cacti?
Dyr
Posts: 23
Joined: Mon Sep 10, 2007 5:21 am

Post by Dyr »

Stunty wrote:I do not understand how to make of this perl script.
Can you explain where to put in the OS and how to add into Cacti?
Put in the scripts folder and add it as always add scripts data input.
Stunty
Posts: 21
Joined: Sun Jun 08, 2008 11:32 am
Location: France

Post by Stunty »

Humm I added the scripts into /var/www/html/scripts and the xml templates into ressources/snmp_queries added them in "Import Templates" but my graph still flat...

Code: Select all

/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=1244643300 \
--end=1244729700 \
--title="FTP server - ProFTP User" \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
COMMENT:"From 2009/06/10 16\:15\:00 To 2009/06/11 16\:15\:00\c" \
COMMENT:"  \n" \
--vertical-label="FTP User" \
--slope-mode \
--font TITLE:10: \
--font AXIS:8: \
--font LEGEND:8: \
--font UNIT:8: \
DEF:a="/var/www/html/rra/ftp_server_user_214.rrd":user:MAX \
DEF:b="/var/www/html/rra/ftp_server_online_213.rrd":online:MAX \
AREA:a#DE0056FF:"FTP User"  \
GPRINT:b:LAST:"Cur\:%8.0lf"  \
GPRINT:b:AVERAGE:"Avg\:%8.0lf"  \
GPRINT:b:MAX:"Max\:%8.0lf" 
Where can I found where the problem comes from?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest