mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
PureFTPd Application (#11048)
* PureFTPd Application * graphing connected Users
This commit is contained in:
committed by
Kevin Krumm
parent
3629db9464
commit
6ffde9ce2d
@@ -61,6 +61,7 @@ class StringHelpers
|
||||
'smart' => 'SMART',
|
||||
'powerdns-recursor' => 'PowerDNS Recursor',
|
||||
'powerdns-dnsdist' => 'PowerDNS dnsdist',
|
||||
'pureftpd' => 'PureFTPd',
|
||||
'dhcp-stats' => 'DHCP Stats',
|
||||
'ups-nut' => 'UPS nut',
|
||||
'ups-apcups' => 'UPS apcups',
|
||||
|
@@ -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
|
||||
@@ -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.
|
||||
|
31
includes/html/graphs/application/pureftpd_bitrate.inc.php
Normal file
31
includes/html/graphs/application/pureftpd_bitrate.inc.php
Normal file
@@ -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';
|
@@ -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
includes/html/graphs/application/pureftpd_users.inc.php
Normal file
30
includes/html/graphs/application/pureftpd_users.inc.php
Normal file
@@ -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';
|
@@ -45,6 +45,11 @@ $graphs['powerdns-recursor'] = array(
|
||||
'cache_performance',
|
||||
'outqueries'
|
||||
);
|
||||
$graphs['pureftpd'] = array(
|
||||
'bitrate',
|
||||
'connections',
|
||||
'users'
|
||||
);
|
||||
$graphs['rrdcached'] = array(
|
||||
'queue_length',
|
||||
'events',
|
||||
|
25
includes/html/pages/device/apps/pureftpd.inc.php
Normal file
25
includes/html/pages/device/apps/pureftpd.inc.php
Normal file
@@ -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
includes/polling/applications/pureftpd.inc.php
Normal file
94
includes/polling/applications/pureftpd.inc.php
Normal file
@@ -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);
|
Reference in New Issue
Block a user