#include "compat/compatlog.h"
#include "icinga/checkresultmessage.h"
+#include "icinga/downtimemessage.h"
#include "icinga/service.h"
#include "icinga/macroprocessor.h"
#include "config/configcompilercontext.h"
m_Endpoint = Endpoint::MakeEndpoint("compatlog_" + GetName(), false);
m_Endpoint->RegisterTopicHandler("checker::CheckResult",
boost::bind(&CompatLog::CheckResultRequestHandler, this, _3));
+ m_Endpoint->RegisterTopicHandler("icinga::Downtime",
+ boost::bind(&CompatLog::DowntimeRequestHandler, this, _3));
m_RotationTimer = boost::make_shared<Timer>();
m_RotationTimer->OnTimerExpired.connect(boost::bind(&CompatLog::RotationTimerHandler, this));
}
}
+/**
+ * @threadsafety Always.
+ */
+void CompatLog::DowntimeRequestHandler(const RequestMessage& request)
+{
+ DowntimeMessage params;
+ if (!request.GetParams(¶ms))
+ return;
+
+ String svcname = params.GetService();
+ Service::Ptr service = Service::GetByName(svcname);
+
+ Host::Ptr host = service->GetHost();
+
+ if (!host)
+ return;
+
+ DowntimeState downtime_state = params.GetState();
+ String downtime_state_str;
+ String downtime_output;
+
+ switch (downtime_state) {
+ case DowntimeStarted:
+ downtime_output = "Service has entered a period of scheduled downtime.";
+ downtime_state_str = "STARTED";
+ break;
+ case DowntimeStopped:
+ downtime_output = "Service has exited from a period of scheduled downtime.";
+ downtime_state_str = "STOPPED";
+ break;
+ case DowntimeCancelled:
+ downtime_output = "Scheduled downtime for service has been cancelled.";
+ downtime_state_str = "CANCELLED";
+ break;
+ default:
+ Log(LogCritical, "compat", "Unknown downtime state: " + Convert::ToString(downtime_state));
+ return;
+ }
+
+ std::ostringstream msgbuf;
+ msgbuf << "SERVICE DOWNTIME ALERT: "
+ << host->GetName() << ";"
+ << service->GetShortName() << ";"
+ << downtime_state_str << "; "
+ << downtime_output
+ << "";
+
+ {
+ ObjectLock oLock(this);
+ WriteLine(msgbuf.str());
+ }
+
+ if (service == host->GetHostCheckService()) {
+ std::ostringstream msgbuf;
+ msgbuf << "HOST DOWNTIME ALERT: "
+ << host->GetName() << ";"
+ << downtime_state_str << "; "
+ << downtime_output
+ << "";
+
+ {
+ ObjectLock oLock(this);
+ WriteLine(msgbuf.str());
+ }
+ }
+
+ {
+ ObjectLock oLock(this);
+ Flush();
+ }
+}
+
void CompatLog::WriteLine(const String& line)
{
ASSERT(OwnsLock());
Endpoint::Ptr m_Endpoint;
void CheckResultRequestHandler(const RequestMessage& request);
+ void DowntimeRequestHandler(const RequestMessage& request);
Timer::Ptr m_RotationTimer;
void RotationTimerHandler(void);
cib.h \
command.cpp \
command.h \
+ downtimemessage.cpp \
+ downtimemessage.h \
eventcommand.cpp \
eventcommand.h \
externalcommandprocessor.cpp \
--- /dev/null
+/******************************************************************************
+ * 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 "icinga/downtimemessage.h"
+
+using namespace icinga;
+
+String DowntimeMessage::GetService(void) const
+{
+ String service;
+ Get("service", &service);
+ return service;
+}
+
+void DowntimeMessage::SetService(const String& service)
+{
+ Set("service", service);
+}
+
+DowntimeState DowntimeMessage::GetState(void) const
+{
+ long state;
+ Get("state", &state);
+ return static_cast<DowntimeState>(state);
+}
+
+void DowntimeMessage::SetState(DowntimeState state)
+{
+ Set("state", state);
+}
--- /dev/null
+/******************************************************************************
+ * 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. *
+ ******************************************************************************/
+
+#ifndef DOWNTIMEMESSAGE_H
+#define DOWNTIMEMESSAGE_H
+
+#include "icinga/i2-icinga.h"
+#include "icinga/service.h"
+#include "remoting/messagepart.h"
+
+namespace icinga
+{
+
+/**
+ * A state change message for a service.
+ *
+ * @ingroup icinga
+ */
+class I2_ICINGA_API DowntimeMessage : public MessagePart
+{
+public:
+ DowntimeMessage(void) : MessagePart() { }
+ explicit DowntimeMessage(const MessagePart& message) : MessagePart(message) { }
+
+ String GetService(void) const;
+ void SetService(const String& service);
+
+ DowntimeState GetState(void) const;
+ void SetState(DowntimeState state);
+};
+
+}
+
+#endif /* DOWNTIMEMESSAGE_H */
<ClCompile Include="api.cpp" />
<ClCompile Include="checkresultmessage.cpp" />
<ClCompile Include="cib.cpp" />
+ <ClCompile Include="downtimemessage.cpp" />
<ClCompile Include="externalcommandprocessor.cpp" />
<ClCompile Include="host.cpp" />
<ClCompile Include="hostgroup.cpp" />
<ClInclude Include="api.h" />
<ClInclude Include="checkresultmessage.h" />
<ClInclude Include="cib.h" />
+ <ClInclude Include="downtimemessage.h" />
<ClInclude Include="externalcommandprocessor.h" />
<ClInclude Include="host.h" />
<ClInclude Include="hostgroup.h" />
<ClCompile Include="checkresultmessage.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
+ <ClCompile Include="downtimemessage.cpp">
+ <Filter>Quelldateien</Filter>
+ </ClCompile>
<ClCompile Include="service-comment.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClInclude Include="checkresultmessage.h">
<Filter>Headerdateien</Filter>
</ClInclude>
+ <ClInclude Include="downtimemessage.h">
+ <Filter>Headerdateien</Filter>
+ </ClInclude>
<ClInclude Include="pluginnotificationtask.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<Filter>Quelldateien</Filter>
</CustomBuild>
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
******************************************************************************/
#include "icinga/service.h"
+#include "icinga/downtimemessage.h"
+#include "remoting/endpointmanager.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
{
ObjectLock olock(owner);
+
downtimes->Remove(id);
+
+ RequestMessage rm;
+ rm.SetMethod("icinga::Downtime");
+
+ DowntimeMessage params;
+ params.SetService(owner->GetName());
+ params.SetState(DowntimeCancelled);
+
+ rm.SetParams(params);
+
+ EndpointManager::GetInstance()->SendMulticastMessage(rm);
+
owner->Touch("downtimes");
}
}
TriggerDowntime(tid);
}
+ RequestMessage rm;
+ rm.SetMethod("icinga::Downtime");
+
+ DowntimeMessage params;
+ params.SetService(owner->GetName());
+ params.SetState(DowntimeStarted);
+
+ rm.SetParams(params);
+
+ EndpointManager::GetInstance()->SendMulticastMessage(rm);
+
owner->Touch("downtimes");
}
if (!expiredDowntimes.empty()) {
BOOST_FOREACH(const String& id, expiredDowntimes) {
+ RequestMessage rm;
+ rm.SetMethod("icinga::Downtime");
+
+ DowntimeMessage params;
+ params.SetService(GetName());
+ params.SetState(DowntimeStopped);
+
+ rm.SetParams(params);
+
+ EndpointManager::GetInstance()->SendMulticastMessage(rm);
+
downtimes->Remove(id);
}
CommentAcknowledgement = 4
};
+/**
+ * The state of a service downtime.
+ *
+ * @ingroup icinga
+ */
+enum DowntimeState
+{
+ DowntimeStarted = 0,
+ DowntimeCancelled = 1,
+ DowntimeStopped = 2
+};
+
class CheckCommand;
class EventCommand;