Puppet Agent Monitoring (#10827)

* puppet agent monitoring

* change position of last run graph

* device overview panel

* updating documentation

* mouseover for Overview Dashboard

* adding blank line for code climate
This commit is contained in:
SourceDoctor
2020-02-12 08:26:02 +01:00
committed by GitHub
parent 95820bf5d4
commit 53dc564ef5
11 changed files with 475 additions and 2 deletions

View File

@@ -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. [Puppet Agent](#puppet_agent) - SNMP extend
1. [PureFTPd](#pureftpd) - SNMP extend
1. [Raspberry PI](#raspberry-pi) - SNMP extend
1. [SDFS info](#sdfs-info) - SNMP extend
@@ -1440,6 +1441,43 @@ snmp ALL=(ALL) NOPASSWD: /usr/local/bin/proxmox
6: Restart snmpd on your host
# Puppet Agent
SNMP extend script to get your Puppet Agent data into your host.
## SNMP Extend
1: Download the script onto the desired host. `wget
https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/puppet_agent.py
-O /etc/snmp/puppet_agent.py`
2: Make the script executable: `chmod +x /etc/snmp/puppet_agent.py`
3: Edit your snmpd.conf file (usually `/etc/snmp/snmpd.conf`) and add:
```
extend puppet-agent /etc/snmp/puppet_agent.py
```
The Script needs `python3-yaml` package to be installed.
Per default script searches for on of this files:
* /var/cache/puppet/state/last_run_summary.yaml
* /opt/puppetlabs/puppet/cache/state/last_run_summary.yaml
optionally you can add a specific summary file with creating `/etc/snmp/puppet.json`
```
{
"agent": {
"summary_file": "/my/custom/path/to/summary_file"
}
}
```
custom summary file has highest priority
4: Restart snmpd on the host
# PureFTPd
SNMP extend script to monitor PureFTPd.
@@ -1468,9 +1506,9 @@ 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
you will also need to create a config file, which is named
pureftpd.json . The file has to be located in /etc/snmp/.
pureftpd.json. The file has to be located in /etc/snmp/.
```

View File

@@ -0,0 +1,27 @@
<?php
$unitlen = 10;
$bigdescrlen = 9;
$smalldescrlen = 9;
$dostack = 0;
$printtotal = 0;
$unit_text = 'Changes';
$colours = 'psychedelic';
$rrd_list = array();
$rrd_filename = rrd_name($device['hostname'], array('app', 'puppet-agent', $app['app_id'], 'changes'));
$array = array(
'total',
);
if (rrdtool_check_rrd_exists($rrd_filename)) {
foreach ($array as $ds) {
$rrd_list[]=array(
'filename' => $rrd_filename,
'descr' => $ds,
'ds' => $ds,
);
}
} else {
echo "file missing: $file";
}
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';

View File

@@ -0,0 +1,29 @@
<?php
$unitlen = 10;
$bigdescrlen = 9;
$smalldescrlen = 9;
$dostack = 0;
$printtotal = 0;
$unit_text = 'Events';
$colours = 'psychedelic';
$rrd_list = array();
$rrd_filename = rrd_name($device['hostname'], array('app', 'puppet-agent', $app['app_id'], 'events'));
$array = array(
'success',
'failure',
'total',
);
if (rrdtool_check_rrd_exists($rrd_filename)) {
foreach ($array as $ds) {
$rrd_list[]=array(
'filename' => $rrd_filename,
'descr' => $ds,
'ds' => $ds,
);
}
} else {
echo "file missing: $file";
}
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';

View File

@@ -0,0 +1,27 @@
<?php
$unitlen = 10;
$bigdescrlen = 9;
$smalldescrlen = 9;
$dostack = 0;
$printtotal = 0;
$unit_text = 'Minutes';
$colours = 'psychedelic';
$rrd_list = array();
$rrd_filename = rrd_name($device['hostname'], array('app', 'puppet-agent', $app['app_id'], 'last_run'));
$array = array(
'last_run',
);
if (rrdtool_check_rrd_exists($rrd_filename)) {
foreach ($array as $ds) {
$rrd_list[]=array(
'filename' => $rrd_filename,
'descr' => $ds,
'ds' => $ds,
);
}
} else {
echo "file missing: $file";
}
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';

View File

@@ -0,0 +1,35 @@
<?php
$unitlen = 10;
$bigdescrlen = 20;
$smalldescrlen = 20;
$dostack = 0;
$printtotal = 0;
$unit_text = 'Resources';
$colours = 'psychedelic';
$rrd_list = array();
$rrd_filename = rrd_name($device['hostname'], array('app', 'puppet-agent', $app['app_id'], 'resources'));
$array = array(
'changed',
'corrective_change',
'failed',
'failed_to_restart',
'out_of_sync',
'restarted',
'scheduled',
'skipped',
'total',
);
if (rrdtool_check_rrd_exists($rrd_filename)) {
foreach ($array as $ds) {
$rrd_list[]=array(
'filename' => $rrd_filename,
'descr' => $ds,
'ds' => $ds,
);
}
} else {
echo "file missing: $file";
}
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';

View File

@@ -0,0 +1,35 @@
<?php
$unitlen = 15;
$bigdescrlen = 20;
$smalldescrlen = 20;
$dostack = 0;
$printtotal = 0;
$unit_text = 'Runtime/sec';
$colours = 'psychedelic';
$rrd_list = array();
$rrd_filename = rrd_name($device['hostname'], array('app', 'puppet-agent', $app['app_id'], 'time'));
$array = array(
'catalog_application',
'config_restrieval',
'convert_catalog',
'fact_generation',
'node_retrieval',
'plugin_sync',
'schedule',
'transaction_evaluation',
'total',
);
if (rrdtool_check_rrd_exists($rrd_filename)) {
foreach ($array as $ds) {
$rrd_list[]=array(
'filename' => $rrd_filename,
'descr' => $ds,
'ds' => $ds,
);
}
} else {
echo "file missing: $file";
}
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';

View File

@@ -250,6 +250,13 @@ $graphs['certificate'] = array(
'age',
'remaining_days',
);
$graphs['puppet-agent'] = array(
'last_run',
'changes',
'events',
'resources',
'time',
);
$graphs['mdadm'] = array(
'level',
'size',

View File

@@ -0,0 +1,29 @@
<?php
$graphs = array(
'puppet-agent_last_run' => 'Last run',
'puppet-agent_changes' => 'Changes',
'puppet-agent_events' => 'Events',
'puppet-agent_resources' => 'Resources',
'puppet-agent_time' => 'Runtime',
);
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

@@ -13,6 +13,7 @@ echo('
<div class="col-md-6">
');
require 'includes/html/dev-overview-data.inc.php';
require 'overview/puppet_agent.inc.php';
require 'overview/tracepath.inc.php';
echo LibreNMS\Plugins::call('device_overview_container', [$device]);

View File

@@ -0,0 +1,106 @@
<?php
use LibreNMS\Util\StringHelpers;
$app_id = \App\Models\Application::query()->where('device_id', $device['device_id'])->where('app_type', 'puppet-agent')->get('app_id')[0];
// show only if Puppet Agent Application discovered
if (count($app_id)) {
$params = [];
$sql = "SELECT `metric`, `value` FROM `application_metrics` WHERE `app_id` =" . $app_id['app_id'];
$metrics = dbFetchKeyValue($sql, $params);
?><div class='row'>
<div class='col-md-12'>
<div class='panel panel-default panel-condensed device-overview'>
<div class='panel-heading'>
<a href="device/device=<?php echo $device['device_id']?>/tab=apps/app=puppet-agent/">
<i class="fa fa-cogs fa-lg icon-theme" aria-hidden="true"></i>
<strong>Puppet Agent</strong>
</a>
</div>
<div class="panel-body">
<?php
$graph_array = array();
$graph_array['height'] = '100';
$graph_array['width'] = '210';
$graph_array['to'] = \LibreNMS\Config::get('time.now');
$graph_array['id'] = $app_id['app_id'];
$graph_array['from'] = \LibreNMS\Config::get('time.day');
$graph_array['legend'] = 'no';
// graph last run
$title_last_run = 'Last run';
$graph_array_last_run = $graph_array;
$graph_array_last_run['type'] = 'application_puppet-agent_last_run';
$link_array_last_run = $graph_array_last_run;
$link_array_last_run['page'] = 'graphs';
unset($link_array_last_run['height'], $link_array_last_run['width'], $link_array_last_run['legend']);
$link_last_run = generate_url($link_array_last_run);
$overlib_content_last_run = generate_overlib_content($graph_array_last_run, $device['hostname'].' - '. $title_last_run);
$overlib_link_last_run = overlib_link($link_last_run, 'Last run', $overlib_content_last_run);
// graph runtime
$title_runtime = 'Runtime';
$graph_array_runtime = $graph_array;
$graph_array_runtime['type'] = 'application_puppet-agent_time';
$link_array_runtime = $graph_array_runtime;
$link_array_runtime['page'] = 'graphs';
unset($link_array_runtime['height'], $link_array_runtime['width'], $link_array_runtime['legend']);
$link_runtime = generate_url($link_array_runtime);
$overlib_content_runtime = generate_overlib_content($graph_array_runtime, $device['hostname'].' - '. $title_runtime);
$overlib_link_runtime = overlib_link($link_runtime, $title_runtime, $overlib_content_runtime);
// graph resources
$title_resources = 'Resources';
$graph_array_resources = $graph_array;
$graph_array_resources['type'] = 'application_puppet-agent_resources';
$link_array_resources = $graph_array_resources;
$link_array_resources['page'] = 'graphs';
unset($link_array_resources['height'], $link_array_resources['width'], $link_array_resources['legend']);
$link_resources = generate_url($link_array_resources);
$overlib_content_resources = generate_overlib_content($graph_array_resources, $device['hostname'].' - '. $title_resources);
$overlib_link_resources = overlib_link($link_resources, $title_resources, $overlib_content_resources);
// graph events
$title_events = 'Change Events';
$graph_array_events = $graph_array;
$graph_array_events['type'] = 'application_puppet-agent_events';
$link_array_events = $graph_array_events;
$link_array_events['page'] = 'graphs';
unset($link_array_events['height'], $link_array_events['width'], $link_array_events['legend']);
$link_events = generate_url($link_array_events);
$overlib_content_events = generate_overlib_content($graph_array_events, $device['hostname'].' - '. $title_events);
$overlib_link_events = overlib_link($link_events, $title_events, $overlib_content_events);
echo '<div class="row">
<div class="col-sm-4">Summary</div>
<div class="col-sm-8">
<table width=100%><tr>
<td><span>'.$overlib_link_last_run.': '.$metrics['last_run_last_run'].'min</span></td>
<td><span>'.$overlib_link_runtime.': '.$metrics['time_total'].'s</span></td>
<td><span>'.$overlib_link_resources.': '.$metrics['resources_total'].'</span></td>
</tr></table>
</div>
<div class="col-sm-4">'.$overlib_link_events.'</div>
<div class="col-sm-8">
<table width=100%><tr>
<td><span ' . ($metrics['events_success']?'class="blue"':''). '>Success: '.$metrics['events_success'].'</span></td>
<td><span ' . ($metrics['events_failure']?'class="red"':'').'>Failure: '.$metrics['events_failure'].'</span></td>
<td><span>Total: '.$metrics['events_total'].'</span></td>
</tr></table>
</div>
</div>
</div>
</div>
</div>
</div>';
}

View File

@@ -0,0 +1,139 @@
<?php
use LibreNMS\Exceptions\JsonAppMissingKeysException;
use LibreNMS\Exceptions\JsonAppException;
use LibreNMS\RRD\RrdDefinition;
$name = 'puppet-agent';
$app_id = $app['app_id'];
$output = 'OK';
try {
$puppet_agent_data = json_app_get($device, $name, 1)['data'];
} catch (JsonAppMissingKeysException $e) {
$puppet_agent_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;
}
$puppet_changes = $puppet_agent_data['changes'];
$puppet_events = $puppet_agent_data['events'];
$puppet_resources = $puppet_agent_data['resources'];
$puppet_time = $puppet_agent_data['time'];
$metrics = array();
//
// Changes Processing
//
$rrd_name = array('app', $name, $app_id, 'changes');
$rrd_def = RrdDefinition::make()
->addDataset('total', 'GAUGE', 0);
$fields = array(
'total' => $puppet_changes['total'],
);
$metrics['changes'] = $fields;
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
//
// Events Processing
//
$rrd_name = array('app', $name, $app_id, 'events');
$rrd_def = RrdDefinition::make()
->addDataset('success', 'GAUGE', 0)
->addDataset('failure', 'GAUGE', 0)
->addDataset('total', 'GAUGE', 0);
$fields = array(
'success' => $puppet_events['success'],
'failure' => $puppet_events['failure'],
'total' => $puppet_events['total'],
);
$metrics['events'] = $fields;
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
//
// Resources Processing
//
$rrd_name = array('app', $name, $app_id, 'resources');
$rrd_def = RrdDefinition::make()
->addDataset('changed', 'GAUGE', 0)
->addDataset('corrective_change', 'GAUGE', 0)
->addDataset('failed', 'GAUGE', 0)
->addDataset('failed_to_restart', 'GAUGE', 0)
->addDataset('out_of_sync', 'GAUGE', 0)
->addDataset('restarted', 'GAUGE', 0)
->addDataset('scheduled', 'GAUGE', 0)
->addDataset('skipped', 'GAUGE', 0)
->addDataset('total', 'GAUGE', 0);
$fields = array(
'changed' => $puppet_resources['changed'],
'corrective_change' => $puppet_resources['corrective_change'],
'failed' => $puppet_resources['failed'],
'failed_to_restart' => $puppet_resources['failed_to_restart'],
'out_of_sync' => $puppet_resources['out_of_sync'],
'restarted' => $puppet_resources['restarted'],
'scheduled' => $puppet_resources['scheduled'],
'skipped' => $puppet_resources['skipped'],
'total' => $puppet_resources['total'],
);
$metrics['resources'] = $fields;
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
//
// Time Processing
//
$rrd_name = array('app', $name, $app_id, 'time');
$rrd_def = RrdDefinition::make()
->addDataset('catalog_application', 'GAUGE', 0)
->addDataset('config_restrieval', 'GAUGE', 0)
->addDataset('convert_catalog', 'GAUGE', 0)
->addDataset('fact_generation', 'GAUGE', 0)
->addDataset('node_retrieval', 'GAUGE', 0)
->addDataset('plugin_sync', 'GAUGE', 0)
->addDataset('schedule', 'GAUGE', 0)
->addDataset('transaction_evaluation', 'GAUGE', 0)
->addDataset('total', 'GAUGE', 0);
$fields = array(
'catalog_application' => $puppet_time['catalog_application'],
'config_retrieval' => $puppet_time['config_retrieval'],
'convert_catalog' => $puppet_time['convert_catalog'],
'fact_generation' => $puppet_time['fact_generation'],
'node_retrieval' => $puppet_time['node_retrieval'],
'plugin_sync' => $puppet_time['plugin_sync'],
'schedule' => $puppet_time['schedule'],
'transaction_evaluation' => $puppet_time['transaction_evaluation'],
'total' => $puppet_time['total'],
);
$metrics['time'] = $fields;
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
//
// Last Rung Processing
//
$rrd_name = array('app', $name, $app_id, 'last_run');
$rrd_def = RrdDefinition::make()
->addDataset('last_run', 'GAUGE', 0);
$fields = array(
'last_run' => round(intval($puppet_time['last_run'])/60, 0), # diff seconds to minutes
);
$metrics['last_run'] = $fields;
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
update_application($app, $output, $metrics);