From: Gunnar Beutner Date: Thu, 29 Aug 2013 08:40:43 +0000 (+0200) Subject: Fix state file functionality. X-Git-Tag: v0.0.3~665 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=911f64c4118f225f3afa45c912e9af07d67ac6a4;p=icinga2 Fix state file functionality. --- diff --git a/components/cluster/endpoint.cpp b/components/cluster/endpoint.cpp index 5194837e2..7c51e6dc5 100644 --- a/components/cluster/endpoint.cpp +++ b/components/cluster/endpoint.cpp @@ -131,7 +131,6 @@ void Endpoint::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) DynamicObject::InternalSerialize(bag, attributeTypes); if (attributeTypes & Attribute_Config) { - bag->Set("local", m_Local); bag->Set("host", m_Host); bag->Set("port", m_Port); } @@ -142,7 +141,6 @@ void Endpoint::InternalDeserialize(const Dictionary::Ptr& bag, int attributeType DynamicObject::InternalDeserialize(bag, attributeTypes); if (attributeTypes & Attribute_Config) { - m_Local = bag->Get("local"); m_Host = bag->Get("host"); m_Port = bag->Get("port"); } diff --git a/components/cluster/endpoint.h b/components/cluster/endpoint.h index 834ae0b59..a7344e700 100644 --- a/components/cluster/endpoint.h +++ b/components/cluster/endpoint.h @@ -58,7 +58,6 @@ protected: virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); private: - bool m_Local; Dictionary::Ptr m_Subscriptions; String m_Host; String m_Port; diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 72bec2ae1..9007c83d3 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -85,9 +85,6 @@ static bool LoadConfigFiles(bool validateOnly) if (validateOnly) return true; - /* restore the previous program state */ - DynamicObject::RestoreObjects(Application::GetStatePath()); - ConfigItem::ActivateItems(); ConfigItem::DiscardItems(); diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h index 8412844dc..048fd5deb 100644 --- a/lib/base/dynamicobject.h +++ b/lib/base/dynamicobject.h @@ -39,18 +39,8 @@ class DynamicType; */ enum AttributeType { - Attribute_Transient = 1, - - /* Unlike transient attributes local attributes are persisted - * in the program state file. */ - Attribute_Local = 2, - - /* Attributes read from the config file are implicitly marked - * as config attributes. */ - Attribute_Config = 4, - - /* Combination of all attribute types */ - Attribute_All = Attribute_Transient | Attribute_Local | Attribute_Config + Attribute_State = 1, + Attribute_Config = 2, }; /** @@ -100,8 +90,8 @@ public: return dynamic_pointer_cast(object); } - static void DumpObjects(const String& filename, int attributeTypes = Attribute_Local); - static void RestoreObjects(const String& filename, int attributeTypes = Attribute_Local); + static void DumpObjects(const String& filename, int attributeTypes = Attribute_State); + static void RestoreObjects(const String& filename, int attributeTypes = Attribute_State); static void StopObjects(void); Dictionary::Ptr GetCustom(void) const; diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index 8a607ef42..9a3bc5a8b 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -138,7 +138,7 @@ DynamicObject::Ptr DynamicType::CreateObject(const Dictionary::Ptr& serializedUp DynamicObject::Ptr object = factory(); - object->Deserialize(serializedUpdate, Attribute_All); + object->Deserialize(serializedUpdate, Attribute_Config); return object; } diff --git a/lib/base/filelogger.cpp b/lib/base/filelogger.cpp index 00056ec13..6dac6878f 100644 --- a/lib/base/filelogger.cpp +++ b/lib/base/filelogger.cpp @@ -53,7 +53,8 @@ void FileLogger::InternalSerialize(const Dictionary::Ptr& bag, int attributeType { StreamLogger::InternalSerialize(bag, attributeTypes); - bag->Set("path", m_Path); + if (attributeTypes & Attribute_Config) + bag->Set("path", m_Path); } void FileLogger::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index cfdae3578..e714074fd 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -156,7 +156,8 @@ void Logger::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) c { DynamicObject::InternalSerialize(bag, attributeTypes); - bag->Set("severity", m_Severity); + if (attributeTypes & Attribute_Config) + bag->Set("severity", m_Severity); } void Logger::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) diff --git a/lib/base/script.cpp b/lib/base/script.cpp index 9f82c555e..8e48c49e4 100644 --- a/lib/base/script.cpp +++ b/lib/base/script.cpp @@ -63,15 +63,18 @@ void Script::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) c { DynamicObject::InternalSerialize(bag, attributeTypes); - bag->Set("language", m_Language); - bag->Set("code", m_Code); + if (attributeTypes & Attribute_Config) { + bag->Set("language", m_Language); + bag->Set("code", m_Code); + } } void Script::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) { DynamicObject::InternalDeserialize(bag, attributeTypes); - m_Language = bag->Get("language"); - m_Code = bag->Get("code"); - + if (attributeTypes & Attribute_Config) { + m_Language = bag->Get("language"); + m_Code = bag->Get("code"); + } } diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 052e7b855..ebca955d9 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -19,6 +19,7 @@ #include "config/configitem.h" #include "config/configcompilercontext.h" +#include "base/application.h" #include "base/dynamictype.h" #include "base/objectlock.h" #include "base/logger_fwd.h" @@ -274,6 +275,9 @@ void ConfigItem::ActivateItems(void) objects.push_back(object); } + /* restore the previous program state */ + DynamicObject::RestoreObjects(Application::GetStatePath()); + BOOST_FOREACH(const DynamicObject::Ptr& object, objects) { Log(LogDebug, "config", "Activating object '" + object->GetName() + "' of type '" + object->GetType()->GetName() + "'"); object->Start(); diff --git a/lib/icinga/icinga-type.conf b/lib/icinga/icinga-type.conf index 63b5a1079..3962611f4 100644 --- a/lib/icinga/icinga-type.conf +++ b/lib/icinga/icinga-type.conf @@ -184,7 +184,6 @@ type HostGroup { type IcingaApplication { %attribute string "pid_path", - %attribute string "state_path", %attribute dictionary "macros" { %attribute string "*" } diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 8b19d2203..7da0ce79a 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -370,40 +370,50 @@ void Notification::InternalSerialize(const Dictionary::Ptr& bag, int attributeTy { DynamicObject::InternalSerialize(bag, attributeTypes); - bag->Set("notification_command", m_NotificationCommand); - bag->Set("notification_interval", m_NotificationInterval); - bag->Set("notification_period", m_NotificationPeriod); - bag->Set("last_notification", m_LastNotification); - bag->Set("next_notification", m_NextNotification); - bag->Set("notification_number", m_NotificationNumber); - bag->Set("macros", m_Macros); - bag->Set("users", m_Users); - bag->Set("groups", m_Groups); - bag->Set("times", m_Times); - bag->Set("notification_type_filter", m_NotificationTypeFilter); - bag->Set("notification_state_filter", m_NotificationStateFilter); - bag->Set("host_name", m_HostName); - bag->Set("export_macros", m_ExportMacros); - bag->Set("service", m_Service); + if (attributeTypes & Attribute_Config) { + bag->Set("notification_command", m_NotificationCommand); + bag->Set("notification_interval", m_NotificationInterval); + bag->Set("notification_period", m_NotificationPeriod); + bag->Set("macros", m_Macros); + bag->Set("users", m_Users); + bag->Set("groups", m_Groups); + bag->Set("times", m_Times); + bag->Set("notification_type_filter", m_NotificationTypeFilter); + bag->Set("notification_state_filter", m_NotificationStateFilter); + bag->Set("host_name", m_HostName); + bag->Set("export_macros", m_ExportMacros); + bag->Set("service", m_Service); + } + + if (attributeTypes & Attribute_State) { + bag->Set("last_notification", m_LastNotification); + bag->Set("next_notification", m_NextNotification); + bag->Set("notification_number", m_NotificationNumber); + } } void Notification::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) { DynamicObject::InternalDeserialize(bag, attributeTypes); - m_NotificationCommand = bag->Get("notification_command"); - m_NotificationInterval = bag->Get("notification_interval"); - m_NotificationPeriod = bag->Get("notification_period"); - m_LastNotification = bag->Get("last_notification"); - m_NextNotification = bag->Get("next_notification"); - m_NotificationNumber = bag->Get("notification_number"); - m_Macros = bag->Get("macros"); - m_Users = bag->Get("users"); - m_Groups = bag->Get("groups"); - m_Times = bag->Get("times"); - m_NotificationTypeFilter = bag->Get("notification_type_filter"); - m_NotificationStateFilter = bag->Get("notification_state_filter"); - m_HostName = bag->Get("host_name"); - m_ExportMacros = bag->Get("export_macros"); - m_Service = bag->Get("service"); + if (attributeTypes & Attribute_Config) { + m_NotificationCommand = bag->Get("notification_command"); + m_NotificationInterval = bag->Get("notification_interval"); + m_NotificationPeriod = bag->Get("notification_period"); + m_Macros = bag->Get("macros"); + m_Users = bag->Get("users"); + m_Groups = bag->Get("groups"); + m_Times = bag->Get("times"); + m_NotificationTypeFilter = bag->Get("notification_type_filter"); + m_NotificationStateFilter = bag->Get("notification_state_filter"); + m_HostName = bag->Get("host_name"); + m_ExportMacros = bag->Get("export_macros"); + m_Service = bag->Get("service"); + } + + if (attributeTypes & Attribute_State) { + m_LastNotification = bag->Get("last_notification"); + m_NextNotification = bag->Get("next_notification"); + m_NotificationNumber = bag->Get("notification_number"); + } } diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index efa213999..c9102d032 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -418,37 +418,39 @@ void Service::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) bag->Set("notifications", m_NotificationDescriptions); } - bag->Set("next_check", m_NextCheck); - bag->Set("current_checker", m_CurrentChecker); - bag->Set("check_attempt", m_CheckAttempt); - bag->Set("state", m_State); - bag->Set("state_type", m_StateType); - bag->Set("last_state", m_LastState); - bag->Set("last_hard_state", m_LastHardState); - bag->Set("last_state_type", m_LastStateType); - bag->Set("last_reachable", m_LastReachable); - bag->Set("last_result", m_LastResult); - bag->Set("last_state_change", m_LastStateChange); - bag->Set("last_hard_state_change", m_LastHardStateChange); - bag->Set("last_state_ok", m_LastStateOK); - bag->Set("last_state_warning", m_LastStateWarning); - bag->Set("last_state_critical", m_LastStateCritical); - bag->Set("last_state_unknown", m_LastStateUnknown); - bag->Set("last_state_unreachable", m_LastStateUnreachable); - bag->Set("last_in_downtime", m_LastInDowntime); - bag->Set("enable_active_checks", m_EnableActiveChecks); - bag->Set("enable_passive_checks", m_EnablePassiveChecks); - bag->Set("force_next_check", m_ForceNextCheck); - bag->Set("acknowledgement", m_Acknowledgement); - bag->Set("acknowledgement_expiry", m_AcknowledgementExpiry); - bag->Set("comments", m_Comments); - bag->Set("downtimes", m_Downtimes); - bag->Set("enable_notifications", m_EnableNotifications); - bag->Set("force_next_notification", m_ForceNextNotification); - bag->Set("flapping_positive", m_FlappingPositive); - bag->Set("flapping_negative", m_FlappingNegative); - bag->Set("flapping_lastchange", m_FlappingLastChange); - bag->Set("enable_flapping", m_EnableFlapping); + if (attributeTypes & Attribute_State) { + bag->Set("next_check", m_NextCheck); + bag->Set("current_checker", m_CurrentChecker); + bag->Set("check_attempt", m_CheckAttempt); + bag->Set("state", m_State); + bag->Set("state_type", m_StateType); + bag->Set("last_state", m_LastState); + bag->Set("last_hard_state", m_LastHardState); + bag->Set("last_state_type", m_LastStateType); + bag->Set("last_reachable", m_LastReachable); + bag->Set("last_result", m_LastResult); + bag->Set("last_state_change", m_LastStateChange); + bag->Set("last_hard_state_change", m_LastHardStateChange); + bag->Set("last_state_ok", m_LastStateOK); + bag->Set("last_state_warning", m_LastStateWarning); + bag->Set("last_state_critical", m_LastStateCritical); + bag->Set("last_state_unknown", m_LastStateUnknown); + bag->Set("last_state_unreachable", m_LastStateUnreachable); + bag->Set("last_in_downtime", m_LastInDowntime); + bag->Set("enable_active_checks", m_EnableActiveChecks); + bag->Set("enable_passive_checks", m_EnablePassiveChecks); + bag->Set("force_next_check", m_ForceNextCheck); + bag->Set("acknowledgement", m_Acknowledgement); + bag->Set("acknowledgement_expiry", m_AcknowledgementExpiry); + bag->Set("comments", m_Comments); + bag->Set("downtimes", m_Downtimes); + bag->Set("enable_notifications", m_EnableNotifications); + bag->Set("force_next_notification", m_ForceNextNotification); + bag->Set("flapping_positive", m_FlappingPositive); + bag->Set("flapping_negative", m_FlappingNegative); + bag->Set("flapping_lastchange", m_FlappingLastChange); + bag->Set("enable_flapping", m_EnableFlapping); + } } void Service::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) @@ -475,35 +477,37 @@ void Service::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes m_NotificationDescriptions = bag->Get("notifications"); } - m_NextCheck = bag->Get("next_check"); - m_CurrentChecker = bag->Get("current_checker"); - m_CheckAttempt = bag->Get("check_attempt"); - m_State = bag->Get("state"); - m_StateType = bag->Get("state_type"); - m_LastState = bag->Get("last_state"); - m_LastHardState = bag->Get("last_hard_state"); - m_LastStateType = bag->Get("last_state_type"); - m_LastReachable = bag->Get("last_reachable"); - m_LastResult = bag->Get("last_result"); - m_LastStateChange = bag->Get("last_state_change"); - m_LastHardStateChange = bag->Get("last_hard_state_change"); - m_LastStateOK = bag->Get("last_state_ok"); - m_LastStateWarning = bag->Get("last_state_warning"); - m_LastStateCritical = bag->Get("last_state_critical"); - m_LastStateUnknown = bag->Get("last_state_unknown"); - m_LastStateUnreachable = bag->Get("last_state_unreachable"); - m_LastInDowntime = bag->Get("last_in_downtime"); - m_EnableActiveChecks = bag->Get("enable_active_checks"); - m_EnablePassiveChecks = bag->Get("enable_passive_checks"); - m_ForceNextCheck = bag->Get("force_next_check"); - m_Acknowledgement = bag->Get("acknowledgement"); - m_AcknowledgementExpiry = bag->Get("acknowledgement_expiry"); - m_Comments = bag->Get("comments"); - m_Downtimes = bag->Get("downtimes"); - m_EnableNotifications = bag->Get("enable_notifications"); - m_ForceNextNotification = bag->Get("force_next_notification"); - m_FlappingPositive = bag->Get("flapping_positive"); - m_FlappingNegative = bag->Get("flapping_negative"); - m_FlappingLastChange = bag->Get("flapping_lastchange"); - m_EnableFlapping = bag->Get("enable_flapping"); + if (attributeTypes & Attribute_State) { + m_NextCheck = bag->Get("next_check"); + m_CurrentChecker = bag->Get("current_checker"); + m_CheckAttempt = bag->Get("check_attempt"); + m_State = bag->Get("state"); + m_StateType = bag->Get("state_type"); + m_LastState = bag->Get("last_state"); + m_LastHardState = bag->Get("last_hard_state"); + m_LastStateType = bag->Get("last_state_type"); + m_LastReachable = bag->Get("last_reachable"); + m_LastResult = bag->Get("last_result"); + m_LastStateChange = bag->Get("last_state_change"); + m_LastHardStateChange = bag->Get("last_hard_state_change"); + m_LastStateOK = bag->Get("last_state_ok"); + m_LastStateWarning = bag->Get("last_state_warning"); + m_LastStateCritical = bag->Get("last_state_critical"); + m_LastStateUnknown = bag->Get("last_state_unknown"); + m_LastStateUnreachable = bag->Get("last_state_unreachable"); + m_LastInDowntime = bag->Get("last_in_downtime"); + m_EnableActiveChecks = bag->Get("enable_active_checks"); + m_EnablePassiveChecks = bag->Get("enable_passive_checks"); + m_ForceNextCheck = bag->Get("force_next_check"); + m_Acknowledgement = bag->Get("acknowledgement"); + m_AcknowledgementExpiry = bag->Get("acknowledgement_expiry"); + m_Comments = bag->Get("comments"); + m_Downtimes = bag->Get("downtimes"); + m_EnableNotifications = bag->Get("enable_notifications"); + m_ForceNextNotification = bag->Get("force_next_notification"); + m_FlappingPositive = bag->Get("flapping_positive"); + m_FlappingNegative = bag->Get("flapping_negative"); + m_FlappingLastChange = bag->Get("flapping_lastchange"); + m_EnableFlapping = bag->Get("enable_flapping"); + } } diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index 999dce9fd..25e803dee 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -332,9 +332,11 @@ void TimePeriod::InternalSerialize(const Dictionary::Ptr& bag, int attributeType bag->Set("ranges", m_Ranges); } - bag->Set("valid_begin", m_ValidBegin); - bag->Set("valid_end", m_ValidEnd); - bag->Set("segments", m_Segments); + if (attributeTypes & Attribute_State) { + bag->Set("valid_begin", m_ValidBegin); + bag->Set("valid_end", m_ValidEnd); + bag->Set("segments", m_Segments); + } } void TimePeriod::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) @@ -346,7 +348,9 @@ void TimePeriod::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTy m_Ranges = bag->Get("ranges"); } - m_ValidBegin = bag->Get("valid_begin"); - m_ValidEnd = bag->Get("valid_end"); - m_Segments = bag->Get("segments"); + if (attributeTypes & Attribute_State) { + m_ValidBegin = bag->Get("valid_begin"); + m_ValidEnd = bag->Get("valid_end"); + m_Segments = bag->Get("segments"); + } } diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index 47ec2110a..b4dcb24d5 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -154,8 +154,10 @@ void User::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) con bag->Set("notification_state_filter", m_NotificationStateFilter); } - bag->Set("enable_notifications", m_EnableNotifications); - bag->Set("last_notification", m_LastNotification); + if (attributeTypes & Attribute_State) { + bag->Set("enable_notifications", m_EnableNotifications); + bag->Set("last_notification", m_LastNotification); + } } void User::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) @@ -171,6 +173,8 @@ void User::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) m_NotificationStateFilter = bag->Get("notification_state_filter"); } - m_EnableNotifications = bag->Get("enable_notifications"); - m_LastNotification = bag->Get("last_notification"); + if (attributeTypes & Attribute_State) { + m_EnableNotifications = bag->Get("enable_notifications"); + m_LastNotification = bag->Get("last_notification"); + } }