livestatus: add first part of host data providers

refs #4372
This commit is contained in:
Michael Friedrich 2013-07-05 09:35:49 +02:00
parent 1db349df18
commit 88197d216a
9 changed files with 1248 additions and 107 deletions

File diff suppressed because it is too large Load Diff

View File

@ -48,6 +48,115 @@ protected:
static Value NameAccessor(const Object::Ptr& object);
static Value DisplayNameAccessor(const Object::Ptr& object);
static Value AddressAccessor(const Object::Ptr& object);
static Value Address6Accessor(const Object::Ptr& object);
static Value CheckCommandAccessor(const Object::Ptr& object);
static Value CheckCommandExpandedAccessor(const Object::Ptr& object);
static Value EventHandlerAccessor(const Object::Ptr& object);
static Value NotificationPeriodAccessor(const Object::Ptr& object);
static Value CheckPeriodAccessor(const Object::Ptr& object);
static Value NotesAccessor(const Object::Ptr& object);
static Value NotesExpandedAccessor(const Object::Ptr& object);
static Value NotesUrlAccessor(const Object::Ptr& object);
static Value NotesUrlExpandedAccessor(const Object::Ptr& object);
static Value ActionUrlAccessor(const Object::Ptr& object);
static Value ActionUrlExpandedAccessor(const Object::Ptr& object);
static Value PluginOutputAccessor(const Object::Ptr& object);
static Value PerfDataAccessor(const Object::Ptr& object);
static Value IconImageAccessor(const Object::Ptr& object);
static Value IconImageExpandedAccessor(const Object::Ptr& object);
static Value IconImageAltAccessor(const Object::Ptr& object);
static Value StatusmapImageAccessor(const Object::Ptr& object);
static Value LongPluginOutputAccessor(const Object::Ptr& object);
static Value InitialStateAccessor(const Object::Ptr& object);
static Value MaxCheckAttemptsAccessor(const Object::Ptr& object);
static Value FlapDetectionEnabledAccessor(const Object::Ptr& object);
static Value CheckFreshnessAccessor(const Object::Ptr& object);
static Value ProcessPerformanceDataAccessor(const Object::Ptr& object);
static Value AcceptPassiveChecksAccessor(const Object::Ptr& object);
static Value EventHandlerEnabledAccessor(const Object::Ptr& object);
static Value AcknowledgementTypeAccessor(const Object::Ptr& object);
static Value CheckTypeAccessor(const Object::Ptr& object);
static Value LastStateAccessor(const Object::Ptr& object);
static Value LastHardStateAccessor(const Object::Ptr& object);
static Value CurrentAttemptAccessor(const Object::Ptr& object);
static Value LastNotificationAccessor(const Object::Ptr& object);
static Value NextNotificationAccessor(const Object::Ptr& object);
static Value NextCheckAccessor(const Object::Ptr& object);
static Value LastHardStateChangeAccessor(const Object::Ptr& object);
static Value HasBeenCheckedAccessor(const Object::Ptr& object);
static Value CurrentNotificationNumberAccessor(const Object::Ptr& object);
static Value PendingFlexDowntimeAccessor(const Object::Ptr& object);
static Value TotalServicesAccessor(const Object::Ptr& object);
static Value ChecksEnabledAccessor(const Object::Ptr& object);
static Value NotificationsEnabledAccessor(const Object::Ptr& object);
static Value AcknowledgedAccessor(const Object::Ptr& object);
static Value StateAccessor(const Object::Ptr& object);
static Value StateTypeAccessor(const Object::Ptr& object);
static Value NoMoreNotificationsAccessor(const Object::Ptr& object);
static Value CheckFlappingRecoveryNotificationAccessor(const Object::Ptr& object);
static Value LastCheckAccessor(const Object::Ptr& object);
static Value LastStateChangeAccessor(const Object::Ptr& object);
static Value LastTimeUpAccessor(const Object::Ptr& object);
static Value LastTimeDownAccessor(const Object::Ptr& object);
static Value LastTimeUnreachableAccessor(const Object::Ptr& object);
static Value IsFlappingAccessor(const Object::Ptr& object);
static Value ScheduledDowntimeDepthAccessor(const Object::Ptr& object);
static Value IsExecutingAccessor(const Object::Ptr& object);
static Value ActiveChecksEnabledAccessor(const Object::Ptr& object);
static Value CheckOptionsAccessor(const Object::Ptr& object);
static Value ObsessOverHostAccessor(const Object::Ptr& object);
static Value ModifiedAttributesAccessor(const Object::Ptr& object);
static Value ModifiedAttributesListAccessor(const Object::Ptr& object);
static Value CheckIntervalAccessor(const Object::Ptr& object);
static Value RetryIntervalAccessor(const Object::Ptr& object);
static Value NotificationIntervalAccessor(const Object::Ptr& object);
static Value FirstNotificationDelayAccessor(const Object::Ptr& object);
static Value LowFlapThresholdAccessor(const Object::Ptr& object);
static Value HighFlapThresholdAccessor(const Object::Ptr& object);
static Value X3dAccessor(const Object::Ptr& object);
static Value Y3dAccessor(const Object::Ptr& object);
static Value Z3dAccessor(const Object::Ptr& object);
static Value X2dAccessor(const Object::Ptr& object);
static Value Y2dAccessor(const Object::Ptr& object);
static Value LatencyAccessor(const Object::Ptr& object);
static Value ExecutionTimeAccessor(const Object::Ptr& object);
static Value PercentStateChangeAccessor(const Object::Ptr& object);
static Value InNotificationPeriodAccessor(const Object::Ptr& object);
static Value InCheckPeriodAccessor(const Object::Ptr& object);
static Value ContactsAccessor(const Object::Ptr& object);
static Value DowntimesAccessor(const Object::Ptr& object);
static Value DowntimesWithInfoAccessor(const Object::Ptr& object);
static Value CommentsAccessor(const Object::Ptr& object);
static Value CommentsWithInfoAccessor(const Object::Ptr& object);
static Value CommentsWithExtraInfoAccessor(const Object::Ptr& object);
static Value CustomVariableNamesAccessor(const Object::Ptr& object);
static Value CustomVariableValuesAccessor(const Object::Ptr& object);
static Value CustomVariablesAccessor(const Object::Ptr& object);
static Value FilenameAccessor(const Object::Ptr& object);
static Value ParentsAccessor(const Object::Ptr& object);
static Value ChildsAccessor(const Object::Ptr& object);
static Value NumServicesAccessor(const Object::Ptr& object);
static Value WorstServiceStateAccessor(const Object::Ptr& object);
static Value NumServicesOkAccessor(const Object::Ptr& object);
static Value NumServicesWarnAccessor(const Object::Ptr& object);
static Value NumServicesCritAccessor(const Object::Ptr& object);
static Value NumServicesUnknownAccessor(const Object::Ptr& object);
static Value NumServicesPendingAccessor(const Object::Ptr& object);
static Value WorstServiceHardStateAccessor(const Object::Ptr& object);
static Value NumServicesHardOkAccessor(const Object::Ptr& object);
static Value NumServicesHardWarnAccessor(const Object::Ptr& object);
static Value NumServicesHardCritAccessor(const Object::Ptr& object);
static Value NumServicesHardUnknownAccessor(const Object::Ptr& object);
static Value HardStateAccessor(const Object::Ptr& object);
static Value PnpgraphPresentAccessor(const Object::Ptr& object);
static Value StalenessAccessor(const Object::Ptr& object);
static Value GroupsAccessor(const Object::Ptr& object);
static Value ContactGroupsAccessor(const Object::Ptr& object);
static Value ServicesAccessor(const Object::Ptr& object);
static Value ServicesWithStateAccessor(const Object::Ptr& object);
static Value ServicesWithInfoAccessor(const Object::Ptr& object);
};
}

