Add support for windows librenms(check_mk) agent (#11691)

* Allow agent to run against windows os

* Display processes from windows check_mk agent

* Replace tabs with spaces

* Fix indent

* Add documentation for windows agent
This commit is contained in:
gardar
2020-05-26 14:04:38 +00:00
committed by GitHub
parent 46fa4eac03
commit 14193253fe
2 changed files with 35 additions and 2 deletions

View File

@@ -7,6 +7,10 @@ LibreNMS in combination with check_mk (found
extended to include data about [applications](Applications.md) on the
remote system.
# Installation
## Linux / BSD
Make sure that systemd or xinetd is installed on the host you want to
run the agent on.
@@ -68,3 +72,8 @@ monitor. Under the modules section, ensure that unix-agent is enabled.
10: Wait for around 10 minutes and you should start seeing data in
your graphs under Apps for the device.
## Windows
1. Grab version 1.2.6b5 of the check_mk agent from the check_mk github repo (exe/msi or compile it yourself depending on your usage): https://github.com/tribe29/checkmk/tree/v1.2.6b5/agents/windows
2. Run the msi / exe
3. Make sure your LibreNMS instance can reach TCP port 6556 on your target.

View File

@@ -3,7 +3,7 @@
use App\Models\Device;
use LibreNMS\RRD\RrdDefinition;
if ($device['os_group'] == 'unix') {
if ($device['os_group'] == 'unix' || $device['os'] == 'windows') {
echo \LibreNMS\Config::get('project_name') . ' UNIX Agent: ';
$agent_port = get_dev_attrib($device, 'override_Unixagent_port');
@@ -91,7 +91,7 @@ if ($device['os_group'] == 'unix') {
}
}
// Processes
// Unix Processes
if (!empty($agent_data['ps'])) {
echo 'Processes: ';
dbDelete('processes', 'device_id = ?', array($device['device_id']));
@@ -109,6 +109,30 @@ if ($device['os_group'] == 'unix') {
echo "\n";
}
// Windows Processes
if (!empty($agent_data['ps:sep(9)'])) {
echo 'Processes: ';
dbDelete('processes', 'device_id = ?', array($device['device_id']));
$data=array();
foreach (explode("\n", $agent_data['ps:sep(9)']) as $process) {
$process = preg_replace('/\((.*),([0-9]*),([0-9]*),([0-9]*),([0-9]*),([0-9]*),([0-9]*),([0-9]*),([0-9]*),([0-9]*)\)(.*)/', '\\1|\\2|\\3|\\4|\\5|\\6|\\7|\\8|\\9|\\10|\\11', $process);
list($user, $VirtualSize, $WorkingSetSize, $zero, $processId, $PageFileUsage, $UserModeTime, $KernelModeTime, $HandleCount, $ThreadCount, $process_name) = explode('|', $process, 11);
if (!empty($process_name)) {
$cputime = ($UserModeTime + $KernelModeTime) / 10000000;
$days = floor($cputime / 86400);
$hours = str_pad(floor(($cputime / 3600) % 24), 2, '0', STR_PAD_LEFT);
$minutes = str_pad(floor(($cputime / 60) % 60), 2, '0', STR_PAD_LEFT);
$seconds = str_pad(($cputime % 60), 2, '0', STR_PAD_LEFT);
$cputime = ($days > 0 ? "$days-" : '') . "$hours:$minutes:$seconds";
$data[]=array('device_id' => $device['device_id'], 'pid' => $processId, 'user' => $user, 'vsz' => $PageFileUsage + $WorkingSetSize, 'rss' => $WorkingSetSize, 'cputime' => $cputime, 'command' => $process_name);
}
}
if (count($data) > 0) {
dbBulkInsert($data, 'processes');
}
echo "\n";
}
foreach (array_keys($agent_data['app']) as $key) {
if (file_exists("includes/polling/applications/$key.inc.php")) {
d_echo("Enabling $key for ".$device['hostname']." if not yet enabled\n");