2012-06-27 18:43:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
|
|
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "i2-compat.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
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).
|
|
|
|
*/
|
|
|
|
|
2012-09-28 14:26:01 +02:00
|
|
|
const String CompatComponent::DefaultStatusPath = Application::GetLocalStateDir() + "/status.dat";
|
|
|
|
const String CompatComponent::DefaultObjectsPath = Application::GetLocalStateDir() + "/objects.cache";
|
2013-01-21 13:08:08 +01:00
|
|
|
const String CompatComponent::DefaultCommandPath = Application::GetLocalStateDir() + "/icinga.cmd";
|
2012-09-28 14:26:01 +02:00
|
|
|
|
|
|
|
/**
|
2013-01-21 13:08:08 +01:00
|
|
|
* Retrieves the status.dat path.
|
|
|
|
*
|
2012-09-28 14:26:01 +02:00
|
|
|
* @returns statuspath from config, or static default
|
|
|
|
*/
|
|
|
|
String CompatComponent::GetStatusPath(void) const
|
|
|
|
{
|
2013-01-21 13:08:08 +01:00
|
|
|
Value statusPath = GetConfig()->Get("status_path");
|
|
|
|
if (statusPath.IsEmpty())
|
2012-09-28 14:26:01 +02:00
|
|
|
return DefaultStatusPath;
|
|
|
|
else
|
2013-01-21 13:08:08 +01:00
|
|
|
return statusPath;
|
2012-09-28 14:26:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-21 13:08:08 +01:00
|
|
|
* Retrieves the objects.cache path.
|
|
|
|
*
|
2012-09-28 14:26:01 +02:00
|
|
|
* @returns objectspath from config, or static default
|
|
|
|
*/
|
|
|
|
String CompatComponent::GetObjectsPath(void) const
|
|
|
|
{
|
2013-01-21 13:08:08 +01:00
|
|
|
Value objectsPath = GetConfig()->Get("objects_path");
|
|
|
|
if (objectsPath.IsEmpty())
|
|
|
|
return DefaultObjectsPath;
|
|
|
|
else
|
|
|
|
return objectsPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the icinga.cmd path.
|
|
|
|
*
|
|
|
|
* @returns icinga.cmd path
|
|
|
|
*/
|
|
|
|
String CompatComponent::GetCommandPath(void) const
|
|
|
|
{
|
|
|
|
Value commandPath = GetConfig()->Get("command_path");
|
|
|
|
if (commandPath.IsEmpty())
|
|
|
|
return DefaultCommandPath;
|
|
|
|
else
|
|
|
|
return commandPath;
|
2012-09-28 14:26:01 +02:00
|
|
|
}
|
|
|
|
|
2012-06-27 18:43:34 +02:00
|
|
|
/**
|
|
|
|
* Starts the component.
|
|
|
|
*/
|
|
|
|
void CompatComponent::Start(void)
|
|
|
|
{
|
|
|
|
m_StatusTimer = boost::make_shared<Timer>();
|
|
|
|
m_StatusTimer->SetInterval(15);
|
|
|
|
m_StatusTimer->OnTimerExpired.connect(boost::bind(&CompatComponent::StatusTimerHandler, this));
|
|
|
|
m_StatusTimer->Start();
|
2012-07-09 16:22:38 +02:00
|
|
|
m_StatusTimer->Reschedule(0);
|
2013-01-21 13:08:08 +01:00
|
|
|
|
2013-01-22 08:47:56 +01:00
|
|
|
#ifndef _WIN32
|
2013-01-21 13:08:08 +01:00
|
|
|
m_CommandThread = thread(boost::bind(&CompatComponent::CommandPipeThread, this, GetCommandPath()));
|
|
|
|
m_CommandThread.detach();
|
2013-01-22 08:47:56 +01:00
|
|
|
#endif /* _WIN32 */
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops the component.
|
|
|
|
*/
|
|
|
|
void CompatComponent::Stop(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-22 08:47:56 +01:00
|
|
|
#ifndef _WIN32
|
2013-01-21 13:08:08 +01:00
|
|
|
void CompatComponent::CommandPipeThread(const String& commandPath)
|
|
|
|
{
|
2013-01-23 10:18:23 +01:00
|
|
|
struct stat statbuf;
|
|
|
|
bool fifo_ok = false;
|
2013-01-21 13:08:08 +01:00
|
|
|
|
2013-01-23 10:18:23 +01:00
|
|
|
if (lstat(commandPath.CStr(), &statbuf) >= 0) {
|
|
|
|
if (S_ISFIFO(statbuf.st_mode) && access(commandPath.CStr(), R_OK) >= 0) {
|
|
|
|
fifo_ok = true;
|
|
|
|
} else {
|
|
|
|
if (unlink(commandPath.CStr()) < 0)
|
|
|
|
throw_exception(PosixException("unlink() failed", errno));
|
|
|
|
}
|
|
|
|
}
|
2013-01-21 13:08:08 +01:00
|
|
|
|
2013-01-23 10:18:23 +01:00
|
|
|
|
|
|
|
if (!fifo_ok && mkfifo(commandPath.CStr(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
|
2013-01-21 13:08:08 +01:00
|
|
|
throw_exception(PosixException("mkfifo() failed", errno));
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
int fd = open(commandPath.CStr(), O_RDONLY);
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
throw_exception(PosixException("open() failed", errno));
|
|
|
|
|
|
|
|
FILE *fp = fdopen(fd, "r");
|
|
|
|
|
|
|
|
if (fp == NULL) {
|
|
|
|
close(fd);
|
|
|
|
throw_exception(PosixException("fdopen() failed", errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
char line[2048];
|
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), fp) != NULL) {
|
|
|
|
// remove trailing new-line
|
|
|
|
while (strlen(line) > 0 &&
|
|
|
|
(line[strlen(line) - 1] == '\r' || line[strlen(line) - 1] == '\n'))
|
|
|
|
line[strlen(line) - 1] = '\0';
|
|
|
|
|
|
|
|
String command = line;
|
|
|
|
Event::Post(boost::bind(&CompatComponent::ProcessCommand, this, command));
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompatComponent::ProcessCommand(const String& command)
|
|
|
|
{
|
2013-01-21 13:39:20 +01:00
|
|
|
if (command.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (command[0] != '[') {
|
|
|
|
Logger::Write(LogWarning, "compat", "Missing timestamp in command: " + command);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t pos = command.FindFirstOf("]");
|
|
|
|
|
|
|
|
if (pos == String::NPos) {
|
|
|
|
Logger::Write(LogWarning, "compat", "Missing timestamp in command: " + command);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String timestamp = command.SubStr(1, pos - 1);
|
|
|
|
String args = command.SubStr(pos + 2, String::NPos);
|
|
|
|
|
2013-01-21 13:45:27 +01:00
|
|
|
double ts = timestamp.ToDouble();
|
|
|
|
|
|
|
|
if (ts == 0) {
|
|
|
|
Logger::Write(LogWarning, "compat", "Invalid timestamp in command: " + command);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-21 13:39:20 +01:00
|
|
|
vector<String> argv = args.Split(is_any_of(";"));
|
|
|
|
|
|
|
|
if (argv.size() == 0) {
|
|
|
|
Logger::Write(LogWarning, "compat", "Missing arguments in command: " + command);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-22 08:34:29 +01:00
|
|
|
vector<String> argvExtra(argv.begin() + 1, argv.end());
|
2013-01-22 15:13:51 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
Logger::Write(LogInformation, "compat", "Executing external command: " + command);
|
|
|
|
|
|
|
|
ExternalCommand::Execute(ts, argv[0], argvExtra);
|
|
|
|
} catch (const exception& ex) {
|
|
|
|
stringstream msgbuf;
|
|
|
|
msgbuf << "External command failed: " << ex.what();
|
|
|
|
Logger::Write(LogWarning, "compat", msgbuf.str());
|
|
|
|
}
|
2013-01-21 13:08:08 +01:00
|
|
|
}
|
2013-01-22 08:47:56 +01:00
|
|
|
#endif /* _WIN32 */
|
2013-01-21 13:08:08 +01:00
|
|
|
|
2012-07-27 16:05:02 +02:00
|
|
|
void CompatComponent::DumpHostStatus(ofstream& fp, const Host::Ptr& host)
|
2012-06-27 18:43:34 +02:00
|
|
|
{
|
2012-07-09 13:27:02 +02:00
|
|
|
int state;
|
2012-07-27 16:05:02 +02:00
|
|
|
if (!host->IsReachable())
|
2012-07-09 13:27:02 +02:00
|
|
|
state = 2; /* unreachable */
|
2012-07-27 16:05:02 +02:00
|
|
|
else if (!host->IsUp())
|
2012-07-09 13:27:02 +02:00
|
|
|
state = 1; /* down */
|
|
|
|
else
|
|
|
|
state = 0; /* up */
|
2012-07-09 10:09:53 +02:00
|
|
|
|
2012-06-29 14:14:51 +02:00
|
|
|
fp << "hoststatus {" << "\n"
|
2012-07-27 16:05:02 +02:00
|
|
|
<< "\t" << "host_name=" << host->GetName() << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "has_been_checked=1" << "\n"
|
|
|
|
<< "\t" << "should_be_scheduled=1" << "\n"
|
|
|
|
<< "\t" << "check_execution_time=0" << "\n"
|
|
|
|
<< "\t" << "check_latency=0" << "\n"
|
2012-07-09 10:09:53 +02:00
|
|
|
<< "\t" << "current_state=" << state << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "state_type=1" << "\n"
|
2012-08-03 18:17:47 +02:00
|
|
|
<< "\t" << "last_check=" << Utility::GetTime() << "\n"
|
|
|
|
<< "\t" << "next_check=" << Utility::GetTime() << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "current_attempt=1" << "\n"
|
|
|
|
<< "\t" << "max_attempts=1" << "\n"
|
|
|
|
<< "\t" << "active_checks_enabled=1" << "\n"
|
|
|
|
<< "\t" << "passive_checks_enabled=1" << "\n"
|
2012-08-03 18:17:47 +02:00
|
|
|
<< "\t" << "last_update=" << Utility::GetTime() << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
2012-07-27 16:05:02 +02:00
|
|
|
void CompatComponent::DumpHostObject(ofstream& fp, const Host::Ptr& host)
|
2012-06-27 18:43:34 +02:00
|
|
|
{
|
2012-06-29 14:14:51 +02:00
|
|
|
fp << "define host {" << "\n"
|
2012-07-27 16:05:02 +02:00
|
|
|
<< "\t" << "host_name" << "\t" << host->GetName() << "\n"
|
|
|
|
<< "\t" << "alias" << "\t" << host->GetAlias() << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "check_interval" << "\t" << 1 << "\n"
|
|
|
|
<< "\t" << "retry_interval" << "\t" << 1 << "\n"
|
|
|
|
<< "\t" << "max_check_attempts" << "\t" << 1 << "\n"
|
|
|
|
<< "\t" << "active_checks_enabled" << "\t" << 1 << "\n"
|
2012-07-09 12:44:31 +02:00
|
|
|
<< "\t" << "passive_checks_enabled" << "\t" << 1 << "\n";
|
|
|
|
|
2013-01-24 13:21:35 +01:00
|
|
|
set<Host::Ptr> parents = host->GetParents();
|
2012-07-09 12:44:31 +02:00
|
|
|
|
|
|
|
if (!parents.empty()) {
|
|
|
|
fp << "\t" << "parents" << "\t";
|
2013-01-24 13:21:35 +01:00
|
|
|
DumpNameList(fp, parents);
|
2012-07-09 12:44:31 +02:00
|
|
|
fp << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
fp << "\t" << "}" << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\n";
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
2012-07-27 16:05:02 +02:00
|
|
|
void CompatComponent::DumpServiceStatus(ofstream& fp, const Service::Ptr& service)
|
2012-06-27 18:43:34 +02:00
|
|
|
{
|
2012-08-02 09:38:08 +02:00
|
|
|
String output;
|
|
|
|
String perfdata;
|
2012-07-25 12:59:17 +02:00
|
|
|
double schedule_start = -1, schedule_end = -1;
|
|
|
|
double execution_start = -1, execution_end = -1;
|
2012-08-02 09:38:08 +02:00
|
|
|
|
|
|
|
Dictionary::Ptr cr = service->GetLastCheckResult();
|
|
|
|
if (cr) {
|
|
|
|
output = cr->Get("output");
|
|
|
|
schedule_start = cr->Get("schedule_start");
|
|
|
|
schedule_end = cr->Get("schedule_end");
|
|
|
|
execution_start = cr->Get("execution_start");
|
|
|
|
execution_end = cr->Get("execution_end");
|
|
|
|
perfdata = cr->Get("performance_data_raw");
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
2012-07-25 12:59:17 +02:00
|
|
|
double execution_time = (execution_end - execution_start);
|
|
|
|
double latency = (schedule_end - schedule_start) - execution_time;
|
2012-06-27 23:38:50 +02:00
|
|
|
|
2012-07-27 16:05:02 +02:00
|
|
|
int state = service->GetState();
|
2012-07-02 15:48:49 +02:00
|
|
|
|
2012-07-09 10:09:53 +02:00
|
|
|
if (state > StateUnknown)
|
2012-07-02 15:48:49 +02:00
|
|
|
state = StateUnknown;
|
|
|
|
|
2012-06-29 14:14:51 +02:00
|
|
|
fp << "servicestatus {" << "\n"
|
2012-07-27 16:05:02 +02:00
|
|
|
<< "\t" << "host_name=" << service->GetHost()->GetName() << "\n"
|
|
|
|
<< "\t" << "service_description=" << service->GetAlias() << "\n"
|
|
|
|
<< "\t" << "check_interval=" << service->GetCheckInterval() / 60.0 << "\n"
|
|
|
|
<< "\t" << "retry_interval=" << service->GetRetryInterval() / 60.0 << "\n"
|
2012-08-02 09:38:08 +02:00
|
|
|
<< "\t" << "has_been_checked=" << (service->GetLastCheckResult() ? 1 : 0) << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "should_be_scheduled=1" << "\n"
|
|
|
|
<< "\t" << "check_execution_time=" << execution_time << "\n"
|
|
|
|
<< "\t" << "check_latency=" << latency << "\n"
|
2012-07-02 15:48:49 +02:00
|
|
|
<< "\t" << "current_state=" << state << "\n"
|
2012-07-27 16:05:02 +02:00
|
|
|
<< "\t" << "state_type=" << service->GetStateType() << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "plugin_output=" << output << "\n"
|
|
|
|
<< "\t" << "performance_data=" << perfdata << "\n"
|
|
|
|
<< "\t" << "last_check=" << schedule_end << "\n"
|
2012-07-27 16:05:02 +02:00
|
|
|
<< "\t" << "next_check=" << service->GetNextCheck() << "\n"
|
|
|
|
<< "\t" << "current_attempt=" << service->GetCurrentCheckAttempt() << "\n"
|
|
|
|
<< "\t" << "max_attempts=" << service->GetMaxCheckAttempts() << "\n"
|
|
|
|
<< "\t" << "last_state_change=" << service->GetLastStateChange() << "\n"
|
|
|
|
<< "\t" << "last_hard_state_change=" << service->GetLastHardStateChange() << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "last_update=" << time(NULL) << "\n"
|
2013-01-22 16:01:08 +01:00
|
|
|
<< "\t" << "active_checks_enabled=" << (service->GetEnableChecks() ? 1 : 0) <<"\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "passive_checks_enabled=1" << "\n"
|
2013-01-23 13:21:07 +01:00
|
|
|
<< "\t" << "problem_has_been_acknowledged=" << (service->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n"
|
|
|
|
<< "\t" << "acknowledgement_type=" << static_cast<int>(service->GetAcknowledgement()) << "\n"
|
|
|
|
<< "\t" << "acknowledgement_end_time=" << service->GetAcknowledgementExpiry() << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
2012-07-27 16:05:02 +02:00
|
|
|
void CompatComponent::DumpServiceObject(ofstream& fp, const Service::Ptr& service)
|
2012-06-27 18:43:34 +02:00
|
|
|
{
|
2012-06-29 14:14:51 +02:00
|
|
|
fp << "define service {" << "\n"
|
2012-07-27 16:05:02 +02:00
|
|
|
<< "\t" << "host_name" << "\t" << service->GetHost()->GetName() << "\n"
|
|
|
|
<< "\t" << "service_description" << "\t" << service->GetAlias() << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "check_command" << "\t" << "check_i2" << "\n"
|
2012-07-27 16:05:02 +02:00
|
|
|
<< "\t" << "check_interval" << "\t" << service->GetCheckInterval() / 60.0 << "\n"
|
|
|
|
<< "\t" << "retry_interval" << "\t" << service->GetRetryInterval() / 60.0 << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "max_check_attempts" << "\t" << 1 << "\n"
|
2013-01-22 16:01:08 +01:00
|
|
|
<< "\t" << "active_checks_enabled" << "\t" << (service->GetEnableChecks() ? 1 : 0) << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "passive_checks_enabled" << "\t" << 1 << "\n"
|
|
|
|
<< "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Periodically writes the status.dat and objects.cache files.
|
|
|
|
*/
|
|
|
|
void CompatComponent::StatusTimerHandler(void)
|
|
|
|
{
|
2012-07-18 11:15:39 +02:00
|
|
|
Logger::Write(LogInformation, "compat", "Writing compat status information");
|
|
|
|
|
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";
|
|
|
|
|
2012-06-27 18:43:34 +02:00
|
|
|
ofstream statusfp;
|
2012-09-28 14:26:01 +02:00
|
|
|
statusfp.open(statuspathtmp.CStr(), ofstream::out | 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"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "version=2.0" << "\n"
|
|
|
|
<< "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
statusfp << "programstatus {" << "\n"
|
2012-09-19 14:10:34 +02:00
|
|
|
<< "icinga_pid=" << Utility::GetPid() << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "daemon_mode=1" << "\n"
|
|
|
|
<< "\t" << "program_start=" << IcingaApplication::GetInstance()->GetStartTime() << "\n"
|
|
|
|
<< "\t" << "active_service_checks_enabled=1" << "\n"
|
|
|
|
<< "\t" << "passive_service_checks_enabled=1" << "\n"
|
|
|
|
<< "\t" << "active_host_checks_enabled=0" << "\n"
|
|
|
|
<< "\t" << "passive_host_checks_enabled=0" << "\n"
|
2012-07-02 15:49:36 +02:00
|
|
|
<< "\t" << "check_service_freshness=0" << "\n"
|
2012-06-29 14:14:51 +02:00
|
|
|
<< "\t" << "check_host_freshness=0" << "\n"
|
|
|
|
<< "\t" << "enable_flap_detection=1" << "\n"
|
|
|
|
<< "\t" << "enable_failure_prediction=0" << "\n"
|
|
|
|
<< "\t" << "active_scheduled_service_check_stats=" << CIB::GetTaskStatistics(60) << "," << CIB::GetTaskStatistics(5 * 60) << "," << CIB::GetTaskStatistics(15 * 60) << "\n"
|
|
|
|
<< "\t" << "}" << "\n"
|
|
|
|
<< "\n";
|
2012-06-27 23:38:50 +02:00
|
|
|
|
2012-06-27 18:43:34 +02:00
|
|
|
ofstream objectfp;
|
2012-09-28 14:26:01 +02:00
|
|
|
objectfp.open(objectspathtmp.CStr(), ofstream::out | 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
|
|
|
|
2012-07-30 10:17:29 +02:00
|
|
|
DynamicObject::Ptr object;
|
2012-12-04 08:42:24 +01:00
|
|
|
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) {
|
2012-07-27 16:05:02 +02:00
|
|
|
const Host::Ptr& host = static_pointer_cast<Host>(object);
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2012-06-30 13:39:55 +02:00
|
|
|
DumpHostStatus(statusfp, host);
|
|
|
|
DumpHostObject(objectfp, host);
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
2013-01-24 13:21:35 +01:00
|
|
|
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("HostGroup")->GetObjects()) {
|
|
|
|
const HostGroup::Ptr& hg = static_pointer_cast<HostGroup>(object);
|
2012-07-16 22:00:50 +02:00
|
|
|
|
2012-06-30 13:39:55 +02:00
|
|
|
objectfp << "define hostgroup {" << "\n"
|
2013-01-24 13:21:35 +01:00
|
|
|
<< "\t" << "hostgroup_name" << "\t" << hg->GetName() << "\n"
|
|
|
|
<< "\t" << "alias" << "\t" << hg->GetAlias() << "\n"
|
|
|
|
<< "\t" << "notes_url" << "\t" << hg->GetNotesUrl() << "\n"
|
|
|
|
<< "\t" << "action_url" << "\t" << hg->GetActionUrl() << "\n";
|
2012-06-30 13:39:55 +02:00
|
|
|
|
|
|
|
objectfp << "\t" << "members" << "\t";
|
2013-01-24 13:21:35 +01:00
|
|
|
DumpNameList(objectfp, hg->GetMembers());
|
2012-06-30 13:39:55 +02:00
|
|
|
objectfp << "\n"
|
|
|
|
<< "}" << "\n";
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
2012-12-04 08:42:24 +01:00
|
|
|
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
|
2013-01-24 13:21:35 +01:00
|
|
|
const Service::Ptr& service = static_pointer_cast<Service>(object);
|
2012-06-30 13:39:55 +02:00
|
|
|
|
|
|
|
DumpServiceStatus(statusfp, service);
|
|
|
|
DumpServiceObject(objectfp, service);
|
|
|
|
}
|
|
|
|
|
2013-01-24 13:21:35 +01:00
|
|
|
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("ServiceGroup")->GetObjects()) {
|
|
|
|
const ServiceGroup::Ptr& sg = static_pointer_cast<ServiceGroup>(object);
|
2012-07-16 22:00:50 +02:00
|
|
|
|
2012-06-30 13:39:55 +02:00
|
|
|
objectfp << "define servicegroup {" << "\n"
|
2013-01-24 13:21:35 +01:00
|
|
|
<< "\t" << "servicegroup_name" << "\t" << sg->GetName() << "\n"
|
|
|
|
<< "\t" << "alias" << "\t" << sg->GetAlias() << "\n"
|
|
|
|
<< "\t" << "notes_url" << "\t" << sg->GetNotesUrl() << "\n"
|
|
|
|
<< "\t" << "action_url" << "\t" << sg->GetActionUrl() << "\n";
|
2012-06-30 13:39:55 +02:00
|
|
|
|
|
|
|
objectfp << "\t" << "members" << "\t";
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
vector<String> sglist;
|
2013-01-24 13:21:35 +01:00
|
|
|
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
2012-07-27 16:05:02 +02:00
|
|
|
sglist.push_back(service->GetHost()->GetName());
|
|
|
|
sglist.push_back(service->GetAlias());
|
2012-06-30 13:39:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DumpStringList(objectfp, sglist);
|
|
|
|
|
|
|
|
objectfp << "\n"
|
|
|
|
<< "}" << "\n";
|
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();
|
|
|
|
if (rename(statuspathtmp.CStr(), statuspath.CStr()) < 0)
|
|
|
|
throw_exception(PosixException("rename() failed", errno));
|
2012-06-27 18:43:34 +02:00
|
|
|
|
|
|
|
objectfp.close();
|
2012-10-17 11:35:06 +02:00
|
|
|
if (rename(objectspathtmp.CStr(), objectspath.CStr()) < 0)
|
|
|
|
throw_exception(PosixException("rename() failed", errno));
|
2012-06-27 18:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_COMPONENT(compat, CompatComponent);
|