View File

@ -22,6 +22,7 @@
#include "livestatus/column.h"
#include "base/object.h"
#include "base/dictionary.h"
#include <vector>
namespace livestatus

View File

@ -20,6 +20,7 @@
#include "icinga/host.h"
#include "icinga/service.h"
#include "icinga/hostgroup.h"
#include "icinga/icingaapplication.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
@ -50,6 +51,7 @@ Host::Host(const Dictionary::Ptr& serializedUpdate)
RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
RegisterAttribute("hostgroups", Attribute_Config, &m_HostGroups);
RegisterAttribute("macros", Attribute_Config, &m_Macros);
RegisterAttribute("custom", Attribute_Config, &m_Custom);
RegisterAttribute("hostdependencies", Attribute_Config, &m_HostDependencies);
RegisterAttribute("servicedependencies", Attribute_Config, &m_ServiceDependencies);
RegisterAttribute("hostcheck", Attribute_Config, &m_HostCheck);
@ -103,6 +105,11 @@ Dictionary::Ptr Host::GetMacros(void) const
return m_Macros;
}
Dictionary::Ptr Host::GetCustom(void) const
{
return m_Custom;
}
Array::Ptr Host::GetHostDependencies(void) const
{
return m_HostDependencies;;
@ -303,6 +310,10 @@ std::set<Service::Ptr> Host::GetServices(void) const
return services;
}
int Host::GetTotalServices(void) const
{
return GetServices().size();
}
void Host::InvalidateServicesCache(void)
{
{
@ -494,6 +505,28 @@ HostState Host::CalculateState(ServiceState state, bool reachable)
}
}
HostState Host::GetState(void) const
{
ASSERT(!OwnsLock());
if (!IsReachable())
return HostUnreachable;
Service::Ptr hc = GetHostCheckService();
if (!hc)
return HostUp;
switch (hc->GetState()) {
case StateOK:
case StateWarning:
return HostUp;
default:
return HostDown;
}
}
HostState Host::GetLastState(void) const
{
ASSERT(!OwnsLock());
@ -515,6 +548,48 @@ HostState Host::GetLastState(void) const
}
}
HostState Host::GetLastHardState(void) const
{
ASSERT(!OwnsLock());
if (!IsReachable())
return HostUnreachable;
Service::Ptr hc = GetHostCheckService();
if (!hc)
return HostUp;
switch (hc->GetLastHardState()) {
case StateOK:
case StateWarning:
return HostUp;
default:
return HostDown;
}
}
double Host::GetLastStateChange(void) const
{
Service::Ptr hc = GetHostCheckService();
if (!hc)
return IcingaApplication::GetInstance()->GetStartTime();
return hc->GetLastStateChange();
}
double Host::GetLastHardStateChange(void) const
{
Service::Ptr hc = GetHostCheckService();
if (!hc)
return IcingaApplication::GetInstance()->GetStartTime();
return hc->GetLastHardStateChange();
}
StateType Host::GetLastStateType(void) const
{
Service::Ptr hc = GetHostCheckService();
@ -525,6 +600,46 @@ StateType Host::GetLastStateType(void) const
return hc->GetLastStateType();
}
StateType Host::GetStateType(void) const
{
Service::Ptr hc = GetHostCheckService();
if (!hc)
return StateTypeHard;
return hc->GetStateType();
}
double Host::GetLastCheck(void) const
{
Service::Ptr hc = GetHostCheckService();
if (!hc)
return -1;
return hc->GetLastCheck();
}
bool Host::IsFlapping(void) const
{
Service::Ptr hc = GetHostCheckService();
if (!hc)
return false;
return hc->IsFlapping();
}
int Host::GetDowntimeDepth() const
{
Service::Ptr hc = GetHostCheckService();
if (!hc)
return 0;
return hc->GetDowntimeDepth();
}
String Host::StateToString(HostState state)
{
switch (state) {

View File

@ -22,6 +22,7 @@
#include "icinga/i2-icinga.h"
#include "icinga/macroresolver.h"
//#include "base/i2-base.h"
#include "base/array.h"
#include "base/dynamicobject.h"
#include "base/dictionary.h"
@ -88,6 +89,7 @@ public:
Array::Ptr GetGroups(void) const;
Dictionary::Ptr GetMacros(void) const;
Dictionary::Ptr GetCustom(void) const;
Array::Ptr GetHostDependencies(void) const;
Array::Ptr GetServiceDependencies(void) const;
String GetHostCheck(void) const;
@ -101,19 +103,33 @@ public:
shared_ptr<Service> GetServiceByShortName(const Value& name) const;
std::set<shared_ptr<Service> > GetServices(void) const;
int GetTotalServices(void) const;
static void InvalidateServicesCache(void);
static Value ValidateServiceDictionary(const String& location, const Dictionary::Ptr& attrs);
static HostState CalculateState(ServiceState state, bool reachable);
HostState GetState(void) const;
StateType GetStateType(void) const;
HostState GetLastState(void) const;
HostState GetLastHardState(void) const;
StateType GetLastStateType(void) const;
double GetLastStateChange(void) const;
double GetLastHardStateChange(void) const;
bool IsFlapping(void) const;
static String StateToString(HostState state);
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
/* Virtual Checks */
double GetLastCheck(void) const;
/* Virtual Downtime */
int GetDowntimeDepth(void) const;
protected:
virtual void OnRegistrationCompleted(void);
virtual void OnAttributeChanged(const String& name);
@ -122,6 +138,7 @@ private:
Attribute<String> m_DisplayName;
Attribute<Array::Ptr> m_HostGroups;
Attribute<Dictionary::Ptr> m_Macros;
Attribute<Dictionary::Ptr> m_Custom;
Attribute<Array::Ptr> m_HostDependencies;
Attribute<Array::Ptr> m_ServiceDependencies;
Attribute<String> m_HostCheck;

View File

@ -178,6 +178,22 @@ ServiceState Service::GetLastState(void) const
return static_cast<ServiceState>(ivalue);
}
void Service::SetLastHardState(ServiceState state)
{
m_LastHardState = static_cast<long>(state);
Touch("last_hard_state");
}
ServiceState Service::GetLastHardState(void) const
{
if (m_LastHardState.IsEmpty())
return StateUnknown;
int ivalue = static_cast<int>(m_LastHardState);
return static_cast<ServiceState>(ivalue);
}
void Service::SetStateType(StateType type)
{
m_StateType = static_cast<long>(type);
@ -233,6 +249,65 @@ Dictionary::Ptr Service::GetLastCheckResult(void) const
return m_LastResult;
}
bool Service::HasBeenChecked(void) const
{
return GetLastCheckResult();
}
double Service::GetLastCheck(void) const
{
Dictionary::Ptr cr = GetLastCheckResult();
double schedule_end = -1;
if (cr) {
schedule_end = cr->Get("schedule_end");
}
return schedule_end;
}
String Service::GetLastCheckOutput(void) const
{
Dictionary::Ptr cr = GetLastCheckResult();
String output;
if (cr) {
String raw_output = cr->Get("output");
size_t line_end = raw_output.Find("\n");
output = raw_output.SubStr(0, line_end);
}
return output;
}
String Service::GetLastCheckLongOutput(void) const
{
Dictionary::Ptr cr = GetLastCheckResult();
String long_output;
if (cr) {
String raw_output = cr->Get("output");
size_t line_end = raw_output.Find("\n");
if (line_end > 0 && line_end != String::NPos) {
long_output = raw_output.SubStr(line_end + 1, raw_output.GetLength());
boost::algorithm::replace_all(long_output, "\n", "\\n");
}
}
return long_output;
}
String Service::GetLastCheckPerfData(void) const
{
Dictionary::Ptr cr = GetLastCheckResult();
String perfdata = cr->Get("performance_data_raw");
boost::algorithm::replace_all(perfdata, "\n", "\\n");
return perfdata;
}
void Service::SetLastStateChange(double ts)
{
m_LastStateChange = ts;
@ -413,8 +488,10 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
if (IsVolatile())
hardChange = true;
if (hardChange)
if (hardChange) {
SetLastHardState(GetState());
SetLastHardStateChange(now);
}
if (GetState() != StateOK)
TriggerDowntimes();

View File

@ -425,3 +425,22 @@ bool Service::IsInDowntime(void) const
return false;
}
int Service::GetDowntimeDepth(void) const
{
int downtime_depth = 0;
Dictionary::Ptr downtimes = GetDowntimes();
if (!downtimes)
return 0;
ObjectLock olock(downtimes);
Dictionary::Ptr downtime;
BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) {
if (Service::IsDowntimeActive(downtime))
downtime_depth++;
}
return downtime_depth;
}

