Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PureFTPd Application #11048

Merged
merged 2 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions LibreNMS/Util/StringHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static function niceCase($string)
'smart' => 'SMART',
'powerdns-recursor' => 'PowerDNS Recursor',
'powerdns-dnsdist' => 'PowerDNS dnsdist',
'pureftpd' => 'PureFTPd',
'dhcp-stats' => 'DHCP Stats',
'ups-nut' => 'UPS nut',
'ups-apcups' => 'UPS apcups',
Expand Down
41 changes: 41 additions & 0 deletions doc/Extensions/Applications.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ by following the steps under the `SNMP Extend` heading.
1. [PowerDNS Recursor](#powerdns-recursor) - Direct, SNMP extend, Agent
1. [PowerDNS dnsdist](#powerdns-dnsdist) - SNMP extend
1. [Proxmox](#proxmox) - SNMP extend
1. [PureFTPd](#pureftpd) - SNMP extend
1. [Raspberry PI](#raspberry-pi) - SNMP extend
1. [SDFS info](#sdfs-info) - SNMP extend
1. [Seafile](#seafile) - SNMP extend
Expand Down Expand Up @@ -1439,6 +1440,46 @@ snmp ALL=(ALL) NOPASSWD: /usr/local/bin/proxmox

6: Restart snmpd on your host

# PureFTPd

SNMP extend script to monitor PureFTPd.

## SNMP Extend

1: Download the script onto the desired host. `wget
https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/pureftpd.py
-O /etc/snmp/pureftpd.py`

2: Make the script executable: `chmod +x /etc/snmp/pureftpd.py`

3: Edit your snmpd.conf file (usually `/etc/snmp/snmpd.conf`) and add:

```
extend pureftpd /etc/snmp/pureftpd.py
```

4: Edit your sudo users (usually `visudo`) and add at the bottom:

```
snmp ALL=(ALL) NOPASSWD: /usr/sbin/pure-ftpwho
```
or the path where your pure-ftpwho is located


5: If pure-ftpwho is not located in /usr/sbin

you will also need to create the config file, which is named

pureftpd.json . The file has to be located in /etc/snmp/.


```
{"pureftpwho_cmd": "/usr/sbin/pure-ftpwho"
}
```

5: Restart snmpd on your host

# Raspberry PI

SNMP extend script to get your PI data into your host.
Expand Down
31 changes: 31 additions & 0 deletions includes/html/graphs/application/pureftpd_bitrate.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
require 'includes/html/graphs/common.inc.php';
$scale_min = 0;
$nototal = 1;
$unit_text = 'bit/s';
$unitlen = 10;
$bigdescrlen = 15;
$smalldescrlen = 15;
$colours = 'mixed';

$array = array(
'download' => 'Download',
'upload' => 'Upload',
);

$rrd_filename = rrd_name($device['hostname'], array('app', 'pureftpd', $app['app_id'], 'bitrate'));

$rrd_list = array();
if (rrdtool_check_rrd_exists($rrd_filename)) {
$i = 0;
foreach ($array as $ds => $descr) {
$rrd_list[$i]['filename'] = $rrd_filename;
$rrd_list[$i]['descr'] = $descr;
$rrd_list[$i]['ds'] = $ds;
$i++;
}
} else {
echo "file missing: $rrd_filename";
}

require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';
32 changes: 32 additions & 0 deletions includes/html/graphs/application/pureftpd_connections.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
require 'includes/html/graphs/common.inc.php';
$scale_min = 0;
$nototal = 1;
$unit_text = 'Connections';
$unitlen = 15;
$bigdescrlen = 20;
$smalldescrlen = 15;
$colours = 'mixed';

$array = array(
'download' => 'Download',
'upload' => 'Upload',
'idle' => 'Idle'
);

$rrd_filename = rrd_name($device['hostname'], array('app', 'pureftpd', $app['app_id'], 'connections'));

$rrd_list = array();
if (rrdtool_check_rrd_exists($rrd_filename)) {
$i = 0;
foreach ($array as $ds => $descr) {
$rrd_list[$i]['filename'] = $rrd_filename;
$rrd_list[$i]['descr'] = $descr;
$rrd_list[$i]['ds'] = $ds;
$i++;
}
} else {
echo "file missing: $rrd_filename";
}

require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';
30 changes: 30 additions & 0 deletions includes/html/graphs/application/pureftpd_users.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
require 'includes/html/graphs/common.inc.php';
$scale_min = 0;
$nototal = 1;
$unit_text = 'Users connected';
$unitlen = 15;
$bigdescrlen = 20;
$smalldescrlen = 15;
$colours = 'mixed';

$array = array(
'total' => 'Total',
);

$rrd_filename = rrd_name($device['hostname'], array('app', 'pureftpd', $app['app_id'], 'users'));

$rrd_list = array();
if (rrdtool_check_rrd_exists($rrd_filename)) {
$i = 0;
foreach ($array as $ds => $descr) {
$rrd_list[$i]['filename'] = $rrd_filename;
$rrd_list[$i]['descr'] = $descr;
$rrd_list[$i]['ds'] = $ds;
$i++;
}
} else {
echo "file missing: $rrd_filename";
}

require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';
5 changes: 5 additions & 0 deletions includes/html/pages/apps.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
'cache_performance',
'outqueries'
);
$graphs['pureftpd'] = array(
'bitrate',
'connections',
'users'
);
$graphs['rrdcached'] = array(
'queue_length',
'events',
Expand Down
25 changes: 25 additions & 0 deletions includes/html/pages/device/apps/pureftpd.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
$graphs = array(
'pureftpd_bitrate' => 'PureFTPd - Bitrate',
'pureftpd_connections' => 'PureFTPd - Connections',
'pureftpd_users' => 'PureFTPd - Users Connected',
);

foreach ($graphs as $key => $text) {
$graph_type = $key;
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = time();
$graph_array['id'] = $app['app_id'];
$graph_array['type'] = 'application_'.$key;
echo '<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">'.$text.'</h3>
</div>
<div class="panel-body">
<div class="row">';
include 'includes/html/print-graphrow.inc.php';
echo '</div>';
echo '</div>';
echo '</div>';
}
94 changes: 94 additions & 0 deletions includes/polling/applications/pureftpd.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

use LibreNMS\Exceptions\JsonAppMissingKeysException;
use LibreNMS\Exceptions\JsonAppException;
use LibreNMS\RRD\RrdDefinition;

$name = 'pureftpd';
$app_id = $app['app_id'];
$output = 'OK';

try {
$pureftpd_data = json_app_get($device, $name, 1)['data'];
} catch (JsonAppMissingKeysException $e) {
$pureftpd_data = $e->getParsedJson();
} catch (JsonAppException $e) {
echo PHP_EOL . $name . ':' .$e->getCode().':'. $e->getMessage() . PHP_EOL;
update_application($app, $e->getCode().':'.$e->getMessage(), []); // Set empty metrics and error message
return;
}

$dl_connections = 0;
$ul_connections = 0;
$idle_connections = 0;

$dl_bitrate = 0;
$ul_bitrate = 0;

$users_connected = 0;

foreach ($pureftpd_data as $client) {
$users_connected++;

$state = 'DL';
if (array_key_exists($state, $client)) {
$dl_connections += $client[$state]['connections'];
$dl_bitrate += $client[$state]['bitrate'];
}

$state = 'UL';
if (array_key_exists($state, $client)) {
$ul_connections += $client[$state]['connections'];
$ul_bitrate += $client[$state]['bitrate'];
}

$state = 'IDLE';
if (array_key_exists($state, $client)) {
$idle_connections += $client[$state]['connections'];
}
}

$metrics = array();
#PureFTPd - Connections
$dataset = 'connections';
$rrd_name = array('app', $name, $app_id, $dataset);
$rrd_def = RrdDefinition::make()
->addDataset('download', 'GAUGE', 0)
->addDataset('upload', 'GAUGE', 0)
->addDataset('idle', 'GAUGE', 0);
$fields = array (
'download' => $dl_connections,
'upload' => $ul_connections,
'idle' => $idle_connections
);
$metrics[$dataset] = $fields;
$tags = array('name' => $dataset, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);

#PureFTPd - connected Users
$dataset = 'users';
$rrd_name = array('app', $name, $app_id, $dataset);
$rrd_def = RrdDefinition::make()
->addDataset('total', 'GAUGE', 0);
$fields = array (
'total' => $users_connected
);
$metrics[$dataset] = $fields;
$tags = array('name' => $dataset, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);

#PureFTPd - Bitrate
$dataset = 'bitrate';
$rrd_name = array('app', $name, $app_id, $dataset);
$rrd_def = RrdDefinition::make()
->addDataset('download', 'GAUGE', 0)
->addDataset('upload', 'GAUGE', 0);
$fields = array (
'download' => $dl_bitrate,
'upload' => $ul_bitrate,
);
$metrics[$dataset] = $fields;
$tags = array('name' => $dataset, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);

update_application($app, $output, $metrics);