mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 22:54:57 +02:00
Add severity
This commit is contained in:
parent
57b9fc94c3
commit
037357aea5
@ -39,23 +39,6 @@ enum CheckableType
|
|||||||
CheckableService
|
CheckableService
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Severity Flags
|
|
||||||
*
|
|
||||||
* @ingroup icinga
|
|
||||||
*/
|
|
||||||
enum SeverityFlag
|
|
||||||
{
|
|
||||||
SeverityFlagDowntime = 1,
|
|
||||||
SeverityFlagAcknowledgement = 2,
|
|
||||||
SeverityFlagHostDown = 4,
|
|
||||||
SeverityFlagUnhandled = 8,
|
|
||||||
SeverityFlagPending = 16,
|
|
||||||
SeverityFlagWarning = 32,
|
|
||||||
SeverityFlagUnknown = 64,
|
|
||||||
SeverityFlagCritical = 128,
|
|
||||||
};
|
|
||||||
|
|
||||||
class CheckCommand;
|
class CheckCommand;
|
||||||
class EventCommand;
|
class EventCommand;
|
||||||
class Dependency;
|
class Dependency;
|
||||||
|
@ -164,32 +164,39 @@ HostState Host::GetLastHardState() const
|
|||||||
return CalculateState(GetLastHardStateRaw());
|
return CalculateState(GetLastHardStateRaw());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* keep in sync with Service::GetSeverity() */
|
/* keep in sync with Service::GetSeverity()
|
||||||
|
* One could think it may be smart to use an enum and some bitmask math here.
|
||||||
|
* But the only thing the consuming icingaweb2 cares about is being able to
|
||||||
|
* sort by severity. It is therefore easier to keep them seperated here. */
|
||||||
int Host::GetSeverity() const
|
int Host::GetSeverity() const
|
||||||
{
|
{
|
||||||
int severity = 0;
|
int severity = 0;
|
||||||
|
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
ServiceState state = GetStateRaw();
|
HostState state = GetState();
|
||||||
|
|
||||||
/* OK/Warning = Up, Critical/Unknownb = Down */
|
if (!HasBeenChecked()) {
|
||||||
if (!HasBeenChecked())
|
severity = 16;
|
||||||
severity |= SeverityFlagPending;
|
} else if (state == HostUp) {
|
||||||
else if (state == ServiceUnknown)
|
severity = 0;
|
||||||
severity |= SeverityFlagCritical;
|
} else {
|
||||||
else if (state == ServiceCritical)
|
if (IsReachable())
|
||||||
severity |= SeverityFlagCritical;
|
severity = 64;
|
||||||
|
else
|
||||||
|
severity = 32;
|
||||||
|
|
||||||
if (IsInDowntime())
|
if (IsAcknowledged())
|
||||||
severity |= SeverityFlagDowntime;
|
severity += 512;
|
||||||
else if (IsAcknowledged())
|
else if (IsInDowntime())
|
||||||
severity |= SeverityFlagAcknowledgement;
|
severity += 256;
|
||||||
else
|
else
|
||||||
severity |= SeverityFlagUnhandled;
|
severity += 2048;
|
||||||
|
}
|
||||||
|
|
||||||
olock.Unlock();
|
olock.Unlock();
|
||||||
|
|
||||||
return severity;
|
return severity;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Host::IsStateOK(ServiceState state) const
|
bool Host::IsStateOK(ServiceState state) const
|
||||||
|
@ -103,32 +103,50 @@ Host::Ptr Service::GetHost() const
|
|||||||
return m_Host;
|
return m_Host;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* keep in sync with Host::GetSeverity() */
|
/* keep in sync with Host::GetSeverity()
|
||||||
|
* One could think it may be smart to use an enum and some bitmask math here.
|
||||||
|
* But the only thing the consuming icingaweb2 cares about is being able to
|
||||||
|
* sort by severity. It is therefore easier to keep them seperated here. */
|
||||||
int Service::GetSeverity() const
|
int Service::GetSeverity() const
|
||||||
{
|
{
|
||||||
int severity = 0;
|
int severity;
|
||||||
|
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
ServiceState state = GetStateRaw();
|
ServiceState state = GetStateRaw();
|
||||||
|
|
||||||
if (!HasBeenChecked())
|
if (!HasBeenChecked()) {
|
||||||
severity |= SeverityFlagPending;
|
severity = 16;
|
||||||
else if (state == ServiceWarning)
|
} else if (state == ServiceOK) {
|
||||||
severity |= SeverityFlagWarning;
|
severity = 0;
|
||||||
else if (state == ServiceUnknown)
|
} else {
|
||||||
severity |= SeverityFlagUnknown;
|
switch (state) {
|
||||||
else if (state == ServiceCritical)
|
case ServiceWarning:
|
||||||
severity |= SeverityFlagCritical;
|
severity = 32;
|
||||||
|
break;
|
||||||
|
case ServiceUnknown:
|
||||||
|
severity = 64;
|
||||||
|
break;
|
||||||
|
case ServiceCritical:
|
||||||
|
severity = 128;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
severity = 256;
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: Add host reachability and handled */
|
Host::Ptr host = GetHost();
|
||||||
if (IsInDowntime())
|
ObjectLock hlock (host);
|
||||||
severity |= SeverityFlagDowntime;
|
if (host->GetState() != HostUp || !host->IsReachable()) {
|
||||||
else if (IsAcknowledged())
|
severity += 1024;
|
||||||
severity |= SeverityFlagAcknowledgement;
|
} else {
|
||||||
else if (m_Host && m_Host->GetProblem())
|
if (IsAcknowledged())
|
||||||
severity |= SeverityFlagHostDown;
|
severity += 512;
|
||||||
else
|
else if (IsInDowntime())
|
||||||
severity |= SeverityFlagUnhandled;
|
severity += 256;
|
||||||
|
else
|
||||||
|
severity += 2048;
|
||||||
|
}
|
||||||
|
hlock.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
olock.Unlock();
|
olock.Unlock();
|
||||||
|
|
||||||
|
@ -737,17 +737,18 @@ Dictionary::Ptr RedisWriter::SerializeState(const Checkable::Ptr& checkable)
|
|||||||
attrs->Set("state", service->GetState());
|
attrs->Set("state", service->GetState());
|
||||||
attrs->Set("last_soft_state", service->GetState());
|
attrs->Set("last_soft_state", service->GetState());
|
||||||
attrs->Set("last_hard_state", service->GetLastHardState());
|
attrs->Set("last_hard_state", service->GetLastHardState());
|
||||||
|
attrs->Set("severity", service->GetSeverity());
|
||||||
} else {
|
} else {
|
||||||
attrs->Set("state", host->GetState());
|
attrs->Set("state", host->GetState());
|
||||||
attrs->Set("last_soft_state", host->GetState());
|
attrs->Set("last_soft_state", host->GetState());
|
||||||
attrs->Set("last_hard_state", host->GetLastHardState());
|
attrs->Set("last_hard_state", host->GetLastHardState());
|
||||||
|
attrs->Set("severity", host->GetSeverity());
|
||||||
}
|
}
|
||||||
|
|
||||||
attrs->Set("check_attempt", checkable->GetCheckAttempt());
|
attrs->Set("check_attempt", checkable->GetCheckAttempt());
|
||||||
|
|
||||||
//attrs->Set("severity")
|
attrs->Set("is_active", checkable->IsActive());
|
||||||
//attrs->Set(checkable->GetSeverity());
|
|
||||||
|
|
||||||
CheckResult::Ptr cr = checkable->GetLastCheckResult();
|
CheckResult::Ptr cr = checkable->GetLastCheckResult();
|
||||||
|
|
||||||
if (cr) {
|
if (cr) {
|
||||||
|
@ -50,7 +50,6 @@ String RedisWriter::FormatCheckSumBinary(const String& str)
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String RedisWriter::FormatCommandLine(const Value& commandLine)
|
String RedisWriter::FormatCommandLine(const Value& commandLine)
|
||||||
{
|
{
|
||||||
String result;
|
String result;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "base/workqueue.hpp"
|
#include "base/workqueue.hpp"
|
||||||
#include "redis/redisconnection.hpp"
|
#include "redis/redisconnection.hpp"
|
||||||
#include "icinga/checkable.hpp"
|
#include "icinga/checkable.hpp"
|
||||||
|
#include "icinga/service.hpp"
|
||||||
#include "icinga/downtime.hpp"
|
#include "icinga/downtime.hpp"
|
||||||
#include <hiredis/hiredis.h>
|
#include <hiredis/hiredis.h>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user