View File

@ -44,6 +44,7 @@ Service::Service(const Dictionary::Ptr& serializedObject)
RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
RegisterAttribute("macros", Attribute_Config, &m_Macros);
RegisterAttribute("custom", Attribute_Config, &m_Custom);
RegisterAttribute("hostdependencies", Attribute_Config, &m_HostDependencies);
RegisterAttribute("servicedependencies", Attribute_Config, &m_ServiceDependencies);
RegisterAttribute("servicegroups", Attribute_Config, &m_ServiceGroups);
@ -165,6 +166,11 @@ Dictionary::Ptr Service::GetMacros(void) const
return m_Macros;
}
Dictionary::Ptr Service::GetCustom(void) const
{
return m_Custom;
}
Array::Ptr Service::GetHostDependencies(void) const
{
return m_HostDependencies;

View File

@ -113,6 +113,7 @@ public:
String GetDisplayName(void) const;
Host::Ptr GetHost(void) const;
Dictionary::Ptr GetMacros(void) const;
Dictionary::Ptr GetCustom(void) const;
Array::Ptr GetHostDependencies(void) const;
Array::Ptr GetServiceDependencies(void) const;
Array::Ptr GetGroups(void) const;
@ -161,11 +162,21 @@ public:
void SetLastState(ServiceState state);
ServiceState GetLastState(void) const;
void SetLastHardState(ServiceState state);
ServiceState GetLastHardState(void) const;
void SetLastStateType(StateType type);
StateType GetLastStateType(void) const;
void SetLastCheckResult(const Dictionary::Ptr& result);
Dictionary::Ptr GetLastCheckResult(void) const;
bool HasBeenChecked(void) const;
double GetLastCheck(void) const;
String GetLastCheckOutput(void) const;
String GetLastCheckLongOutput(void) const;
String GetLastCheckPerfData(void) const;
void SetLastStateChange(double ts);
double GetLastStateChange(void) const;
@ -217,6 +228,7 @@ public:
static int GetNextDowntimeID(void);
Dictionary::Ptr GetDowntimes(void) const;
int GetDowntimeDepth(void) const;
String AddDowntime(const String& author, const String& comment,
double startTime, double endTime, bool fixed,
@ -298,6 +310,7 @@ private:
Attribute<String> m_DisplayName;
Attribute<Dictionary::Ptr> m_Macros;
Attribute<Dictionary::Ptr> m_Custom;
Attribute<Array::Ptr> m_HostDependencies;
Attribute<Array::Ptr> m_ServiceDependencies;
Attribute<Array::Ptr> m_ServiceGroups;
@ -320,6 +333,7 @@ private:
Attribute<long> m_State;
Attribute<long> m_StateType;
Attribute<long> m_LastState;
Attribute<long> m_LastHardState;
Attribute<long> m_LastStateType;
Attribute<bool> m_LastReachable;
Attribute<Dictionary::Ptr> m_LastResult;