2012-06-27 18:43:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2013-09-25 07:43:57 +02:00
|
|
|
* Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) *
|
2012-06-27 18:43:34 +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 07:31:46 +02:00
|
|
|
#include "compat/statusdatawriter.h"
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "icinga/icingaapplication.h"
|
|
|
|
#include "icinga/cib.h"
|
|
|
|
#include "icinga/hostgroup.h"
|
|
|
|
#include "icinga/servicegroup.h"
|
2013-07-01 19:04:08 +02:00
|
|
|
#include "icinga/checkcommand.h"
|
|
|
|
#include "icinga/eventcommand.h"
|
|
|
|
#include "icinga/timeperiod.h"
|
|
|
|
#include "icinga/notificationcommand.h"
|
2013-07-23 09:12:38 +02:00
|
|
|
#include "icinga/compatutility.h"
|
2013-03-16 21:18:53 +01:00
|
|
|
#include "base/dynamictype.h"
|
|
|
|
#include "base/objectlock.h"
|
2013-07-01 13:46:50 +02:00
|
|
|
#include "base/convert.h"
|
2013-03-16 21:18:53 +01:00
|
|
|
#include "base/logger_fwd.h"
|
|
|
|
#include "base/exception.h"
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "base/application.h"
|
2013-03-16 21:18:53 +01:00
|
|
|
#include <boost/foreach.hpp>
|
2013-03-18 11:02:18 +01:00
|
|
|
#include <boost/tuple/tuple.hpp>
|
2013-06-24 11:35:56 +02:00
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
2013-03-17 20:19:29 +01:00
|
|
|
#include <fstream>
|
2012-06-27 18:43:34 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2013-09-25 07:31:46 +02:00
|
|
|
REGISTER_TYPE(StatusDataWriter);
|
2013-02-08 07:11:14 +01:00
|
|
|
|
2012-06-29 14:14:51 +02:00
|
|
|
/**
|
|
|
|
* Hint: The reason why we're using "\n" rather than std::endl is because
|
|
|
|
* std::endl also _flushes_ the output stream which severely degrades
|
|
|
|
* performance (see http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25s02.html).
|
|
|
|
*/
|
|
|
|
|
2013-03-12 13:45:54 +01:00
|
|
|
/**
|
|
|
|
* Starts the component.
|
|
|
|
*/
|
2013-09-25 07:31:46 +02:00
|
|
|
void StatusDataWriter::Start(void)
|
2013-03-12 13:45:54 +01:00
|
|
|
{
|
2013-08-20 11:06:04 +02:00
|
|
|
DynamicObject::Start();
|
|
|
|
|
2013-11-06 08:51:56 +01:00
|
|
|
m_StatusTimer = make_shared<Timer>();
|
2013-12-05 10:00:20 +01:00
|
|
|
m_StatusTimer->SetInterval(GetUpdateInterval());
|
2013-09-25 07:31:46 +02:00
|
|
|
m_StatusTimer->OnTimerExpired.connect(boost::bind(&StatusDataWriter::StatusTimerHandler, this));
|
2013-03-12 13:45:54 +01:00
|
|
|
m_StatusTimer->Start();
|
|
|
|
m_StatusTimer->Reschedule(0);
|
|
|
|
}
|
|
|
|
|
2013-09-25 07:31:46 +02:00
|
|
|
void StatusDataWriter::DumpComments(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type)
|
2013-01-29 16:29:09 +01:00
|
|
|
{
|
|
|
|
Service::Ptr service;
|
2013-02-09 01:16:43 +01:00
|
|
|
Dictionary::Ptr comments = owner->GetComments();
|
2013-01-29 16:29:09 +01:00
|
|
|
|
2013-07-16 10:18:03 +02:00
|
|
|
Host::Ptr host = owner->GetHost();
|
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
ObjectLock olock(comments);
|
|
|
|
|
2013-11-30 17:42:50 +01:00
|
|
|
BOOST_FOREACH(const Dictionary::Pair& kv, comments) {
|
|
|
|
Comment::Ptr comment = kv.second;
|
|
|
|
|
2013-11-09 22:16:53 +01:00
|
|
|
if (comment->IsExpired())
|
2013-01-30 14:28:13 +01:00
|
|
|
continue;
|
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
if (type == CompatTypeHost)
|
2013-01-29 16:29:09 +01:00
|
|
|
fp << "hostcomment {" << "\n";
|
|
|
|
else
|
|
|
|
fp << "servicecomment {" << "\n"
|
2013-02-09 01:16:43 +01:00
|
|
|
<< "\t" << "service_description=" << owner->GetShortName() << "\n";
|
2013-01-29 16:29:09 +01:00
|
|
|
|
2013-07-16 10:18:03 +02:00
|
|
|
fp << "\t" << "host_name=" << host->GetName() << "\n"
|
2013-11-09 21:19:52 +01:00
|
|
|
<< "\t" << "comment_id=" << comment->GetLegacyId() << "\n"
|
|
|
|
<< "\t" << "entry_time=" << comment->GetEntryTime() << "\n"
|
|
|
|
<< "\t" << "entry_type=" << comment->GetEntryType() << "\n"
|
2013-01-29 16:29:09 +01:00
|
|
|
<< "\t" << "persistent=" << 1 << "\n"
|
2013-11-09 21:19:52 +01:00
|
|
|
<< "\t" << "author=" << comment->GetAuthor() << "\n"
|
|
|
|
<< "\t" << "comment_data=" << comment->GetText() << "\n"
|
|
|
|
<< "\t" << "expires=" << (comment->GetExpireTime() != 0 ? 1 : 0) << "\n"
|
|
|
|
<< "\t" << "expire_time=" << comment->GetExpireTime() << "\n"
|
2013-01-29 16:29:09 +01:00
|
|
|
<< "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-25 07:31:46 +02:00
|
|
|
void StatusDataWriter::DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& tp)
|
2013-07-01 20:12:03 +02:00
|
|
|
{
|
2013-07-02 08:44:03 +02:00
|
|
|
fp << "define timeperiod {" << "\n"
|
2013-07-02 08:52:47 +02:00
|
|
|
<< "\t" << "timeperiod_name" << "\t" << tp->GetName() << "\n"
|
|
|
|
<< "\t" << "alias" << "\t" << tp->GetName() << "\n";
|
2013-07-01 20:12:03 +02:00
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
Dictionary::Ptr ranges = tp->GetRanges();
|
2013-07-02 08:44:03 +02:00
|
|
|
|
|
|
|
if (ranges) {
|
|
|
|
ObjectLock olock(ranges);
|
2013-11-30 17:42:50 +01:00
|
|
|
BOOST_FOREACH(const Dictionary::Pair& kv, ranges) {
|
|
|
|
fp << "\t" << kv.first << "\t" << kv.second << "\n";
|
2013-07-02 08:44:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fp << "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
2013-07-01 20:12:03 +02:00
|
|
|
}
|
2013-07-02 08:44:03 +02:00
|
|
|
|
2013-09-25 07:31:46 +02:00
|
|
|
void StatusDataWriter::DumpCommand(std::ostream& fp, const Command::Ptr& command)
|
2013-07-01 20:12:03 +02:00
|
|
|
{
|
2013-07-02 08:44:03 +02:00
|
|
|
fp << "define command {" << "\n"
|
2013-07-02 09:35:03 +02:00
|
|
|
<< "\t" << "command_name\t";
|
|
|
|
|
|
|
|
|
|
|
|
if (command->GetType() == DynamicType::GetByName("CheckCommand"))
|
|
|
|
fp << "check_";
|
|
|
|
else if (command->GetType() == DynamicType::GetByName("NotificationCommand"))
|
|
|
|
fp << "notification_";
|
|
|
|
else if (command->GetType() == DynamicType::GetByName("EventCommand"))
|
|
|
|
fp << "event_";
|
|
|
|
|
|
|
|
fp << command->GetName() << "\n";
|
2013-07-01 20:12:03 +02:00
|
|
|
|
2013-07-02 08:44:03 +02:00
|
|
|
fp << "\t" << "command_line\t";
|
|
|
|
|
|
|
|
Value commandLine = command->GetCommandLine();
|
|
|
|
|
|
|
|
if (commandLine.IsObjectType<Array>()) {
|
|
|
|
Array::Ptr args = commandLine;
|
|
|
|
|
|
|
|
ObjectLock olock(args);
|
|
|
|
String arg;
|
|
|
|
BOOST_FOREACH(arg, args) {
|
|
|
|
// This is obviously incorrect for non-trivial cases.
|
2013-07-23 09:12:38 +02:00
|
|
|
fp << " \"" << CompatUtility::EscapeString(arg) << "\"";
|
2013-07-02 08:44:03 +02:00
|
|
|
}
|
2013-07-02 08:52:47 +02:00
|
|
|
} else if (!commandLine.IsEmpty()) {
|
2013-11-11 13:04:18 +01:00
|
|
|
fp << CompatUtility::EscapeString(commandLine);
|
2013-07-02 08:44:03 +02:00
|
|
|
} else {
|
2013-07-02 08:52:47 +02:00
|
|
|
fp << "<internal>";
|
2013-07-01 20:12:03 +02:00
|
|
|
}
|
|
|
|
|
2013-07-02 08:44:03 +02:00
|
|
|
fp << "\n";
|
|
|
|
|
|
|
|
fp << "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
2013-07-01 20:12:03 +02:00
|
|
|
|
|
|
|
}
|
2013-07-02 08:44:03 +02:00
|
|
|
|
2013-09-25 07:31:46 +02:00
|
|
|
void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type)
|
2013-01-29 14:19:54 +01:00
|
|
|
{
|
2013-03-02 09:07:47 +01:00
|
|
|
Host::Ptr host = owner->GetHost();
|
2013-03-01 12:07:52 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
Dictionary::Ptr downtimes = owner->GetDowntimes();
|
2013-01-29 14:19:54 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
ObjectLock olock(downtimes);
|
2013-03-01 12:07:52 +01:00
|
|
|
|
2013-11-30 17:42:50 +01:00
|
|
|
BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) {
|
|
|
|
Downtime::Ptr downtime = kv.second;
|
|
|
|
|
2013-11-09 22:16:53 +01:00
|
|
|
if (downtime->IsExpired())
|
2013-01-30 14:28:13 +01:00
|
|
|
continue;
|
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
if (type == CompatTypeHost)
|
2013-01-29 14:19:54 +01:00
|
|
|
fp << "hostdowntime {" << "\n";
|
|
|
|
else
|
|
|
|
fp << "servicedowntime {" << "\n"
|
2013-03-02 09:07:47 +01:00
|
|
|
<< "\t" << "service_description=" << owner->GetShortName() << "\n";
|
2013-01-29 14:19:54 +01:00
|
|
|
|
2013-11-09 22:08:26 +01:00
|
|
|
Downtime::Ptr triggeredByObj = Service::GetDowntimeByID(downtime->GetTriggeredBy());
|
2013-01-30 11:10:47 +01:00
|
|
|
int triggeredByLegacy = 0;
|
2013-01-31 13:57:14 +01:00
|
|
|
if (triggeredByObj)
|
2013-11-09 22:08:26 +01:00
|
|
|
triggeredByLegacy = triggeredByObj->GetLegacyId();
|
2013-01-30 11:10:47 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
fp << "\t" << "host_name=" << host->GetName() << "\n"
|
2013-11-09 22:08:26 +01:00
|
|
|
<< "\t" << "downtime_id=" << downtime->GetLegacyId() << "\n"
|
|
|
|
<< "\t" << "entry_time=" << downtime->GetEntryTime() << "\n"
|
|
|
|
<< "\t" << "start_time=" << downtime->GetStartTime() << "\n"
|
|
|
|
<< "\t" << "end_time=" << downtime->GetEndTime() << "\n"
|
2013-01-30 11:10:47 +01:00
|
|
|
<< "\t" << "triggered_by=" << triggeredByLegacy << "\n"
|
2013-11-09 22:08:26 +01:00
|
|
|
<< "\t" << "fixed=" << static_cast<long>(downtime->GetFixed()) << "\n"
|
|
|
|
<< "\t" << "duration=" << static_cast<long>(downtime->GetDuration()) << "\n"
|
2013-11-09 22:16:53 +01:00
|
|
|
<< "\t" << "is_in_effect=" << (downtime->IsActive() ? 1 : 0) << "\n"
|
2013-11-09 22:08:26 +01:00
|
|
|
<< "\t" << "author=" << downtime->GetAuthor() << "\n"
|
|
|
|
<< "\t" << "comment=" << downtime->GetComment() << "\n"
|
|
|
|
<< "\t" << "trigger_time=" << downtime->GetTriggerTime() << "\n"
|
2013-01-29 14:19:54 +01:00
|
|
|
<< "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-25 07:31:46 +02:00
|
|
|
void StatusDataWriter::DumpHostStatus(std::ostream& fp, const Host::Ptr& host)
|
2012-06-27 18:43:34 +02:00
|
|
|
{
|
2013-03-02 09:07:47 +01:00
|
|
|
fp << "hoststatus {" << "\n"
|
|
|
|
<< "\t" << "host_name=" << host->GetName() << "\n";
|
2013-02-19 23:02:08 +01:00
|
|
|
|
2013-09-25 09:12:15 +02:00
|
|
|
Service::Ptr hc = host->GetCheckService();
|
2013-03-02 09:07:47 +01:00
|
|
|
ObjectLock olock(hc);
|
|
|
|
|
2013-02-19 23:02:08 +01:00
|
|
|
if (hc)
|
|
|
|
DumpServiceStatusAttrs(fp, hc, CompatTypeHost);
|
2013-02-07 20:29:35 +01:00
|
|
|
|
2013-07-18 18:28:43 +02:00
|
|
|
/* ugly but cgis parse only that */
|
|
|
|
fp << "\t" << "last_time_up=" << host->GetLastStateUp() << "\n"
|
|
|
|
<< "\t" << "last_time_down=" << host->GetLastStateDown() << "\n"
|
|
|
|
<< "\t" << "last_time_unreachable=" << host->GetLastStateUnreachable() << "\n";
|
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
fp << "\t" << "}" << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\n";
|
2013-01-29 14:19:54 +01:00
|
|
|
|
2013-02-19 23:02:08 +01:00
|
|
|
if (hc) {
|
|
|
|
DumpDowntimes(fp, hc, CompatTypeHost);
|
|
|
|
DumpComments(fp, hc, CompatTypeHost);
|
2013-02-09 01:16:43 +01:00
|
|
|
}
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
2013-09-25 07:31:46 +02:00
|
|
|
void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host)
|
2012-06-27 18:43:34 +02:00
|
|
|
{
|
2013-03-02 09:07:47 +01:00
|
|
|
fp << "define host {" << "\n"
|
|
|
|
<< "\t" << "host_name" << "\t" << host->GetName() << "\n"
|
2013-10-02 21:09:13 +02:00
|
|
|
<< "\t" << "display_name" << "\t" << host->GetDisplayName() << "\n"
|
2013-08-29 19:48:54 +02:00
|
|
|
<< "\t" << "alias" << "\t" << host->GetDisplayName() << "\n";
|
2013-02-26 12:37:25 +01:00
|
|
|
|
2013-10-02 21:09:13 +02:00
|
|
|
Dictionary::Ptr macros = host->GetMacros();
|
|
|
|
|
|
|
|
if (macros) {
|
|
|
|
fp << "\t" << "address" << "\t" << macros->Get("address") << "\n"
|
|
|
|
<< "\t" << "address6" << "\t" << macros->Get("address6") << "\n";
|
|
|
|
}
|
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
std::set<Host::Ptr> parents = host->GetParentHosts();
|
2013-02-26 12:37:25 +01:00
|
|
|
|
2013-02-27 12:44:51 +01:00
|
|
|
if (!parents.empty()) {
|
|
|
|
fp << "\t" << "parents" << "\t";
|
|
|
|
DumpNameList(fp, parents);
|
|
|
|
fp << "\n";
|
2013-02-26 12:37:25 +01:00
|
|
|
}
|
|
|
|
|
2013-09-25 09:12:15 +02:00
|
|
|
Service::Ptr hc = host->GetCheckService();
|
2013-02-26 12:37:25 +01:00
|
|
|
if (hc) {
|
|
|
|
ObjectLock olock(hc);
|
|
|
|
|
2013-03-09 00:00:43 +01:00
|
|
|
fp << "\t" << "check_interval" << "\t" << hc->GetCheckInterval() / 60.0 << "\n"
|
|
|
|
<< "\t" << "retry_interval" << "\t" << hc->GetRetryInterval() / 60.0 << "\n"
|
2013-02-26 12:37:25 +01:00
|
|
|
<< "\t" << "max_check_attempts" << "\t" << hc->GetMaxCheckAttempts() << "\n"
|
|
|
|
<< "\t" << "active_checks_enabled" << "\t" << (hc->GetEnableActiveChecks() ? 1 : 0) << "\n"
|
|
|
|
<< "\t" << "passive_checks_enabled" << "\t" << (hc->GetEnablePassiveChecks() ? 1 : 0) << "\n"
|
|
|
|
<< "\t" << "notifications_enabled" << "\t" << (hc->GetEnableNotifications() ? 1 : 0) << "\n"
|
|
|
|
<< "\t" << "notification_options" << "\t" << "d,u,r" << "\n"
|
2013-10-16 15:20:14 +02:00
|
|
|
<< "\t" << "notification_interval" << "\t" << 1 << "\n"
|
|
|
|
<< "\t" << "event_handler_enabled" << "\t" << (hc->GetEnableEventHandler() ? 1 : 0) << "\n";
|
2013-07-02 10:24:27 +02:00
|
|
|
|
|
|
|
CheckCommand::Ptr checkcommand = hc->GetCheckCommand();
|
|
|
|
if (checkcommand)
|
|
|
|
fp << "\t" << "check_command" << "\t" << "check_" << checkcommand->GetName() << "\n";
|
|
|
|
|
|
|
|
EventCommand::Ptr eventcommand = hc->GetEventCommand();
|
2013-10-16 15:20:14 +02:00
|
|
|
if (eventcommand)
|
|
|
|
fp << "\t" << "event_handler" << "\t" << "event_" << eventcommand->GetName() << "\n";
|
2013-10-02 21:09:13 +02:00
|
|
|
|
|
|
|
TimePeriod::Ptr check_period = hc->GetCheckPeriod();
|
|
|
|
if (check_period)
|
|
|
|
fp << "\t" << "check_period" << "\t" << check_period->GetName() << "\n";
|
|
|
|
|
|
|
|
fp << "\t" << "contacts" << "\t";
|
|
|
|
DumpNameList(fp, CompatUtility::GetServiceNotificationUsers(hc));
|
|
|
|
fp << "\n";
|
|
|
|
|
|
|
|
fp << "\t" << "contact_groups" << "\t";
|
|
|
|
DumpNameList(fp, CompatUtility::GetServiceNotificationUserGroups(hc));
|
|
|
|
fp << "\n";
|
|
|
|
|
|
|
|
fp << "\t" << "initial_state" << "\t" << "o" << "\n"
|
|
|
|
<< "\t" << "low_flap_threshold" << "\t" << hc->GetFlappingThreshold() << "\n"
|
|
|
|
<< "\t" << "high_flap_threshold" << "\t" << hc->GetFlappingThreshold() << "\n"
|
|
|
|
<< "\t" << "process_perf_data" << "\t" << 1 << "\n"
|
|
|
|
<< "\t" << "check_freshness" << "\t" << 1 << "\n";
|
|
|
|
|
2013-02-28 10:26:01 +01:00
|
|
|
} else {
|
|
|
|
fp << "\t" << "check_interval" << "\t" << 60 << "\n"
|
|
|
|
<< "\t" << "retry_interval" << "\t" << 60 << "\n"
|
|
|
|
<< "\t" << "max_check_attempts" << "\t" << 1 << "\n"
|
|
|
|
<< "\t" << "active_checks_enabled" << "\t" << 0 << "\n"
|
|
|
|
<< "\t" << "passive_checks_enabled" << "\t" << 0 << "\n"
|
|
|
|
<< "\t" << "notifications_enabled" << "\t" << 0 << "\n";
|
|
|
|
|
2012-07-09 12:44:31 +02:00
|
|
|
}
|
|
|
|
|
2013-10-03 17:59:17 +02:00
|
|
|
fp << "\t" << "host_groups" << "\t";
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
Array::Ptr groups = host->GetGroups();
|
|
|
|
|
|
|
|
if (groups) {
|
|
|
|
ObjectLock olock(groups);
|
|
|
|
|
|
|
|
BOOST_FOREACH(const String& name, groups) {
|
|
|
|
HostGroup::Ptr hg = HostGroup::GetByName(name);
|
|
|
|
|
|
|
|
if (hg) {
|
|
|
|
if (!first)
|
|
|
|
fp << ",";
|
|
|
|
else
|
|
|
|
first = false;
|
|
|
|
|
|
|
|
fp << hg->GetName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fp << "\n";
|
2013-10-02 21:09:13 +02:00
|
|
|
|
2013-07-01 13:46:50 +02:00
|
|
|
DumpCustomAttributes(fp, host);
|
|
|
|
|
2012-07-09 12:44:31 +02:00
|
|
|
fp << "\t" << "}" << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\n";
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
2013-09-25 07:31:46 +02:00
|
|
|
void StatusDataWriter::DumpServiceStatusAttrs(std::ostream& fp, const Service::Ptr& service, CompatObjectType type)
|
2012-06-27 18:43:34 +02:00
|
|
|
{
|
2013-07-23 09:12:38 +02:00
|
|
|
Dictionary::Ptr attrs = CompatUtility::GetServiceStatusAttributes(service, type);
|
|
|
|
|
|
|
|
fp << "\t" << "check_command=" << attrs->Get("check_command") << "\n"
|
|
|
|
<< "\t" << "event_handler=" << attrs->Get("event_handler") << "\n"
|
|
|
|
<< "\t" << "check_period=" << attrs->Get("check_period") << "\n"
|
2013-08-20 11:06:04 +02:00
|
|
|
<< "\t" << "check_interval=" << static_cast<double>(attrs->Get("check_interval")) << "\n"
|
|
|
|
<< "\t" << "retry_interval=" << static_cast<double>(attrs->Get("retry_interval")) << "\n"
|
2013-07-23 09:12:38 +02:00
|
|
|
<< "\t" << "has_been_checked=" << attrs->Get("has_been_checked") << "\n"
|
|
|
|
<< "\t" << "should_be_scheduled=" << attrs->Get("should_be_scheduled") << "\n"
|
2013-08-20 11:06:04 +02:00
|
|
|
<< "\t" << "check_execution_time=" << static_cast<double>(attrs->Get("check_execution_time")) << "\n"
|
|
|
|
<< "\t" << "check_latency=" << static_cast<double>(attrs->Get("check_latency")) << "\n"
|
2013-07-23 09:12:38 +02:00
|
|
|
<< "\t" << "current_state=" << attrs->Get("current_state") << "\n"
|
|
|
|
<< "\t" << "state_type=" << attrs->Get("state_type") << "\n"
|
|
|
|
<< "\t" << "plugin_output=" << attrs->Get("plugin_output") << "\n"
|
|
|
|
<< "\t" << "long_plugin_output=" << attrs->Get("long_plugin_output") << "\n"
|
|
|
|
<< "\t" << "performance_data=" << attrs->Get("performance_data") << "\n"
|
2013-09-26 21:53:43 +02:00
|
|
|
<< "\t" << "check_source=" << attrs->Get("check_source") << "\n"
|
2013-07-25 09:45:40 +02:00
|
|
|
<< "\t" << "last_check=" << static_cast<long>(attrs->Get("last_check")) << "\n"
|
|
|
|
<< "\t" << "next_check=" << static_cast<long>(attrs->Get("next_check")) << "\n"
|
2013-07-23 09:12:38 +02:00
|
|
|
<< "\t" << "current_attempt=" << attrs->Get("current_attempt") << "\n"
|
|
|
|
<< "\t" << "max_attempts=" << attrs->Get("max_attempts") << "\n"
|
2013-07-25 09:45:40 +02:00
|
|
|
<< "\t" << "last_state_change=" << static_cast<long>(attrs->Get("last_state_change")) << "\n"
|
|
|
|
<< "\t" << "last_hard_state_change=" << static_cast<long>(attrs->Get("last_hard_state_change")) << "\n"
|
|
|
|
<< "\t" << "last_time_ok=" << static_cast<long>(attrs->Get("last_time_ok")) << "\n"
|
|
|
|
<< "\t" << "last_time_warn=" << static_cast<long>(attrs->Get("last_time_warn")) << "\n"
|
|
|
|
<< "\t" << "last_time_critical=" << static_cast<long>(attrs->Get("last_time_critical")) << "\n"
|
|
|
|
<< "\t" << "last_time_unknown=" << static_cast<long>(attrs->Get("last_time_unknown")) << "\n"
|
|
|
|
<< "\t" << "last_update=" << static_cast<long>(attrs->Get("last_update")) << "\n"
|
2013-07-23 09:12:38 +02:00
|
|
|
<< "\t" << "notifications_enabled=" << attrs->Get("notifications_enabled") << "\n"
|
|
|
|
<< "\t" << "active_checks_enabled=" << attrs->Get("active_checks_enabled") << "\n"
|
|
|
|
<< "\t" << "passive_checks_enabled=" << attrs->Get("passive_checks_enabled") << "\n"
|
|
|
|
<< "\t" << "flap_detection_enabled=" << attrs->Get("flap_detection_enabled") << "\n"
|
|
|
|
<< "\t" << "is_flapping=" << attrs->Get("is_flapping") << "\n"
|
|
|
|
<< "\t" << "percent_state_change=" << attrs->Get("percent_state_change") << "\n"
|
|
|
|
<< "\t" << "problem_has_been_acknowledged=" << attrs->Get("problem_has_been_acknowledged") << "\n"
|
|
|
|
<< "\t" << "acknowledgement_type=" << attrs->Get("acknowledgement_type") << "\n"
|
|
|
|
<< "\t" << "acknowledgement_end_time=" << attrs->Get("acknowledgement_end_time") << "\n"
|
|
|
|
<< "\t" << "scheduled_downtime_depth=" << attrs->Get("scheduled_downtime_depth") << "\n"
|
2013-07-25 09:45:40 +02:00
|
|
|
<< "\t" << "last_notification=" << static_cast<long>(attrs->Get("last_notification")) << "\n"
|
|
|
|
<< "\t" << "next_notification=" << static_cast<long>(attrs->Get("next_notification")) << "\n"
|
2013-10-16 11:46:54 +02:00
|
|
|
<< "\t" << "current_notification_number=" << attrs->Get("current_notification_number") << "\n"
|
|
|
|
<< "\t" << "modified_attributes=" << attrs->Get("modified_attributes") << "\n";
|
2013-02-07 20:29:35 +01:00
|
|
|
}
|
|
|
|
|
2013-09-25 07:31:46 +02:00
|
|
|
void StatusDataWriter::DumpServiceStatus(std::ostream& fp, const Service::Ptr& service)
|
2013-02-07 20:29:35 +01:00
|
|
|
{
|
2013-03-02 09:07:47 +01:00
|
|
|
Host::Ptr host = service->GetHost();
|
2013-02-19 23:02:08 +01:00
|
|
|
|
2013-02-07 20:29:35 +01:00
|
|
|
fp << "servicestatus {" << "\n"
|
2013-03-02 09:07:47 +01:00
|
|
|
<< "\t" << "host_name=" << host->GetName() << "\n"
|
|
|
|
<< "\t" << "service_description=" << service->GetShortName() << "\n";
|
2013-02-07 20:29:35 +01:00
|
|
|
|
2013-03-04 15:52:42 +01:00
|
|
|
{
|
|
|
|
ObjectLock olock(service);
|
|
|
|
DumpServiceStatusAttrs(fp, service, CompatTypeService);
|
|
|
|
}
|
2013-02-07 20:29:35 +01:00
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
fp << "\t" << "}" << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\n";
|
2013-01-29 14:19:54 +01:00
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
DumpDowntimes(fp, service, CompatTypeService);
|
|
|
|
DumpComments(fp, service, CompatTypeService);
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
2013-09-25 07:31:46 +02:00
|
|
|
void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& service)
|
2012-06-27 18:43:34 +02:00
|
|
|
{
|
2013-03-02 09:07:47 +01:00
|
|
|
Host::Ptr host = service->GetHost();
|
2013-02-19 23:02:08 +01:00
|
|
|
|
2013-07-01 19:04:08 +02:00
|
|
|
String check_period_str;
|
|
|
|
TimePeriod::Ptr check_period = service->GetCheckPeriod();
|
|
|
|
if (check_period)
|
|
|
|
check_period_str = check_period->GetName();
|
|
|
|
else
|
|
|
|
check_period_str = "24x7";
|
|
|
|
|
2013-03-20 10:08:27 +01:00
|
|
|
double notification_interval = -1;
|
|
|
|
BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
|
|
|
|
if (notification_interval == -1 || notification->GetNotificationInterval() < notification_interval)
|
|
|
|
notification_interval = notification->GetNotificationInterval();
|
|
|
|
}
|
|
|
|
|
2013-03-20 11:11:46 +01:00
|
|
|
if (notification_interval == -1)
|
|
|
|
notification_interval = 60;
|
|
|
|
|
2013-02-19 23:02:08 +01:00
|
|
|
{
|
|
|
|
ObjectLock olock(service);
|
|
|
|
|
|
|
|
fp << "define service {" << "\n"
|
2013-03-02 09:07:47 +01:00
|
|
|
<< "\t" << "host_name" << "\t" << host->GetName() << "\n"
|
|
|
|
<< "\t" << "service_description" << "\t" << service->GetShortName() << "\n"
|
2013-02-19 23:02:08 +01:00
|
|
|
<< "\t" << "display_name" << "\t" << service->GetDisplayName() << "\n"
|
2013-07-01 19:04:08 +02:00
|
|
|
<< "\t" << "check_period" << "\t" << check_period_str << "\n"
|
2013-02-19 23:02:08 +01:00
|
|
|
<< "\t" << "check_interval" << "\t" << service->GetCheckInterval() / 60.0 << "\n"
|
|
|
|
<< "\t" << "retry_interval" << "\t" << service->GetRetryInterval() / 60.0 << "\n"
|
2013-07-01 19:04:08 +02:00
|
|
|
<< "\t" << "max_check_attempts" << "\t" << service->GetMaxCheckAttempts() << "\n"
|
2013-02-19 23:02:08 +01:00
|
|
|
<< "\t" << "active_checks_enabled" << "\t" << (service->GetEnableActiveChecks() ? 1 : 0) << "\n"
|
|
|
|
<< "\t" << "passive_checks_enabled" << "\t" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\n"
|
2013-07-01 19:04:08 +02:00
|
|
|
<< "\t" << "flap_detection_enabled" << "\t" << (service->GetEnableFlapping() ? 1 : 0) << "\n"
|
2013-10-26 09:41:45 +02:00
|
|
|
<< "\t" << "is_volatile" << "\t" << (service->GetVolatile() ? 1 : 0) << "\n"
|
2013-02-26 12:37:25 +01:00
|
|
|
<< "\t" << "notifications_enabled" << "\t" << (service->GetEnableNotifications() ? 1 : 0) << "\n"
|
|
|
|
<< "\t" << "notification_options" << "\t" << "u,w,c,r" << "\n"
|
2013-10-16 15:20:14 +02:00
|
|
|
<< "\t" << "notification_interval" << "\t" << notification_interval / 60.0 << "\n"
|
|
|
|
<< "\t" << "event_handler_enabled" << "\t" << (service->GetEnableEventHandler() ? 1 : 0) << "\n";
|
2013-07-02 09:35:03 +02:00
|
|
|
|
2013-07-02 10:24:27 +02:00
|
|
|
CheckCommand::Ptr checkcommand = service->GetCheckCommand();
|
|
|
|
if (checkcommand)
|
|
|
|
fp << "\t" << "check_command" << "\t" << "check_" << checkcommand->GetName() << "\n";
|
|
|
|
|
|
|
|
EventCommand::Ptr eventcommand = service->GetEventCommand();
|
2013-10-16 15:20:14 +02:00
|
|
|
if (eventcommand)
|
|
|
|
fp << "\t" << "event_handler" << "\t" << "event_" << eventcommand->GetName() << "\n";
|
2013-10-03 17:30:58 +02:00
|
|
|
|
|
|
|
TimePeriod::Ptr check_period = service->GetCheckPeriod();
|
|
|
|
if (check_period)
|
|
|
|
fp << "\t" << "check_period" << "\t" << check_period->GetName() << "\n";
|
|
|
|
|
|
|
|
fp << "\t" << "contacts" << "\t";
|
|
|
|
DumpNameList(fp, CompatUtility::GetServiceNotificationUsers(service));
|
|
|
|
fp << "\n";
|
|
|
|
|
|
|
|
fp << "\t" << "contact_groups" << "\t";
|
|
|
|
DumpNameList(fp, CompatUtility::GetServiceNotificationUserGroups(service));
|
|
|
|
fp << "\n";
|
|
|
|
|
|
|
|
fp << "\t" << "initial_state" << "\t" << "o" << "\n"
|
|
|
|
<< "\t" << "low_flap_threshold" << "\t" << service->GetFlappingThreshold() << "\n"
|
|
|
|
<< "\t" << "high_flap_threshold" << "\t" << service->GetFlappingThreshold() << "\n"
|
|
|
|
<< "\t" << "process_perf_data" << "\t" << 1 << "\n"
|
|
|
|
<< "\t" << "check_freshness" << "\t" << 1 << "\n";
|
2013-02-19 23:02:08 +01:00
|
|
|
}
|
|
|
|
|
2013-10-03 17:59:17 +02:00
|
|
|
fp << "\t" << "service_groups" << "\t";
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
Array::Ptr groups = service->GetGroups();
|
|
|
|
|
|
|
|
if (groups) {
|
|
|
|
ObjectLock olock(groups);
|
|
|
|
|
|
|
|
BOOST_FOREACH(const String& name, groups) {
|
|
|
|
ServiceGroup::Ptr sg = ServiceGroup::GetByName(name);
|
|
|
|
|
|
|
|
if (sg) {
|
|
|
|
if (!first)
|
|
|
|
fp << ",";
|
|
|
|
else
|
|
|
|
first = false;
|
|
|
|
|
|
|
|
fp << sg->GetName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fp << "\n";
|
|
|
|
|
2013-07-01 13:46:50 +02:00
|
|
|
DumpCustomAttributes(fp, service);
|
|
|
|
|
|
|
|
fp << "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
BOOST_FOREACH(const Service::Ptr& parent, service->GetParentServices()) {
|
|
|
|
Host::Ptr host = service->GetHost();
|
|
|
|
|
|
|
|
Host::Ptr parent_host = parent->GetHost();
|
|
|
|
|
|
|
|
if (!parent_host)
|
|
|
|
continue;
|
2013-02-18 14:40:24 +01:00
|
|
|
|
2013-02-06 22:41:40 +01:00
|
|
|
fp << "define servicedependency {" << "\n"
|
2013-03-02 09:07:47 +01:00
|
|
|
<< "\t" << "dependent_host_name" << "\t" << host->GetName() << "\n"
|
2013-02-08 15:38:22 +01:00
|
|
|
<< "\t" << "dependent_service_description" << "\t" << service->GetShortName() << "\n"
|
2013-03-02 09:07:47 +01:00
|
|
|
<< "\t" << "host_name" << "\t" << parent_host->GetName() << "\n"
|
2013-08-05 17:01:40 +02:00
|
|
|
<< "\t" << "service_description" << "\t" << parent->GetShortName() << "\n"
|
2013-02-06 22:41:40 +01:00
|
|
|
<< "\t" << "execution_failure_criteria" << "\t" << "n" << "\n"
|
2013-02-07 20:29:35 +01:00
|
|
|
<< "\t" << "notification_failure_criteria" << "\t" << "w,u,c" << "\n"
|
2013-02-06 22:41:40 +01:00
|
|
|
<< "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
|
|
|
}
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
2013-09-25 07:31:46 +02:00
|
|
|
void StatusDataWriter::DumpCustomAttributes(std::ostream& fp, const DynamicObject::Ptr& object)
|
2013-07-01 13:46:50 +02:00
|
|
|
{
|
2013-07-12 15:13:05 +02:00
|
|
|
Dictionary::Ptr custom = object->GetCustom();
|
2013-07-01 13:46:50 +02:00
|
|
|
|
|
|
|
if (!custom)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ObjectLock olock(custom);
|
2013-11-30 17:42:50 +01:00
|
|
|
BOOST_FOREACH(const Dictionary::Pair& kv, custom) {
|
2013-07-01 13:46:50 +02:00
|
|
|
fp << "\t";
|
|
|
|
|
2013-11-30 17:42:50 +01:00
|
|
|
if (kv.first != "notes" && kv.first != "action_url" && kv.first != "notes_url" &&
|
|
|
|
kv.first != "icon_image" && kv.first != "icon_image_alt" && kv.first != "statusmap_image" && kv.first != "2d_coords")
|
2013-07-01 13:46:50 +02:00
|
|
|
fp << "_";
|
|
|
|
|
2013-11-30 17:42:50 +01:00
|
|
|
fp << kv.first << "\t" << kv.second << "\n";
|
2013-07-01 13:46:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-27 18:43:34 +02:00
|
|
|
/**
|
|
|
|
* Periodically writes the status.dat and objects.cache files.
|
|
|
|
*/
|
2013-09-25 07:31:46 +02:00
|
|
|
void StatusDataWriter::StatusTimerHandler(void)
|
2012-06-27 18:43:34 +02:00
|
|
|
{
|
2013-03-16 21:18:53 +01:00
|
|
|
Log(LogInformation, "compat", "Writing compat status information");
|
2012-07-18 11:15:39 +02:00
|
|
|
|
2012-09-28 14:26:01 +02:00
|
|
|
String statuspath = GetStatusPath();
|
|
|
|
String objectspath = GetObjectsPath();
|
|
|
|
String statuspathtmp = statuspath + ".tmp"; /* XXX make this a global definition */
|
|
|
|
String objectspathtmp = objectspath + ".tmp";
|
|
|
|
|
2013-03-17 20:19:29 +01:00
|
|
|
std::ofstream statusfp;
|
|
|
|
statusfp.open(statuspathtmp.CStr(), std::ofstream::out | std::ofstream::trunc);
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2012-07-25 12:59:17 +02:00
|
|
|
statusfp << std::fixed;
|
|
|
|
|
2012-06-29 14:14:51 +02:00
|
|
|
statusfp << "# Icinga status file" << "\n"
|
|
|
|
<< "# This file is auto-generated. Do not modify this file." << "\n"
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
statusfp << "info {" << "\n"
|
2012-08-03 18:17:47 +02:00
|
|
|
<< "\t" << "created=" << Utility::GetTime() << "\n"
|
2013-10-09 08:46:10 +02:00
|
|
|
<< "\t" << "version=" << Application::GetVersion() << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
statusfp << "programstatus {" << "\n"
|
2013-09-24 09:59:04 +02:00
|
|
|
<< "\t" << "icinga_pid=" << Utility::GetPid() << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "daemon_mode=1" << "\n"
|
2013-10-26 09:41:45 +02:00
|
|
|
<< "\t" << "program_start=" << static_cast<long>(Application::GetStartTime()) << "\n"
|
2013-10-08 11:57:35 +02:00
|
|
|
<< "\t" << "active_service_checks_enabled=" << (IcingaApplication::GetInstance()->GetEnableChecks() ? 1 : 0) << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "passive_service_checks_enabled=1" << "\n"
|
2013-02-26 12:37:25 +01:00
|
|
|
<< "\t" << "active_host_checks_enabled=1" << "\n"
|
|
|
|
<< "\t" << "passive_host_checks_enabled=1" << "\n"
|
2013-10-08 11:57:35 +02:00
|
|
|
<< "\t" << "check_service_freshness=1" << "\n"
|
|
|
|
<< "\t" << "check_host_freshness=1" << "\n"
|
|
|
|
<< "\t" << "enable_notifications=" << (IcingaApplication::GetInstance()->GetEnableNotifications() ? 1 : 0) << "\n"
|
|
|
|
<< "\t" << "enable_flap_detection=" << (IcingaApplication::GetInstance()->GetEnableFlapping() ? 1 : 0) << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "enable_failure_prediction=0" << "\n"
|
2013-10-08 11:57:35 +02:00
|
|
|
<< "\t" << "process_performance_data=" << (IcingaApplication::GetInstance()->GetEnablePerfdata() ? 1 : 0) << "\n"
|
2013-01-28 09:01:47 +01:00
|
|
|
<< "\t" << "active_scheduled_service_check_stats=" << CIB::GetActiveChecksStatistics(60) << "," << CIB::GetActiveChecksStatistics(5 * 60) << "," << CIB::GetActiveChecksStatistics(15 * 60) << "\n"
|
|
|
|
<< "\t" << "passive_service_check_stats=" << CIB::GetPassiveChecksStatistics(60) << "," << CIB::GetPassiveChecksStatistics(5 * 60) << "," << CIB::GetPassiveChecksStatistics(15 * 60) << "\n"
|
2013-02-09 01:16:43 +01:00
|
|
|
<< "\t" << "next_downtime_id=" << Service::GetNextDowntimeID() << "\n"
|
|
|
|
<< "\t" << "next_comment_id=" << Service::GetNextCommentID() << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
2012-06-27 23:38:50 +02:00
|
|
|
|
2013-03-17 20:19:29 +01:00
|
|
|
std::ofstream objectfp;
|
|
|
|
objectfp.open(objectspathtmp.CStr(), std::ofstream::out | std::ofstream::trunc);
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2012-07-25 12:59:17 +02:00
|
|
|
objectfp << std::fixed;
|
|
|
|
|
2012-09-25 11:38:40 +02:00
|
|
|
objectfp << "# Icinga objects cache file" << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "# This file is auto-generated. Do not modify this file." << "\n"
|
|
|
|
<< "\n";
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
2013-03-16 21:18:53 +01:00
|
|
|
std::ostringstream tempstatusfp;
|
2013-02-26 10:13:54 +01:00
|
|
|
tempstatusfp << std::fixed;
|
2013-02-24 12:47:24 +01:00
|
|
|
DumpHostStatus(tempstatusfp, host);
|
|
|
|
statusfp << tempstatusfp.str();
|
2013-02-26 10:13:54 +01:00
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
std::ostringstream tempobjectfp;
|
2013-02-26 10:13:54 +01:00
|
|
|
tempobjectfp << std::fixed;
|
|
|
|
DumpHostObject(tempobjectfp, host);
|
2013-02-24 12:47:24 +01:00
|
|
|
objectfp << tempobjectfp.str();
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
BOOST_FOREACH(const HostGroup::Ptr& hg, DynamicType::GetObjects<HostGroup>()) {
|
2013-03-16 21:18:53 +01:00
|
|
|
std::ostringstream tempobjectfp;
|
2013-02-26 10:13:54 +01:00
|
|
|
tempobjectfp << std::fixed;
|
2013-02-24 12:47:24 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
tempobjectfp << "define hostgroup {" << "\n"
|
2013-07-01 13:54:38 +02:00
|
|
|
<< "\t" << "hostgroup_name" << "\t" << hg->GetName() << "\n";
|
|
|
|
|
|
|
|
DumpCustomAttributes(tempobjectfp, hg);
|
2013-02-18 14:40:24 +01:00
|
|
|
|
2013-02-24 12:47:24 +01:00
|
|
|
tempobjectfp << "\t" << "members" << "\t";
|
2013-03-02 09:07:47 +01:00
|
|
|
DumpNameList(tempobjectfp, hg->GetMembers());
|
2013-02-24 12:47:24 +01:00
|
|
|
tempobjectfp << "\n"
|
2013-02-28 10:26:01 +01:00
|
|
|
<< "\t" << "}" << "\n";
|
2013-02-24 12:47:24 +01:00
|
|
|
|
|
|
|
objectfp << tempobjectfp.str();
|
2012-06-30 13:39:55 +02:00
|
|
|
}
|
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
|
2013-03-16 21:18:53 +01:00
|
|
|
std::ostringstream tempstatusfp;
|
2013-02-26 10:13:54 +01:00
|
|
|
tempstatusfp << std::fixed;
|
|
|
|
DumpServiceStatus(tempstatusfp, service);
|
2013-02-24 12:47:24 +01:00
|
|
|
statusfp << tempstatusfp.str();
|
2013-02-26 10:13:54 +01:00
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
std::ostringstream tempobjectfp;
|
2013-02-26 10:13:54 +01:00
|
|
|
tempobjectfp << std::fixed;
|
|
|
|
DumpServiceObject(tempobjectfp, service);
|
2013-02-24 12:47:24 +01:00
|
|
|
objectfp << tempobjectfp.str();
|
2013-02-18 23:44:24 +01:00
|
|
|
}
|
2012-06-30 13:39:55 +02:00
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
BOOST_FOREACH(const ServiceGroup::Ptr& sg, DynamicType::GetObjects<ServiceGroup>()) {
|
2013-03-16 21:18:53 +01:00
|
|
|
std::ostringstream tempobjectfp;
|
2013-02-26 10:13:54 +01:00
|
|
|
tempobjectfp << std::fixed;
|
2013-02-24 12:47:24 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
tempobjectfp << "define servicegroup {" << "\n"
|
2013-07-01 13:54:38 +02:00
|
|
|
<< "\t" << "servicegroup_name" << "\t" << sg->GetName() << "\n";
|
|
|
|
|
|
|
|
DumpCustomAttributes(tempobjectfp, sg);
|
2013-02-18 14:40:24 +01:00
|
|
|
|
2013-02-24 12:47:24 +01:00
|
|
|
tempobjectfp << "\t" << "members" << "\t";
|
2013-02-18 14:40:24 +01:00
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
std::vector<String> sglist;
|
2013-03-02 09:07:47 +01:00
|
|
|
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
|
|
|
Host::Ptr host = service->GetHost();
|
2013-02-19 23:02:08 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
sglist.push_back(host->GetName());
|
|
|
|
sglist.push_back(service->GetShortName());
|
2013-02-18 14:40:24 +01:00
|
|
|
}
|
2013-02-18 23:44:24 +01:00
|
|
|
|
2013-02-24 12:47:24 +01:00
|
|
|
DumpStringList(tempobjectfp, sglist);
|
2013-02-18 23:44:24 +01:00
|
|
|
|
2013-02-24 12:47:24 +01:00
|
|
|
tempobjectfp << "\n"
|
2013-02-18 23:44:24 +01:00
|
|
|
<< "}" << "\n";
|
2013-02-24 12:47:24 +01:00
|
|
|
|
|
|
|
objectfp << tempobjectfp.str();
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
BOOST_FOREACH(const User::Ptr& user, DynamicType::GetObjects<User>()) {
|
2013-03-16 21:18:53 +01:00
|
|
|
std::ostringstream tempobjectfp;
|
2013-02-28 10:50:20 +01:00
|
|
|
tempobjectfp << std::fixed;
|
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
tempobjectfp << "define contact {" << "\n"
|
|
|
|
<< "\t" << "contact_name" << "\t" << user->GetName() << "\n"
|
|
|
|
<< "\t" << "alias" << "\t" << user->GetDisplayName() << "\n"
|
|
|
|
<< "\t" << "service_notification_options" << "\t" << "w,u,c,r,f,s" << "\n"
|
|
|
|
<< "\t" << "host_notification_options" << "\t" << "d,u,r,f,s" << "\n"
|
|
|
|
<< "\t" << "host_notifications_enabled" << "\t" << 1 << "\n"
|
|
|
|
<< "\t" << "service_notifications_enabled" << "\t" << 1 << "\n"
|
|
|
|
<< "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
2013-02-28 10:50:20 +01:00
|
|
|
|
|
|
|
objectfp << tempobjectfp.str();
|
|
|
|
}
|
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
BOOST_FOREACH(const UserGroup::Ptr& ug, DynamicType::GetObjects<UserGroup>()) {
|
2013-03-16 21:18:53 +01:00
|
|
|
std::ostringstream tempobjectfp;
|
2013-02-28 10:50:20 +01:00
|
|
|
tempobjectfp << std::fixed;
|
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
tempobjectfp << "define contactgroup {" << "\n"
|
|
|
|
<< "\t" << "contactgroup_name" << "\t" << ug->GetName() << "\n"
|
|
|
|
<< "\t" << "alias" << "\t" << ug->GetDisplayName() << "\n";
|
2013-02-28 10:50:20 +01:00
|
|
|
|
|
|
|
tempobjectfp << "\t" << "members" << "\t";
|
2013-03-02 09:07:47 +01:00
|
|
|
DumpNameList(tempobjectfp, ug->GetMembers());
|
2013-02-28 10:50:20 +01:00
|
|
|
tempobjectfp << "\n"
|
|
|
|
<< "\t" << "}" << "\n";
|
|
|
|
|
|
|
|
objectfp << tempobjectfp.str();
|
|
|
|
}
|
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
BOOST_FOREACH(const Command::Ptr& command, DynamicType::GetObjects<CheckCommand>()) {
|
2013-07-02 08:44:03 +02:00
|
|
|
DumpCommand(objectfp, command);
|
|
|
|
}
|
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
BOOST_FOREACH(const Command::Ptr& command, DynamicType::GetObjects<NotificationCommand>()) {
|
2013-07-02 08:44:03 +02:00
|
|
|
DumpCommand(objectfp, command);
|
|
|
|
}
|
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
BOOST_FOREACH(const Command::Ptr& command, DynamicType::GetObjects<EventCommand>()) {
|
2013-07-02 08:44:03 +02:00
|
|
|
DumpCommand(objectfp, command);
|
|
|
|
}
|
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
BOOST_FOREACH(const TimePeriod::Ptr& tp, DynamicType::GetObjects<TimePeriod>()) {
|
2013-07-02 08:44:03 +02:00
|
|
|
DumpTimePeriod(objectfp, tp);
|
|
|
|
}
|
|
|
|
|
2012-06-27 18:43:34 +02:00
|
|
|
statusfp.close();
|
2012-10-17 11:35:06 +02:00
|
|
|
objectfp.close();
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
_unlink(statuspath.CStr());
|
|
|
|
_unlink(objectspath.CStr());
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
statusfp.close();
|
2013-03-11 13:45:08 +01:00
|
|
|
if (rename(statuspathtmp.CStr(), statuspath.CStr()) < 0) {
|
|
|
|
BOOST_THROW_EXCEPTION(posix_error()
|
2013-03-18 17:04:22 +01:00
|
|
|
<< boost::errinfo_api_function("rename")
|
|
|
|
<< boost::errinfo_errno(errno)
|
|
|
|
<< boost::errinfo_file_name(statuspathtmp));
|
2013-03-11 13:45:08 +01:00
|
|
|
}
|
2012-06-27 18:43:34 +02:00
|
|
|
|
|
|
|
objectfp.close();
|
2013-03-11 13:45:08 +01:00
|
|
|
if (rename(objectspathtmp.CStr(), objectspath.CStr()) < 0) {
|
|
|
|
BOOST_THROW_EXCEPTION(posix_error()
|
2013-03-18 17:04:22 +01:00
|
|
|
<< boost::errinfo_api_function("rename")
|
|
|
|
<< boost::errinfo_errno(errno)
|
|
|
|
<< boost::errinfo_file_name(objectspathtmp));
|
2013-03-11 13:45:08 +01:00
|
|
|
}
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
2013-08-20 11:06:04 +02:00
|
|
|
|