mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-22 21:24:41 +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,6 +53,7 @@ void FileLogger::InternalSerialize(const Dictionary::Ptr& bag, int attributeType
|
||||
{
|
||||
StreamLogger::InternalSerialize(bag, attributeTypes);
|
||||
|
||||
if (attributeTypes & Attribute_Config)
|
||||
bag->Set("path", m_Path);
|
||||
}
|
||||
|
||||
|
@ -156,6 +156,7 @@ void Logger::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) c
|
||||
{
|
||||
DynamicObject::InternalSerialize(bag, attributeTypes);
|
||||
|
||||
if (attributeTypes & Attribute_Config)
|
||||
bag->Set("severity", m_Severity);
|
||||
}
|
||||
|
||||
|
@ -63,15 +63,18 @@ void Script::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) c
|
||||
{
|
||||
DynamicObject::InternalSerialize(bag, attributeTypes);
|
||||
|
||||
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);
|
||||
|
||||
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,12 +370,10 @@ void Notification::InternalSerialize(const Dictionary::Ptr& bag, int attributeTy
|
||||
{
|
||||
DynamicObject::InternalSerialize(bag, attributeTypes);
|
||||
|
||||
if (attributeTypes & Attribute_Config) {
|
||||
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);
|
||||
@ -387,16 +385,21 @@ void Notification::InternalSerialize(const Dictionary::Ptr& bag, int attributeTy
|
||||
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);
|
||||
|
||||
if (attributeTypes & Attribute_Config) {
|
||||
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");
|
||||
@ -407,3 +410,10 @@ void Notification::InternalDeserialize(const Dictionary::Ptr& bag, int attribute
|
||||
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,6 +418,7 @@ void Service::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes)
|
||||
bag->Set("notifications", m_NotificationDescriptions);
|
||||
}
|
||||
|
||||
if (attributeTypes & Attribute_State) {
|
||||
bag->Set("next_check", m_NextCheck);
|
||||
bag->Set("current_checker", m_CurrentChecker);
|
||||
bag->Set("check_attempt", m_CheckAttempt);
|
||||
@ -450,6 +451,7 @@ void Service::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes)
|
||||
bag->Set("flapping_lastchange", m_FlappingLastChange);
|
||||
bag->Set("enable_flapping", m_EnableFlapping);
|
||||
}
|
||||
}
|
||||
|
||||
void Service::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
|
||||
{
|
||||
@ -475,6 +477,7 @@ void Service::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes
|
||||
m_NotificationDescriptions = bag->Get("notifications");
|
||||
}
|
||||
|
||||
if (attributeTypes & Attribute_State) {
|
||||
m_NextCheck = bag->Get("next_check");
|
||||
m_CurrentChecker = bag->Get("current_checker");
|
||||
m_CheckAttempt = bag->Get("check_attempt");
|
||||
@ -507,3 +510,4 @@ void Service::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes
|
||||
m_FlappingLastChange = bag->Get("flapping_lastchange");
|
||||
m_EnableFlapping = bag->Get("enable_flapping");
|
||||
}
|
||||
}
|
||||
|
@ -332,10 +332,12 @@ void TimePeriod::InternalSerialize(const Dictionary::Ptr& bag, int attributeType
|
||||
bag->Set("ranges", m_Ranges);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
if (attributeTypes & Attribute_State) {
|
||||
m_ValidBegin = bag->Get("valid_begin");
|
||||
m_ValidEnd = bag->Get("valid_end");
|
||||
m_Segments = bag->Get("segments");
|
||||
}
|
||||
}
|
||||
|
@ -154,9 +154,11 @@ void User::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) con
|
||||
bag->Set("notification_state_filter", m_NotificationStateFilter);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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