Added Seafile Server Monitoring (#10465)

* Seafile Monitoring

* generalized function for application with multiple similar entries

* adding snmprec file

* Create linux_seafile-v1.json

* Update linux_seafile-v1.snmprec

Updated linux_seafile-v1.snmprec to use 4x for encoding json data response

* Update Applications.md
This commit is contained in:
SourceDoctor
2019-10-22 00:28:21 +02:00
committed by Neil Lathwood
parent d3994b3671
commit 8f1c77545d
16 changed files with 588 additions and 31 deletions

View File

@@ -1432,6 +1432,53 @@ the user snmpd is using with `ps aux | grep snmpd`
5: Restart snmpd on PI host
# Seafile
## SNMP Extend
1: Copy the Python script, seafile.py, to the desired host. `wget
https://github.com/librenms/librenms-agent/raw/master/snmp/seafile.py -O
/etc/snmp/seafile.py`
Also you have to install the requests Package for Python3.
Under Ubuntu/Debian just run `apt install python3-requests`
2: Run `chmod +x /etc/snmp/seafile.py`
3: Edit your snmpd.conf file and add:
```
extend seafile /etc/snmp/seafile.py
```
4: You will also need to create the config file, which is named
seafile.json . The script has to be located at /etc/snmp/.
```
{"url": "https://seafile.mydomain.org",
"username": "some_admin_login@mail.address",
"password": "password",
"account_identifier": "name"
"hide_monitoring_account": true
}
```
The variables are as below.
```
url = Url how to get access to Seafile Server
username = Login to Seafile Server.
It is important that used Login has admin privileges.
Otherwise most API calls will be denied.
password = Password to the configured login.
the device name. 1 is the default. 0 will use the device name.
account_identifier = Defines how accounts are listed.
Options are: name, email
hide_monitoring_account = With this Boolean you can hide the Account which you
use to access Seafile API
```
# SMART
## SNMP Extend

View File

@@ -1290,31 +1290,65 @@ function get_postgres_databases($device_id)
return array();
}
/**
* Get all application data from the collected
* rrd files.
*
* @param array $device device for which we get the rrd's
* @param int $app_id application id on the device
* @param string $category which category of seafile graphs are searched
* @return array list of entry data
*/
function get_arrays_with_application($device, $app_id, $app_name, $category = null)
{
$entries = array();
if ($category) {
$pattern = sprintf('%s/%s-%s-%s-%s-*.rrd', get_rrd_dir($device['hostname']), 'app', $app_name, $app_id, $category);
} else {
$pattern = sprintf('%s/%s-%s-%s-*.rrd', get_rrd_dir($device['hostname']), 'app', $app_name, $app_id);
}
foreach (glob($pattern) as $rrd) {
$filename = basename($rrd, '.rrd');
list(,,, $entry) = explode("-", $filename, 4);
if ($entry) {
array_push($entries, $entry);
}
}
return $entries;
}
/**
* Get all seafile data from the collected
* rrd files.
*
* @param array $device device for which we get the rrd's
* @param int $app_id application id on the device
* @param string $category which category of seafile graphs are searched
* @return array list of seafile data
*/
function get_arrays_with_seafile($device, $app_id, $category)
{
$app_name = 'seafile';
return get_arrays_with_application($device, $app_id, $app_name, $category);
}
/**
* Get all mdadm arrays from the collected
* rrd files.
*
* @param array $device device for which we get the rrd's
* @param int $app_id application id on the device
* @return array list of disks
* @return array list of raid-arrays
*/
function get_arrays_with_mdadm($device, $app_id)
{
$arrays = array();
$pattern = sprintf('%s/%s-%s-%s-*.rrd', get_rrd_dir($device['hostname']), 'app', 'mdadm', $app_id);
foreach (glob($pattern) as $rrd) {
$filename = basename($rrd, '.rrd');
list(,,, $array_name) = explode("-", $filename, 4);
if ($array_name) {
array_push($arrays, $array_name);
}
}
return $arrays;
$app_name = 'mdadm';
return get_arrays_with_application($device, $app_id, $app_name);
}
/**
@@ -1327,21 +1361,8 @@ function get_arrays_with_mdadm($device, $app_id)
*/
function get_disks_with_smart($device, $app_id)
{
$disks = array();
$pattern = sprintf('%s/%s-%s-%s-*.rrd', get_rrd_dir($device['hostname']), 'app', 'smart', $app_id);
foreach (glob($pattern) as $rrd) {
$filename = basename($rrd, '.rrd');
list(,,, $disk) = explode("-", $filename, 4);
if ($disk) {
array_push($disks, $disk);
}
}
return $disks;
$app_name = 'smart';
return get_arrays_with_application($device, $app_id, $app_name);
}
/**

View File

@@ -0,0 +1,35 @@
<?php
$name = 'seafile';
$app_id = $app['app_id'];
$colours = 'mega';
$dostack = 0;
$printtotal = 0;
$addarea = 1;
$transparency = 15;
if (isset($vars['array'])) {
$arrays=array($vars['array']);
} else {
$arrays=get_arrays_with_seafile($device, $app['app_id'], $category);
}
$int=0;
while (isset($arrays[$int])) {
$array=$arrays[$int];
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
if (rrdtool_check_rrd_exists($rrd_filename)) {
$rrd_list[]=array(
'filename' => $rrd_filename,
'descr' => str_replace($category.'-', '', $array),
'ds' => $rrdVar,
);
}
$int++;
}
if ($unit_type == 'float') {
require 'includes/html/graphs/generic_multi_line.inc.php';
} else {
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';
}

View File

@@ -0,0 +1,11 @@
<?php
$unit_text = 'Connected Devices';
$unitlen = 20;
$bigdescrlen = 20;
$smalldescrlen = 20;
$unit_type = 'int';
$category = 'sysinfo';
$rrdVar='connected';
require 'seafile-common.inc.php';

View File

@@ -0,0 +1,11 @@
<?php
$unit_text = 'activated Accounts';
$unitlen = 20;
$bigdescrlen = 20;
$smalldescrlen = 20;
$unit_type = 'int';
$category = 'acc';
$rrdVar='enabled';
require 'seafile-common.inc.php';

View File

@@ -0,0 +1,11 @@
<?php
$unit_text = 'Groups';
$unitlen = 20;
$bigdescrlen = 20;
$smalldescrlen = 20;
$unit_type = 'int';
$category = 'grp';
$rrdVar='count';
require 'seafile-common.inc.php';

View File

@@ -0,0 +1,11 @@
<?php
$unit_text = 'libraries';
$unitlen = 20;
$bigdescrlen = 20;
$smalldescrlen = 20;
$unit_type = 'int';
$category = 'acc';
$rrdVar='libraries';
require 'seafile-common.inc.php';

View File

@@ -0,0 +1,11 @@
<?php
$unit_text = 'Client Platform';
$unitlen = 20;
$bigdescrlen = 20;
$smalldescrlen = 20;
$unit_type = 'int';
$category = 'cltos';
$rrdVar='platform';
require 'seafile-common.inc.php';

View File

@@ -0,0 +1,11 @@
<?php
$unit_text = 'Usage (Byte)';
$unitlen = 20;
$bigdescrlen = 20;
$smalldescrlen = 20;
$unit_type = 'float';
$category = 'acc';
$rrdVar = 'size_consumption';
require 'seafile-common.inc.php';

View File

@@ -0,0 +1,11 @@
<?php
$unit_text = 'trashed libraries';
$unitlen = 20;
$bigdescrlen = 20;
$smalldescrlen = 20;
$unit_type = 'int';
$category = 'acc';
$rrdVar='trashed_libraries';
require 'seafile-common.inc.php';

View File

@@ -0,0 +1,11 @@
<?php
$unit_text = 'Client Version';
$unitlen = 20;
$bigdescrlen = 20;
$smalldescrlen = 20;
$unit_type = 'int';
$category = 'cltver';
$rrdVar='version';
require 'seafile-common.inc.php';

View File

@@ -162,6 +162,16 @@ $graphs['nvidia'] = array(
'sbecc',
'dbecc',
);
$graphs['seafile'] = array(
'connected',
'enabled',
'libraries',
'trashed_libraries',
'size_consumption',
'groups',
'version',
'platform',
);
$graphs['squid'] = array(
'memory',
'clients',

View File

@@ -0,0 +1,32 @@
<?php
$graphs = array(
'seafile_connected' => 'Connected Devices',
'seafile_enabled' => 'activated Accounts',
'seafile_libraries' => 'Libraries',
'seafile_trashed_libraries' => 'Trashed Libraries',
'seafile_size_consumption' => 'Size Consumption',
'seafile_groups' => 'Groups',
'seafile_version' => 'Client Version',
'seafile_platform' => 'Client Platform',
);
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>';
}

View File

@@ -0,0 +1,137 @@
<?php
use LibreNMS\Exceptions\JsonAppMissingKeysException;
use LibreNMS\Exceptions\JsonAppException;
use LibreNMS\RRD\RrdDefinition;
$name = 'seafile';
$app_id = $app['app_id'];
$output = 'OK';
try {
$seafile_data = json_app_get($device, $name, 1)['data'];
} catch (JsonAppMissingKeysException $e) {
$seafile_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;
}
$account_data = $seafile_data['accounts'];
$client_version = $seafile_data['devices']['client_version'];
$client_platform = $seafile_data['devices']['platform'];
$group_data = $seafile_data['groups'];
$sysinfo_data = $seafile_data['sysinfo'];
$rrd_name = array('app', $name, $app_id);
$rrd_def = RrdDefinition::make()
->addDataset('enabled', 'GAUGE', 0)
->addDataset('libraries', 'GAUGE', 0)
->addDataset('trashed_libraries', 'GAUGE', 0)
->addDataset('size_consumption', 'GAUGE', 0);
$category = 'acc';
$metrics = array();
# handling accounts
foreach ($account_data as $data) {
$owner_name = str_replace(' ', '_', $data['owner']);
$enabled = $data['is_active'] ? 1: 0;
$libraries = $data['repos'];
$trashed_libraries = $data['trash_repos'];
$size_consumption = $data['usage'];
$rrd_name = array('app', $name, $app_id, $category, $owner_name);
$fields = array(
'enabled' => $enabled,
'libraries' => $libraries,
'trashed_libraries' => $trashed_libraries,
'size_consumption' => $size_consumption
);
$metrics[$owner_name.'_'.$category] = $fields;
$tags = array('name' => $owner_name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
}
# handling groups
$rrd_def = RrdDefinition::make()
->addDataset('count', 'GAUGE', 0);
$category = 'grp';
$group_name = 'groups';
$group_count = $group_data['count'];
$rrd_name = array('app', $name, $app_id, $category, $group_name);
$fields = array(
'count' => $group_count,
);
$metrics[$group_name.'_'.$category] = $fields;
$tags = array('name' => $group_name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
# handling client version
$rrd_def = RrdDefinition::make()
->addDataset('version', 'GAUGE', 0);
$category = 'cltver';
foreach ($client_version as $data) {
$version_name = $data['client_version'];
$version_count = $data['clients'];
$rrd_name = array('app', $name, $app_id, $category, $version_name);
$fields = array(
'version' => $version_count,
);
$metrics[$version_name.'_'.$category] = $fields;
$tags = array('name' => $version_name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
}
# handling client platform
$rrd_def = RrdDefinition::make()
->addDataset('platform', 'GAUGE', 0);
$category = 'cltos';
foreach ($client_platform as $data) {
$os_name = $data['os_name'];
$os_count = $data['clients'];
$rrd_name = array('app', $name, $app_id, $category, $os_name);
$fields = array(
'platform' => $os_count,
);
$metrics[$os_name.'_'.$category] = $fields;
$tags = array('name' => $os_name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
}
# handling sysinfo
$rrd_def = RrdDefinition::make()
->addDataset('connected', 'GAUGE', 0);
$category = 'sysinfo';
$sysinfo_name = 'devices';
$sysinfo_connected_devices = $sysinfo_data['current_connected_devices_count'];
$rrd_name = array('app', $name, $app_id, $category, $sysinfo_name);
$fields = array(
'connected' => $sysinfo_connected_devices,
);
$metrics[$sysinfo_name.'_'.$category] = $fields;
$tags = array('name' => $sysinfo_name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
update_application($app, $output, $metrics);

View File

@@ -0,0 +1,177 @@
{
"os": {
"discovery": {
"devices": [
{
"sysName": "<private>",
"sysObjectID": ".1.3.6.1.4.1.8072.3.2.10",
"sysDescr": "Linux SERVERNAME 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2 (2019-08-28) x86_64",
"sysContact": null,
"version": null,
"hardware": null,
"features": null,
"os": "linux",
"type": "server",
"serial": null,
"icon": "linux.svg",
"location": null
}
]
},
"poller": {
"devices": [
{
"sysName": "<private>",
"sysObjectID": ".1.3.6.1.4.1.8072.3.2.10",
"sysDescr": "Linux SERVERNAME 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2 (2019-08-28) x86_64",
"sysContact": "<private>",
"version": "4.19.0-6-amd64",
"hardware": "Generic x86 64-bit",
"features": null,
"os": "linux",
"type": "server",
"serial": null,
"icon": "linux.svg",
"location": "<private>"
}
]
}
},
"applications": {
"discovery": {
"applications": [
{
"app_type": "seafile",
"app_state": "UNKNOWN",
"discovered": 1,
"app_state_prev": null,
"app_status": "",
"app_instance": ""
}
],
"application_metrics": []
},
"poller": {
"applications": [
{
"app_type": "seafile",
"app_state": "OK",
"discovered": 1,
"app_state_prev": "UNKNOWN",
"app_status": "",
"app_instance": ""
}
],
"application_metrics": [
{
"metric": "2.2.1_cltver_version",
"value": 1,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "6.1.5_cltver_version",
"value": 2,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "devices_sysinfo_connected",
"value": 1,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "groups_grp_count",
"value": 3,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test os 1_cltos_platform",
"value": 4,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test os 2_cltos_platform",
"value": 7,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test_user_1_acc_enabled",
"value": 1,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test_user_1_acc_libraries",
"value": 1,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test_user_1_acc_size_consumption",
"value": 311296,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test_user_1_acc_trashed_librarie",
"value": 0,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test_user_2_acc_enabled",
"value": 1,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test_user_2_acc_libraries",
"value": 0,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test_user_2_acc_size_consumption",
"value": 0,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test_user_2_acc_trashed_librarie",
"value": 0,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test_user_3_acc_enabled",
"value": 0,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test_user_3_acc_libraries",
"value": 1,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test_user_3_acc_size_consumption",
"value": 311296,
"value_prev": null,
"app_type": "seafile"
},
{
"metric": "test_user_3_acc_trashed_librarie",
"value": 0,
"value_prev": null,
"app_type": "seafile"
}
]
}
}
}

View File

@@ -0,0 +1,10 @@
1.3.6.1.2.1.1.1.0|4|Linux SERVERNAME 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2 (2019-08-28) x86_64
1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.8072.3.2.10
1.3.6.1.2.1.1.3.0|67|2525
1.3.6.1.2.1.1.4.0|4|<private>
1.3.6.1.2.1.1.5.0|4|<private>
1.3.6.1.2.1.1.6.0|4|<private>
1.3.6.1.2.1.25.1.1.0|67|77552962
1.3.6.1.4.1.8072.1.3.2.2.1.21.7.115.101.97.102.105.108.101|2|1
1.3.6.1.4.1.8072.1.3.2.3.1.2.7.115.101.97.102.105.108.101|4x|7B2276657273696F6E223A20312C20226572726F72223A20302C20226572726F72537472696E67223A2022222C202264617461223A207B22737973696E666F223A207B226D756C74695F74656E616E63795F656E61626C6564223A2066616C73652C20226F72675F636F756E74223A20302C20227265706F735F636F756E74223A2033322C2022746F74616C5F73746F72616765223A2031343836343331343033372C20226163746976655F75736572735F636F756E74223A2031312C202269735F70726F223A2066616C73652C202275736572735F636F756E74223A2031312C20226C6963656E73655F746F223A2022222C20226C6963656E73655F6D6F6465223A2022222C20226C6963656E73655F6D61787573657273223A20302C2022746F74616C5F66696C65735F636F756E74223A2033363139382C2022746F74616C5F646576696365735F636F756E74223A2031392C202263757272656E745F636F6E6E65637465645F646576696365735F636F756E74223A20312C2022776974685F6C6963656E7365223A2066616C73652C20226C6963656E73655F65787069726174696F6E223A2022222C202267726F7570735F636F756E74223A20337D2C20226163636F756E7473223A205B7B227265706F73223A20312C202269735F616374697665223A20747275652C20226F776E6572223A20227465737420757365722031222C20227573616765223A203331313239362C202274726173685F7265706F73223A20307D2C207B227265706F73223A20302C202269735F616374697665223A20747275652C20226F776E6572223A20227465737420757365722032222C20227573616765223A20302C202274726173685F7265706F73223A20307D2C207B227265706F73223A20312C202269735F616374697665223A2066616C73652C20226F776E6572223A20227465737420757365722033222C20227573616765223A203331313239362C202274726173685F7265706F73223A20307D5D2C202264657669636573223A207B22636C69656E745F76657273696F6E223A205B7B22636C69656E7473223A20322C2022636C69656E745F76657273696F6E223A2022362E312E35227D2C207B22636C69656E7473223A20312C2022636C69656E745F76657273696F6E223A2022322E322E31227D5D2C2022706C6174666F726D223A205B7B22636C69656E7473223A20342C20226F735F6E616D65223A202274657374206F732031227D2C207B22636C69656E7473223A20372C20226F735F6E616D65223A202274657374206F732032227D5D7D2C202267726F757073223A207B22636F756E74223A20337D7D7D
1.3.6.1.6.3.10.2.1.3.0|2|25