mirror of https://github.com/Icinga/icinga2.git
Add severity
This commit is contained in:
parent
57b9fc94c3
commit
037357aea5
|
@ -39,23 +39,6 @@ enum CheckableType
|
|||
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 EventCommand;
|
||||
class Dependency;
|
||||
|
|
|
@ -164,32 +164,39 @@ HostState Host::GetLastHardState() const
|
|||
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 severity = 0;
|
||||
|
||||
ObjectLock olock(this);
|
||||
ServiceState state = GetStateRaw();
|
||||
HostState state = GetState();
|
||||
|
||||
/* OK/Warning = Up, Critical/Unknownb = Down */
|
||||
if (!HasBeenChecked())
|
||||
severity |= SeverityFlagPending;
|
||||
else if (state == ServiceUnknown)
|
||||
severity |= SeverityFlagCritical;
|
||||
else if (state == ServiceCritical)
|
||||
severity |= SeverityFlagCritical;
|
||||
if (!HasBeenChecked()) {
|
||||
severity = 16;
|
||||
} else if (state == HostUp) {
|
||||
severity = 0;
|
||||
} else {
|
||||
if (IsReachable())
|
||||
severity = 64;
|
||||
else
|
||||
severity = 32;
|
||||
|
||||
if (IsInDowntime())
|
||||
severity |= SeverityFlagDowntime;
|
||||
else if (IsAcknowledged())
|
||||
severity |= SeverityFlagAcknowledgement;
|
||||
else
|
||||
severity |= SeverityFlagUnhandled;
|
||||
if (IsAcknowledged())
|
||||
severity += 512;
|
||||
else if (IsInDowntime())
|
||||
severity += 256;
|
||||
else
|
||||
severity += 2048;
|
||||
}
|
||||
|
||||
olock.Unlock();
|
||||
|
||||
return severity;
|
||||
|
||||
}
|
||||
|
||||
bool Host::IsStateOK(ServiceState state) const
|
||||
|
|
|
@ -103,32 +103,50 @@ Host::Ptr Service::GetHost() const
|
|||
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 severity = 0;
|
||||
int severity;
|
||||
|
||||
ObjectLock olock(this);
|
||||
ServiceState state = GetStateRaw();
|
||||
|
||||
if (!HasBeenChecked())
|
||||
severity |= SeverityFlagPending;
|
||||
else if (state == ServiceWarning)
|
||||
severity |= SeverityFlagWarning;
|
||||
else if (state == ServiceUnknown)
|
||||
severity |= SeverityFlagUnknown;
|
||||
else if (state == ServiceCritical)
|
||||
severity |= SeverityFlagCritical;
|
||||
if (!HasBeenChecked()) {
|
||||
severity = 16;
|
||||
} else if (state == ServiceOK) {
|
||||
severity = 0;
|
||||
} else {
|
||||
switch (state) {
|
||||
case ServiceWarning:
|
||||
severity = 32;
|
||||
break;
|
||||
case ServiceUnknown:
|
||||
severity = 64;
|
||||
break;
|
||||
case ServiceCritical:
|
||||
severity = 128;
|
||||
break;
|
||||
default:
|
||||
severity = 256;
|
||||
}
|
||||
|
||||
/* TODO: Add host reachability and handled */
|
||||
if (IsInDowntime())
|
||||
severity |= SeverityFlagDowntime;
|
||||
else if (IsAcknowledged())
|
||||
severity |= SeverityFlagAcknowledgement;
|
||||
else if (m_Host && m_Host->GetProblem())
|
||||
severity |= SeverityFlagHostDown;
|
||||
else
|
||||
severity |= SeverityFlagUnhandled;
|
||||
Host::Ptr host = GetHost();
|
||||
ObjectLock hlock (host);
|
||||
if (host->GetState() != HostUp || !host->IsReachable()) {
|
||||
severity += 1024;
|
||||
} else {
|
||||
if (IsAcknowledged())
|
||||
severity += 512;
|
||||
else if (IsInDowntime())
|
||||
severity += 256;
|
||||
else
|
||||
severity += 2048;
|
||||
}
|
||||
hlock.Unlock();
|
||||
}
|
||||
|
||||
olock.Unlock();
|
||||
|
||||
|
|
|
@ -737,17 +737,18 @@ Dictionary::Ptr RedisWriter::SerializeState(const Checkable::Ptr& checkable)
|
|||
attrs->Set("state", service->GetState());
|
||||
attrs->Set("last_soft_state", service->GetState());
|
||||
attrs->Set("last_hard_state", service->GetLastHardState());
|
||||
attrs->Set("severity", service->GetSeverity());
|
||||
} else {
|
||||
attrs->Set("state", host->GetState());
|
||||
attrs->Set("last_soft_state", host->GetState());
|
||||
attrs->Set("last_hard_state", host->GetLastHardState());
|
||||
attrs->Set("severity", host->GetSeverity());
|
||||
}
|
||||
|
||||
attrs->Set("check_attempt", checkable->GetCheckAttempt());
|
||||
|
||||
//attrs->Set("severity")
|
||||
//attrs->Set(checkable->GetSeverity());
|
||||
|
||||
attrs->Set("is_active", checkable->IsActive());
|
||||
|
||||
CheckResult::Ptr cr = checkable->GetLastCheckResult();
|
||||
|
||||
if (cr) {
|
||||
|
|
|
@ -50,7 +50,6 @@ String RedisWriter::FormatCheckSumBinary(const String& str)
|
|||
return output;
|
||||
}
|
||||
|
||||
|
||||
String RedisWriter::FormatCommandLine(const Value& commandLine)
|
||||
{
|
||||
String result;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "base/workqueue.hpp"
|
||||
#include "redis/redisconnection.hpp"
|
||||
#include "icinga/checkable.hpp"
|
||||
#include "icinga/service.hpp"
|
||||
#include "icinga/downtime.hpp"
|
||||
#include <hiredis/hiredis.h>
|
||||
|
||||
|
|
Loading…
Reference in New Issue