mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
Fix state file functionality.
This commit is contained in:
parent
f134ed61bc
commit
911f64c411
@ -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");
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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<T>(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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -184,7 +184,6 @@ type HostGroup {
|
||||
|
||||
type IcingaApplication {
|
||||
%attribute string "pid_path",
|
||||
%attribute string "state_path",
|
||||
%attribute dictionary "macros" {
|
||||
%attribute string "*"
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user