mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
Introduce hook RedisHealth
This commit is contained in:
parent
7a7ecd22e9
commit
54a1b20aea
2 changed files with 52 additions and 0 deletions
51
library/Icingadb/ProvidedHook/RedisHealth.php
Normal file
51
library/Icingadb/ProvidedHook/RedisHealth.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
// Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2
|
||||
|
||||
namespace Icinga\Module\Icingadb\ProvidedHook;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Application\Hook\HealthHook;
|
||||
use Icinga\Module\Icingadb\Common\Database;
|
||||
use Icinga\Module\Icingadb\Common\IcingaRedis;
|
||||
use Icinga\Module\Icingadb\Model\Instance;
|
||||
|
||||
class RedisHealth extends HealthHook
|
||||
{
|
||||
use Database;
|
||||
use IcingaRedis;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'Icinga Redis';
|
||||
}
|
||||
|
||||
public function checkHealth()
|
||||
{
|
||||
try {
|
||||
$redis = $this->getIcingaRedis();
|
||||
|
||||
$lastIcingaHeartbeat = $this->getLastIcingaHeartbeat($redis);
|
||||
if ($lastIcingaHeartbeat === false) {
|
||||
$this->setState(self::STATE_UNKNOWN);
|
||||
$this->setMessage(t("Can't connect to Icinga Redis: phpredis>=4.3.0 required"));
|
||||
return;
|
||||
} elseif ($lastIcingaHeartbeat === null) {
|
||||
$lastIcingaHeartbeat = time();
|
||||
}
|
||||
|
||||
$instance = Instance::on($this->getDb())->columns('heartbeat')->first();
|
||||
$outdatedDbHeartbeat = $instance->heartbeat < time() - 60;
|
||||
if (! $outdatedDbHeartbeat || $instance->heartbeat <= $lastIcingaHeartbeat) {
|
||||
$this->setState(self::STATE_OK);
|
||||
$this->setMessage(t('Icinga Redis available and up to date.'));
|
||||
} elseif ($instance->heartbeat > $lastIcingaHeartbeat) {
|
||||
$this->setState(self::STATE_CRITICAL);
|
||||
$this->setMessage(t('Icinga Redis outdated. Make sure Icinga 2 is running and connected to Redis.'));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->setState(self::STATE_UNKNOWN);
|
||||
$this->setMessage(sprintf(t("Can't connect to Icinga Redis: %s"), $e->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
1
run.php
1
run.php
|
|
@ -7,3 +7,4 @@
|
|||
$this->provideHook('ApplicationState');
|
||||
$this->provideHook('X509/Sni');
|
||||
$this->provideHook('health', 'IcingaHealth');
|
||||
$this->provideHook('health', 'RedisHealth');
|
||||
|
|
|
|||
Loading…
Reference in a new issue