2013-07-31 09:09:39 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2014-01-09 00:32:11 +01:00
|
|
|
* Copyright (C) 2012-present Icinga Development Team (http://www.icinga.org) *
|
2013-07-31 09:09:39 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2013-09-25 10:41:59 +02:00
|
|
|
#include "db_ido/userdbobject.h"
|
|
|
|
#include "db_ido/dbtype.h"
|
|
|
|
#include "db_ido/dbvalue.h"
|
2013-07-31 09:09:39 +02:00
|
|
|
#include "icinga/user.h"
|
2013-08-05 09:58:30 +02:00
|
|
|
#include "icinga/notification.h"
|
2013-10-01 17:16:36 +02:00
|
|
|
#include "base/convert.h"
|
2013-07-31 09:09:39 +02:00
|
|
|
#include "base/objectlock.h"
|
2013-10-01 17:16:36 +02:00
|
|
|
#include "base/logger_fwd.h"
|
2013-07-31 09:09:39 +02:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2013-08-02 17:12:07 +02:00
|
|
|
REGISTER_DBTYPE(User, "contact", DbObjectTypeContact, "contact_object_id", UserDbObject);
|
2013-07-31 09:09:39 +02:00
|
|
|
|
2013-08-01 13:20:30 +02:00
|
|
|
UserDbObject::UserDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
|
|
|
|
: DbObject(type, name1, name2)
|
2013-07-31 09:09:39 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
Dictionary::Ptr UserDbObject::GetConfigFields(void) const
|
|
|
|
{
|
2013-11-06 08:51:56 +01:00
|
|
|
Dictionary::Ptr fields = make_shared<Dictionary>();
|
2013-07-31 09:09:39 +02:00
|
|
|
User::Ptr user = static_pointer_cast<User>(GetObject());
|
|
|
|
|
2013-08-05 09:58:30 +02:00
|
|
|
fields->Set("alias", user->GetDisplayName());
|
|
|
|
|
|
|
|
Dictionary::Ptr macros = user->GetMacros();
|
|
|
|
|
|
|
|
if (macros) { /* Yuck. */
|
|
|
|
fields->Set("email_address", macros->Get("email"));
|
|
|
|
fields->Set("pager_address", macros->Get("pager"));
|
|
|
|
}
|
|
|
|
|
|
|
|
fields->Set("host_timeperiod_object_id", user->GetNotificationPeriod());
|
|
|
|
fields->Set("service_timeperiod_object_id", user->GetNotificationPeriod());
|
|
|
|
fields->Set("host_notifications_enabled", user->GetEnableNotifications());
|
|
|
|
fields->Set("service_notifications_enabled", user->GetEnableNotifications());
|
|
|
|
fields->Set("can_submit_commands", 1);
|
|
|
|
fields->Set("notify_service_recovery", user->GetNotificationStateFilter() & NotificationRecovery);
|
|
|
|
fields->Set("notify_service_warning", user->GetNotificationStateFilter() & NotificationProblem);
|
|
|
|
fields->Set("notify_service_unknown", user->GetNotificationStateFilter() & NotificationProblem);
|
|
|
|
fields->Set("notify_service_critical", user->GetNotificationStateFilter() & NotificationProblem);
|
|
|
|
fields->Set("notify_service_flapping", user->GetNotificationStateFilter() & (NotificationFlappingStart | NotificationFlappingEnd));
|
|
|
|
fields->Set("notify_service_downtime", user->GetNotificationStateFilter() & (NotificationDowntimeStart | NotificationDowntimeEnd | NotificationDowntimeRemoved));
|
|
|
|
fields->Set("notify_host_recovery", user->GetNotificationStateFilter() & NotificationRecovery);
|
|
|
|
fields->Set("notify_host_down", user->GetNotificationStateFilter() & NotificationProblem);
|
|
|
|
fields->Set("notify_host_unreachable", user->GetNotificationStateFilter() & NotificationProblem);
|
|
|
|
fields->Set("notify_host_flapping", user->GetNotificationStateFilter() & (NotificationFlappingStart | NotificationFlappingEnd));
|
|
|
|
fields->Set("notify_host_downtime", user->GetNotificationStateFilter() & (NotificationDowntimeStart | NotificationDowntimeEnd | NotificationDowntimeRemoved));
|
2013-07-31 09:09:39 +02:00
|
|
|
|
|
|
|
return fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary::Ptr UserDbObject::GetStatusFields(void) const
|
|
|
|
{
|
2013-11-06 08:51:56 +01:00
|
|
|
Dictionary::Ptr fields = make_shared<Dictionary>();
|
2013-07-31 09:09:39 +02:00
|
|
|
User::Ptr user = static_pointer_cast<User>(GetObject());
|
|
|
|
|
2013-08-08 08:30:19 +02:00
|
|
|
fields->Set("host_notifications_enabled", user->GetEnableNotifications());
|
|
|
|
fields->Set("service_notifications_enabled", user->GetEnableNotifications());
|
|
|
|
fields->Set("last_host_notification", DbValue::FromTimestamp(user->GetLastNotification()));
|
|
|
|
fields->Set("last_service_notification", DbValue::FromTimestamp(user->GetLastNotification()));
|
2013-07-31 09:09:39 +02:00
|
|
|
fields->Set("modified_attributes", Empty);
|
|
|
|
fields->Set("modified_host_attributes", Empty);
|
|
|
|
fields->Set("modified_service_attributes", Empty);
|
|
|
|
|
|
|
|
return fields;
|
|
|
|
}
|
2013-08-08 08:30:19 +02:00
|
|
|
|
2013-10-01 17:16:36 +02:00
|
|
|
void UserDbObject::OnConfigUpdate(void)
|
|
|
|
{
|
2013-11-06 08:51:56 +01:00
|
|
|
Dictionary::Ptr fields = make_shared<Dictionary>();
|
2013-10-01 17:16:36 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 08:30:19 +02:00
|
|
|
bool UserDbObject::IsStatusAttribute(const String& attribute) const
|
|
|
|
{
|
|
|
|
return (attribute == "last_notification");
|
|
|
|
}
|