mirror of https://github.com/Icinga/icinga2.git
parent
0c3d246dbb
commit
8cfce66604
|
@ -374,8 +374,7 @@ Dictionary::Ptr DynamicObject::GetVars(void) const
|
|||
|
||||
void DynamicObject::SetVars(const Dictionary::Ptr& vars, const String& authority)
|
||||
{
|
||||
Dictionary::Ptr override_vars = vars->ShallowClone();
|
||||
SetOverrideVars(override_vars);
|
||||
SetOverrideVars(vars);
|
||||
|
||||
Log(LogDebug, "base", "Setting vars for object '" + GetName() + "'");
|
||||
|
||||
|
@ -384,14 +383,10 @@ void DynamicObject::SetVars(const Dictionary::Ptr& vars, const String& authority
|
|||
|
||||
bool DynamicObject::IsVarOverridden(const String& name)
|
||||
{
|
||||
Dictionary::Ptr vars_raw = GetVarsRaw();
|
||||
Dictionary::Ptr vars_override = GetOverrideVars();
|
||||
|
||||
if (!vars_raw || !vars_override)
|
||||
if (!vars_override)
|
||||
return false;
|
||||
|
||||
if (vars_raw->Get(name) != vars_override->Get(name))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return vars_override->Contains(name);
|
||||
}
|
||||
|
|
|
@ -151,9 +151,7 @@ void DbObject::SendVarsConfigUpdate(void)
|
|||
{
|
||||
DynamicObject::Ptr obj = GetObject();
|
||||
|
||||
Dictionary::Ptr vars;
|
||||
|
||||
vars = CompatUtility::GetCustomAttributeConfig(obj);
|
||||
Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(obj);
|
||||
|
||||
if (vars) {
|
||||
Log(LogDebug, "db_ido", "Updating object vars for '" + obj->GetName() + "'");
|
||||
|
@ -162,14 +160,16 @@ void DbObject::SendVarsConfigUpdate(void)
|
|||
|
||||
BOOST_FOREACH(const Dictionary::Pair& kv, vars) {
|
||||
if (!kv.first.IsEmpty()) {
|
||||
int overridden = obj->IsVarOverridden(kv.first) ? 1 : 0;
|
||||
|
||||
Log(LogDebug, "db_ido", "object customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) +
|
||||
"' overridden: " + Convert::ToString(obj->IsVarOverridden(kv.first) ? 1 : 0));
|
||||
"' overridden: " + Convert::ToString(overridden));
|
||||
|
||||
Dictionary::Ptr fields = make_shared<Dictionary>();
|
||||
fields->Set("varname", Convert::ToString(kv.first));
|
||||
fields->Set("varvalue", Convert::ToString(kv.second));
|
||||
fields->Set("config_type", 1);
|
||||
fields->Set("has_been_modified", obj->IsVarOverridden(kv.first) ? 1 : 0);
|
||||
fields->Set("has_been_modified", overridden);
|
||||
fields->Set("object_id", obj);
|
||||
fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
|
||||
|
@ -188,9 +188,7 @@ void DbObject::SendVarsStatusUpdate(void)
|
|||
{
|
||||
DynamicObject::Ptr obj = GetObject();
|
||||
|
||||
Dictionary::Ptr vars, vars_raw;
|
||||
|
||||
vars = CompatUtility::GetCustomAttributeConfig(obj);
|
||||
Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(obj);
|
||||
|
||||
if (vars) {
|
||||
Log(LogDebug, "db_ido", "Updating object vars for '" + obj->GetName() + "'");
|
||||
|
@ -311,7 +309,5 @@ void DbObject::VarsChangedHandler(const DynamicObject::Ptr& object)
|
|||
if (!dbobj)
|
||||
return;
|
||||
|
||||
Log(LogDebug, "db_ido", "Vars changed for db object '" + dbobj->GetName1() + ":" + dbobj->GetName2() + "'");
|
||||
|
||||
dbobj->SendVarsStatusUpdate();
|
||||
}
|
||||
|
|
|
@ -1950,18 +1950,19 @@ void ExternalCommandProcessor::ChangeCustomHostVar(double time, const std::vecto
|
|||
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent host '" + arguments[0] + "'"));
|
||||
|
||||
Dictionary::Ptr vars = host->GetVars();
|
||||
Dictionary::Ptr override_vars = vars->ShallowClone();
|
||||
|
||||
if (!vars->Contains(arguments[1]))
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Custom var '" + arguments[1] + "' for host '" + arguments[0] + "' does not exist."));
|
||||
|
||||
vars->Set(arguments[1], arguments[2]);
|
||||
override_vars->Set(arguments[1], arguments[2]);
|
||||
|
||||
Log(LogInformation, "icinga", "Changing custom var '" + arguments[1] + "' for host '" + arguments[0] + "' to value '" + arguments[2] + "'");
|
||||
|
||||
{
|
||||
ObjectLock olock(host);
|
||||
|
||||
host->SetVars(vars);
|
||||
host->SetVars(override_vars);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1973,12 +1974,13 @@ void ExternalCommandProcessor::ChangeCustomSvcVar(double time, const std::vector
|
|||
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
|
||||
|
||||
Dictionary::Ptr vars = service->GetVars();
|
||||
Dictionary::Ptr override_vars = vars->ShallowClone();
|
||||
|
||||
if (!vars->Contains(arguments[2]))
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Custom var '" + arguments[2] + "' for service '" + arguments[1] +
|
||||
"' on host '" + arguments[0] + "' does not exist."));
|
||||
|
||||
vars->Set(arguments[2], arguments[3]);
|
||||
override_vars->Set(arguments[2], arguments[3]);
|
||||
|
||||
Log(LogInformation, "icinga", "Changing custom var '" + arguments[2] + "' for service '" + arguments[1] + "' on host '" +
|
||||
arguments[0] + "' to value '" + arguments[3] + "'");
|
||||
|
@ -1986,7 +1988,7 @@ void ExternalCommandProcessor::ChangeCustomSvcVar(double time, const std::vector
|
|||
{
|
||||
ObjectLock olock(service);
|
||||
|
||||
service->SetVars(vars);
|
||||
service->SetVars(override_vars);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1998,18 +2000,19 @@ void ExternalCommandProcessor::ChangeCustomUserVar(double time, const std::vecto
|
|||
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent user '" + arguments[0] + "'"));
|
||||
|
||||
Dictionary::Ptr vars = user->GetVars();
|
||||
Dictionary::Ptr override_vars = vars->ShallowClone();
|
||||
|
||||
if (!vars->Contains(arguments[1]))
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Custom var '" + arguments[1] + "' for user '" + arguments[0] + "' does not exist."));
|
||||
|
||||
vars->Set(arguments[1], arguments[2]);
|
||||
override_vars->Set(arguments[1], arguments[2]);
|
||||
|
||||
Log(LogInformation, "icinga", "Changing custom var '" + arguments[1] + "' for user '" + arguments[0] + "' to value '" + arguments[2] + "'");
|
||||
|
||||
{
|
||||
ObjectLock olock(user);
|
||||
|
||||
user->SetVars(vars);
|
||||
user->SetVars(override_vars);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2021,18 +2024,19 @@ void ExternalCommandProcessor::ChangeCustomCheckcommandVar(double time, const st
|
|||
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent command '" + arguments[0] + "'"));
|
||||
|
||||
Dictionary::Ptr vars = command->GetVars();
|
||||
Dictionary::Ptr override_vars = vars->ShallowClone();
|
||||
|
||||
if (!vars->Contains(arguments[1]))
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Custom var '" + arguments[1] + "' for command '" + arguments[0] + "' does not exist."));
|
||||
|
||||
vars->Set(arguments[1], arguments[2]);
|
||||
override_vars->Set(arguments[1], arguments[2]);
|
||||
|
||||
Log(LogInformation, "icinga", "Changing custom var '" + arguments[1] + "' for command '" + arguments[0] + "' to value '" + arguments[2] + "'");
|
||||
|
||||
{
|
||||
ObjectLock olock(command);
|
||||
|
||||
command->SetVars(vars);
|
||||
command->SetVars(override_vars);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2044,18 +2048,19 @@ void ExternalCommandProcessor::ChangeCustomEventcommandVar(double time, const st
|
|||
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent command '" + arguments[0] + "'"));
|
||||
|
||||
Dictionary::Ptr vars = command->GetVars();
|
||||
Dictionary::Ptr override_vars = vars->ShallowClone();
|
||||
|
||||
if (!vars->Contains(arguments[1]))
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Custom var '" + arguments[1] + "' for command '" + arguments[0] + "' does not exist."));
|
||||
|
||||
vars->Set(arguments[1], arguments[2]);
|
||||
override_vars->Set(arguments[1], arguments[2]);
|
||||
|
||||
Log(LogInformation, "icinga", "Changing custom var '" + arguments[1] + "' for command '" + arguments[0] + "' to value '" + arguments[2] + "'");
|
||||
|
||||
{
|
||||
ObjectLock olock(command);
|
||||
|
||||
command->SetVars(vars);
|
||||
command->SetVars(override_vars);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2067,18 +2072,19 @@ void ExternalCommandProcessor::ChangeCustomNotificationcommandVar(double time, c
|
|||
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent command '" + arguments[0] + "'"));
|
||||
|
||||
Dictionary::Ptr vars = command->GetVars();
|
||||
Dictionary::Ptr override_vars = vars->ShallowClone();
|
||||
|
||||
if (!vars->Contains(arguments[1]))
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Custom var '" + arguments[1] + "' for command '" + arguments[0] + "' does not exist."));
|
||||
|
||||
vars->Set(arguments[1], arguments[2]);
|
||||
override_vars->Set(arguments[1], arguments[2]);
|
||||
|
||||
Log(LogInformation, "icinga", "Changing custom var '" + arguments[1] + "' for command '" + arguments[0] + "' to value '" + arguments[2] + "'");
|
||||
|
||||
{
|
||||
ObjectLock olock(command);
|
||||
|
||||
command->SetVars(vars);
|
||||
command->SetVars(override_vars);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue