mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 23:34:08 +02:00
monitoring: Provide health hook
This commit is contained in:
parent
0d2bf1ae33
commit
84949f214e
@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2021 Icinga GmbH | GPLv2+ */
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\ProvidedHook;
|
||||||
|
|
||||||
|
use Icinga\Application\Hook\HealthHook;
|
||||||
|
use Icinga\Date\DateFormatter;
|
||||||
|
use Icinga\Module\Monitoring\Backend;
|
||||||
|
use ipl\Web\Url;
|
||||||
|
|
||||||
|
class Health extends HealthHook
|
||||||
|
{
|
||||||
|
/** @var object */
|
||||||
|
protected $programStatus;
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return 'Icinga';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUrl()
|
||||||
|
{
|
||||||
|
return Url::fromPath('monitoring/health/info');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkHealth()
|
||||||
|
{
|
||||||
|
$backendName = Backend::instance()->getName();
|
||||||
|
$programStatus = $this->getProgramStatus();
|
||||||
|
if ($programStatus === false) {
|
||||||
|
$this->setState(self::STATE_UNKNOWN);
|
||||||
|
$this->setMessage(sprintf(t('%s is currently not up and running'), $backendName));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($programStatus->is_currently_running) {
|
||||||
|
$this->setState(self::STATE_OK);
|
||||||
|
$this->setMessage(sprintf(
|
||||||
|
t(
|
||||||
|
'%1$s has been up and running with PID %2$d %3$s',
|
||||||
|
'Last format parameter represents the time running'
|
||||||
|
),
|
||||||
|
$backendName,
|
||||||
|
$programStatus->process_id,
|
||||||
|
DateFormatter::timeSince($programStatus->program_start_time)
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
$this->setState(self::STATE_CRITICAL);
|
||||||
|
$this->setMessage(sprintf(t('Backend %s is not running'), $backendName));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setMetrics((array) $programStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getProgramStatus()
|
||||||
|
{
|
||||||
|
if ($this->programStatus === null) {
|
||||||
|
$this->programStatus = Backend::instance()->select()
|
||||||
|
->from('programstatus', [
|
||||||
|
'program_version',
|
||||||
|
'status_update_time',
|
||||||
|
'program_start_time',
|
||||||
|
'program_end_time',
|
||||||
|
'endpoint_name',
|
||||||
|
'is_currently_running',
|
||||||
|
'process_id',
|
||||||
|
'last_command_check',
|
||||||
|
'last_log_rotation',
|
||||||
|
'notifications_enabled',
|
||||||
|
'active_service_checks_enabled',
|
||||||
|
'active_host_checks_enabled',
|
||||||
|
'event_handlers_enabled',
|
||||||
|
'flap_detection_enabled',
|
||||||
|
'process_performance_data'
|
||||||
|
])
|
||||||
|
->fetchRow();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->programStatus;
|
||||||
|
}
|
||||||
|
}
|
@ -4,4 +4,5 @@
|
|||||||
/** @var $this \Icinga\Application\Modules\Module */
|
/** @var $this \Icinga\Application\Modules\Module */
|
||||||
|
|
||||||
$this->provideHook('ApplicationState');
|
$this->provideHook('ApplicationState');
|
||||||
|
$this->provideHook('Health');
|
||||||
$this->provideHook('X509/Sni');
|
$this->provideHook('X509/Sni');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user