Skip to content

Commit

Permalink
Merge pull request #1273 from it-novum/ITC-2645
Browse files Browse the repository at this point in the history
ITC-2645 Use Statusengine to process Agent check results
  • Loading branch information
ibering authored Nov 12, 2021
2 parents 74f0ad1 + 0022b78 commit 2917cea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/Controller/AgentconnectorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,10 @@ public function submit_checkdata() {
try {
$config = $CheckConfig->getConfigByHostName($hostUuid);

$results = [
'Messages' => []
];

foreach ($config['checks'] as $pluginConfig) {
$pluginName = $pluginConfig['plugin'];

Expand All @@ -1138,20 +1142,31 @@ public function submit_checkdata() {
$pluginOutput .= '|' . $Plugin->getPerfdataSerialized();
}

$GearmanClient->sendBackground('cmd_external_command', [
'command' => 'PROCESS_SERVICE_CHECK_RESULT',
'parameters' => [
'hostUuid' => $hostUuid,
'serviceUuid' => $pluginConfig['uuid'],
'status_code' => $Plugin->getStatuscode(),
'plugin_output' => $pluginOutput,
'long_output' => $Plugin->getLongOutput()
],
'satelliteId' => 0 // Agent check results are always Master system!,
]);
// Create bulk message for Statusengine Broker
$results['messages'][] = [
'Command' => 'check_result',
'Data' => [
'host_name' => $hostUuid,
'service_description' => $pluginConfig['uuid'],
'output' => $pluginOutput,
'long_output' => ($Plugin->getLongOutput() === '' ? null : $Plugin->getLongOutput()),
'check_type' => 1, //https://github.com/naemon/naemon-core/blob/cec6e10cbee9478de04b4cf5af29e83d47b5cfd9/src/naemon/common.h#L330-L334
'return_code' => $Plugin->getStatuscode(),
'start_time' => time(),
'end_time' => time(),
'early_timeout' => 0,
'latency' => 0,
'exited_ok' => 1
]
];

$receivedChecks++;
}

if (!empty($results['messages'])) {
$GearmanClient->toStatusnginCmdBackground($results);
}

} catch (\RuntimeException $e) {
// Host was not exported yet to Monitoring Engine and check receiver - just save the check result to the database
// and ignore the error
Expand Down
8 changes: 8 additions & 0 deletions src/itnovum/openITCOCKPIT/Core/System/Gearman.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,12 @@ public function ping() {
return $result;
}

/**
* @param array $payload
* @return string
*/
public function toStatusnginCmdBackground(array $payload) {
return $this->client->doBackground('statusngin_cmd', json_encode($payload));
}

}

0 comments on commit 2917cea

Please sign in to comment.