#include "icinga/checkcommand.h"
#include "icinga/eventcommand.h"
#include "icinga/compatutility.h"
+#include "base/convert.h"
#include "base/objectlock.h"
#include <boost/foreach.hpp>
+#include <boost/tuple/tuple.hpp>
using namespace icinga;
{
Host::Ptr host = static_pointer_cast<Host>(GetObject());
- /* safety delete */
+ /* parents, host dependencies */
DbQuery query_del1;
query_del1.Table = GetType()->GetTable() + "_parenthosts";
query_del1.Type = DbQueryDelete;
query2.Fields = fields2;
OnQuery(query2);
}
+
+ /* custom variables */
+ Log(LogDebug, "ido", "host customvars for '" + host->GetName() + "'");
+
+ DbQuery query_del3;
+ query_del3.Table = "customvariables";
+ query_del3.Type = DbQueryDelete;
+ query_del3.WhereCriteria = boost::make_shared<Dictionary>();
+ query_del3.WhereCriteria->Set("object_id", host);
+ OnQuery(query_del3);
+
+ Dictionary::Ptr customvars;
+ {
+ ObjectLock olock(host);
+ customvars = CompatUtility::GetCustomVariableConfig(host);
+ }
+
+ if (customvars) {
+ ObjectLock olock (customvars);
+
+ String key;
+ Value value;
+ BOOST_FOREACH(boost::tie(key, value), customvars) {
+ Log(LogDebug, "ido", "host customvar key: '" + key + "' value: '" + Convert::ToString(value) + "'");
+
+ Dictionary::Ptr fields3 = boost::make_shared<Dictionary>();
+ fields3->Set("varname", Convert::ToString(key));
+ fields3->Set("varvalue", Convert::ToString(value));
+ fields3->Set("config_type", 1);
+ fields3->Set("has_been_modified", 0);
+ fields3->Set("object_id", host);
+ fields3->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ DbQuery query3;
+ query3.Table = "customvariables";
+ query3.Type = DbQueryInsert;
+ query3.Fields = fields3;
+ OnQuery(query3);
+ }
+ }
}
void HostDbObject::OnStatusUpdate(void)
#include "ido/servicedbobject.h"
#include "ido/dbtype.h"
#include "ido/dbvalue.h"
+#include "base/convert.h"
#include "base/objectlock.h"
#include "base/initialize.h"
#include "base/dynamictype.h"
OnQuery(query1);
}
+ /* custom variables */
+ Log(LogDebug, "ido", "service customvars for '" + service->GetName() + "'");
+
+ DbQuery query_del2;
+ query_del2.Table = "customvariables";
+ query_del2.Type = DbQueryDelete;
+ query_del2.WhereCriteria = boost::make_shared<Dictionary>();
+ query_del2.WhereCriteria->Set("object_id", service);
+ OnQuery(query_del2);
+
+ Dictionary::Ptr customvars;
+ {
+ ObjectLock olock(service);
+ customvars = CompatUtility::GetCustomVariableConfig(service);
+ }
+
+ if (customvars) {
+ ObjectLock olock (customvars);
+
+ String key;
+ Value value;
+ BOOST_FOREACH(boost::tie(key, value), customvars) {
+ Log(LogDebug, "ido", "service customvar key: '" + key + "' value: '" + Convert::ToString(value) + "'");
+
+ Dictionary::Ptr fields2 = boost::make_shared<Dictionary>();
+ fields2->Set("varname", Convert::ToString(key));
+ fields2->Set("varvalue", Convert::ToString(value));
+ fields2->Set("config_type", 1);
+ fields2->Set("has_been_modified", 0);
+ fields2->Set("object_id", service);
+ fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ DbQuery query2;
+ query2.Table = "customvariables";
+ query2.Type = DbQueryInsert;
+ query2.Fields = fields2;
+ OnQuery(query2);
+ }
+ }
+
/* update comments */
//OnCommentsChanged(service, Empty, CommentChangedUpdated);