db_ido: Add contact_addresses.

refs #4378
This commit is contained in:
Michael Friedrich 2013-10-01 17:16:36 +02:00
parent a71ccaefb9
commit 582cafc866
2 changed files with 36 additions and 0 deletions

View File

@ -22,7 +22,9 @@
#include "db_ido/dbvalue.h" #include "db_ido/dbvalue.h"
#include "icinga/user.h" #include "icinga/user.h"
#include "icinga/notification.h" #include "icinga/notification.h"
#include "base/convert.h"
#include "base/objectlock.h" #include "base/objectlock.h"
#include "base/logger_fwd.h"
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace icinga; using namespace icinga;
@ -83,6 +85,38 @@ Dictionary::Ptr UserDbObject::GetStatusFields(void) const
return fields; return fields;
} }
void UserDbObject::OnConfigUpdate(void)
{
Dictionary::Ptr fields = boost::make_shared<Dictionary>();
User::Ptr user = static_pointer_cast<User>(GetObject());
/* contact addresses */
Log(LogDebug, "db_ido", "contact addresses for '" + user->GetName() + "'");
Dictionary::Ptr macros = user->GetMacros();
if (macros) { /* This is sparta. */
for (int i = 1; i <= 6; i++) {
String key = "address" + Convert::ToString(i);
String val = macros->Get(key);
if (val.IsEmpty())
continue;
fields->Set("contact_id", DbValue::FromObjectInsertID(user));
fields->Set("address_number", i);
fields->Set("address", val);
fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
DbQuery query;
query.Type = DbQueryInsert;
query.Table = "contact_addresses";
query.Fields = fields;
OnQuery(query);
}
}
}
bool UserDbObject::IsStatusAttribute(const String& attribute) const bool UserDbObject::IsStatusAttribute(const String& attribute) const
{ {
return (attribute == "last_notification"); return (attribute == "last_notification");

View File

@ -41,6 +41,8 @@ public:
virtual Dictionary::Ptr GetConfigFields(void) const; virtual Dictionary::Ptr GetConfigFields(void) const;
virtual Dictionary::Ptr GetStatusFields(void) const; virtual Dictionary::Ptr GetStatusFields(void) const;
virtual void OnConfigUpdate(void);
virtual bool IsStatusAttribute(const String& attribute) const; virtual bool IsStatusAttribute(const String& attribute) const;
}; };