2014-05-03 20:02:22 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2015-01-22 12:00:23 +01:00
|
|
|
* Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
|
2014-05-03 20:02:22 +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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/apievents.hpp"
|
|
|
|
#include "icinga/service.hpp"
|
2015-10-19 17:31:18 +02:00
|
|
|
#include "remote/eventqueue.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/initialize.hpp"
|
2014-10-26 19:59:49 +01:00
|
|
|
#include "base/serializer.hpp"
|
2015-10-19 17:31:18 +02:00
|
|
|
#include "base/logger.hpp"
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
INITIALIZE_ONCE(&ApiEvents::StaticInitialize);
|
|
|
|
|
|
|
|
void ApiEvents::StaticInitialize(void)
|
|
|
|
{
|
|
|
|
Checkable::OnNewCheckResult.connect(&ApiEvents::CheckResultHandler);
|
2015-10-19 17:31:18 +02:00
|
|
|
Checkable::OnStateChange.connect(&ApiEvents::StateChangeHandler);
|
|
|
|
Checkable::OnNotificationSentToAllUsers.connect(&ApiEvents::NotificationSentToAllUsersHandler);
|
|
|
|
|
|
|
|
Checkable::OnFlappingChanged.connect(&ApiEvents::FlappingChangedHandler);
|
2015-09-28 19:03:13 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
Checkable::OnAcknowledgementSet.connect(&ApiEvents::AcknowledgementSetHandler);
|
|
|
|
Checkable::OnAcknowledgementCleared.connect(&ApiEvents::AcknowledgementClearedHandler);
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Checkable::OnCommentAdded.connect(&ApiEvents::CommentAddedHandler);
|
|
|
|
Checkable::OnCommentRemoved.connect(&ApiEvents::CommentRemovedHandler);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Checkable::OnDowntimeAdded.connect(&ApiEvents::DowntimeAddedHandler);
|
|
|
|
Checkable::OnDowntimeRemoved.connect(&ApiEvents::DowntimeRemovedHandler);
|
|
|
|
Checkable::OnDowntimeTriggered.connect(&ApiEvents::DowntimeTriggeredHandler);
|
2014-11-13 11:23:57 +01:00
|
|
|
}
|
|
|
|
|
2015-08-04 14:47:44 +02:00
|
|
|
void ApiEvents::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin)
|
2014-11-13 11:23:57 +01:00
|
|
|
{
|
2015-10-19 17:31:18 +02:00
|
|
|
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("CheckResult");
|
2014-11-13 11:23:57 +01:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
if (queues.empty())
|
2014-11-13 11:23:57 +01:00
|
|
|
return;
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Log(LogDebug, "ApiEvents", "Processing event type 'CheckResult'.");
|
2014-11-13 11:23:57 +01:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Dictionary::Ptr result = new Dictionary();
|
|
|
|
result->Set("type", "CheckResult");
|
|
|
|
result->Set("timestamp", Utility::GetTime());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("service", service->GetShortName());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("check_result", Serialize(cr));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
BOOST_FOREACH(const EventQueue::Ptr& queue, queues) {
|
|
|
|
queue->ProcessEvent(result);
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
void ApiEvents::StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type, const MessageOrigin::Ptr& origin)
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
2015-10-19 17:31:18 +02:00
|
|
|
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("StateChange");
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
if (queues.empty())
|
2014-05-03 20:02:22 +02:00
|
|
|
return;
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Log(LogDebug, "ApiEvents", "Processing event type 'StateChange'.");
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Dictionary::Ptr result = new Dictionary();
|
|
|
|
result->Set("type", "StateChange");
|
|
|
|
result->Set("timestamp", Utility::GetTime());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("service", service->GetShortName());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-21 15:50:32 +02:00
|
|
|
result->Set("state", service ? static_cast<int>(service->GetState()) : static_cast<int>(host->GetState()));
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("state_type", checkable->GetStateType());
|
|
|
|
result->Set("check_result", Serialize(cr));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
BOOST_FOREACH(const EventQueue::Ptr& queue, queues) {
|
|
|
|
queue->ProcessEvent(result);
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
void ApiEvents::NotificationSentToAllUsersHandler(const Notification::Ptr& notification,
|
|
|
|
const Checkable::Ptr& checkable, const std::set<User::Ptr>& users, NotificationType type,
|
|
|
|
const CheckResult::Ptr& cr, const String& author, const String& text)
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
2015-10-19 17:31:18 +02:00
|
|
|
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("Notification");
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
if (queues.empty())
|
2014-05-03 20:02:22 +02:00
|
|
|
return;
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Log(LogDebug, "ApiEvents", "Processing event type 'Notification'.");
|
|
|
|
|
|
|
|
Dictionary::Ptr result = new Dictionary();
|
|
|
|
result->Set("type", "Notification");
|
|
|
|
result->Set("timestamp", Utility::GetTime());
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("service", service->GetShortName());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Array::Ptr userNames = new Array();
|
2015-07-02 13:04:38 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
BOOST_FOREACH(const User::Ptr& user, users) {
|
|
|
|
userNames->Add(user->GetName());
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("users", userNames);
|
|
|
|
result->Set("notification_type", Notification::NotificationTypeToString(type));
|
|
|
|
result->Set("author", author);
|
|
|
|
result->Set("text", text);
|
|
|
|
result->Set("check_result", Serialize(cr));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
BOOST_FOREACH(const EventQueue::Ptr& queue, queues) {
|
|
|
|
queue->ProcessEvent(result);
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
void ApiEvents::FlappingChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin)
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
2015-10-19 17:31:18 +02:00
|
|
|
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("Flapping");
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
if (queues.empty())
|
2014-05-03 20:02:22 +02:00
|
|
|
return;
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Log(LogDebug, "ApiEvents", "Processing event type 'Flapping'.");
|
|
|
|
|
|
|
|
Dictionary::Ptr result = new Dictionary();
|
|
|
|
result->Set("type", "Flapping");
|
|
|
|
result->Set("timestamp", Utility::GetTime());
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("service", service->GetShortName());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-21 15:50:32 +02:00
|
|
|
result->Set("state", service ? static_cast<int>(service->GetState()) : static_cast<int>(host->GetState()));
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("state_type", checkable->GetStateType());
|
|
|
|
result->Set("is_flapping", checkable->IsFlapping());
|
2015-07-02 13:04:38 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
BOOST_FOREACH(const EventQueue::Ptr& queue, queues) {
|
|
|
|
queue->ProcessEvent(result);
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
void ApiEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable,
|
|
|
|
const String& author, const String& comment, AcknowledgementType type,
|
|
|
|
bool notify, double expiry, const MessageOrigin::Ptr& origin)
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
2015-10-19 17:31:18 +02:00
|
|
|
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("AcknowledgementSet");
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
if (queues.empty())
|
2014-05-03 20:02:22 +02:00
|
|
|
return;
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Log(LogDebug, "ApiEvents", "Processing event type 'AcknowledgementSet'.");
|
|
|
|
|
|
|
|
Dictionary::Ptr result = new Dictionary();
|
|
|
|
result->Set("type", "AcknowledgementSet");
|
|
|
|
result->Set("timestamp", Utility::GetTime());
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("service", service->GetShortName());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-21 15:50:32 +02:00
|
|
|
result->Set("state", service ? static_cast<int>(service->GetState()) : static_cast<int>(host->GetState()));
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("state_type", checkable->GetStateType());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("author", author);
|
|
|
|
result->Set("comment", comment);
|
|
|
|
result->Set("acknowledgement_type", type);
|
|
|
|
result->Set("notify", notify);
|
|
|
|
result->Set("expiry", expiry);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
BOOST_FOREACH(const EventQueue::Ptr& queue, queues) {
|
|
|
|
queue->ProcessEvent(result);
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
void ApiEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin)
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
2015-10-19 17:31:18 +02:00
|
|
|
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("AcknowledgementCleared");
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
if (queues.empty())
|
2014-05-03 20:02:22 +02:00
|
|
|
return;
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Log(LogDebug, "ApiEvents", "Processing event type 'AcknowledgementCleared'.");
|
|
|
|
|
|
|
|
Dictionary::Ptr result = new Dictionary();
|
|
|
|
result->Set("type", "AcknowledgementCleared");
|
|
|
|
result->Set("timestamp", Utility::GetTime());
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("service", service->GetShortName());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-21 15:50:32 +02:00
|
|
|
result->Set("state", service ? static_cast<int>(service->GetState()) : static_cast<int>(host->GetState()));
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("state_type", checkable->GetStateType());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
BOOST_FOREACH(const EventQueue::Ptr& queue, queues) {
|
|
|
|
queue->ProcessEvent(result);
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("acknowledgement_type", AcknowledgementNone);
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
void ApiEvents::CommentAddedHandler(const Checkable::Ptr& checkable, const Comment::Ptr& comment, const MessageOrigin::Ptr& origin)
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
2015-10-19 17:31:18 +02:00
|
|
|
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("CommentAdded");
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
if (queues.empty())
|
2014-05-03 20:02:22 +02:00
|
|
|
return;
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Log(LogDebug, "ApiEvents", "Processing event type 'CommentAdded'.");
|
|
|
|
|
|
|
|
Dictionary::Ptr result = new Dictionary();
|
|
|
|
result->Set("type", "CommentAdded");
|
|
|
|
result->Set("timestamp", Utility::GetTime());
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("service", service->GetShortName());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("comment", Serialize(comment));
|
2015-07-02 13:04:38 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
BOOST_FOREACH(const EventQueue::Ptr& queue, queues) {
|
|
|
|
queue->ProcessEvent(result);
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
void ApiEvents::CommentRemovedHandler(const Checkable::Ptr& checkable, const Comment::Ptr& comment, const MessageOrigin::Ptr& origin)
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
2015-10-19 17:31:18 +02:00
|
|
|
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("CommentRemoved");
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
if (queues.empty())
|
2014-05-03 20:02:22 +02:00
|
|
|
return;
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Log(LogDebug, "ApiEvents", "Processing event type 'CommentRemoved'.");
|
|
|
|
|
|
|
|
Dictionary::Ptr result = new Dictionary();
|
|
|
|
result->Set("type", "CommentRemoved");
|
|
|
|
result->Set("timestamp", Utility::GetTime());
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("service", service->GetShortName());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
BOOST_FOREACH(const EventQueue::Ptr& queue, queues) {
|
|
|
|
queue->ProcessEvent(result);
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
void ApiEvents::DowntimeAddedHandler(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime, const MessageOrigin::Ptr& origin)
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
2015-10-19 17:31:18 +02:00
|
|
|
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("DowntimeAdded");
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
if (queues.empty())
|
2014-05-03 20:02:22 +02:00
|
|
|
return;
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Log(LogDebug, "ApiEvents", "Processing event type 'DowntimeAdded'.");
|
|
|
|
|
|
|
|
Dictionary::Ptr result = new Dictionary();
|
|
|
|
result->Set("type", "DowntimeAdded");
|
|
|
|
result->Set("timestamp", Utility::GetTime());
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("service", service->GetShortName());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("downtime", Serialize(downtime));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
BOOST_FOREACH(const EventQueue::Ptr& queue, queues) {
|
|
|
|
queue->ProcessEvent(result);
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
void ApiEvents::DowntimeRemovedHandler(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime, const MessageOrigin::Ptr& origin)
|
2014-11-13 11:23:57 +01:00
|
|
|
{
|
2015-10-19 17:31:18 +02:00
|
|
|
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("DowntimeRemoved");
|
2014-11-13 11:23:57 +01:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
if (queues.empty())
|
|
|
|
return;
|
2015-02-05 15:17:56 +01:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Log(LogDebug, "ApiEvents", "Processing event type 'DowntimeRemoved'.");
|
2015-02-05 15:17:56 +01:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Dictionary::Ptr result = new Dictionary();
|
|
|
|
result->Set("type", "DowntimeRemoved");
|
|
|
|
result->Set("timestamp", Utility::GetTime());
|
2015-03-05 20:50:27 +01:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
2015-02-05 15:17:56 +01:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("host", host->GetName());
|
|
|
|
if (service)
|
|
|
|
result->Set("service", service->GetShortName());
|
2014-11-13 11:23:57 +01:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
BOOST_FOREACH(const EventQueue::Ptr& queue, queues) {
|
|
|
|
queue->ProcessEvent(result);
|
2015-02-05 15:36:17 +01:00
|
|
|
}
|
2014-11-13 11:23:57 +01:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
void ApiEvents::DowntimeTriggeredHandler(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime)
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
2015-10-19 17:31:18 +02:00
|
|
|
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("DowntimeTriggered");
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
if (queues.empty())
|
2014-05-03 20:02:22 +02:00
|
|
|
return;
|
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Log(LogDebug, "ApiEvents", "Processing event type 'DowntimeTriggered'.");
|
2014-08-04 14:03:37 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Dictionary::Ptr result = new Dictionary();
|
|
|
|
result->Set("type", "DowntimeTriggered");
|
|
|
|
result->Set("timestamp", Utility::GetTime());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("host", host->GetName());
|
|
|
|
if (service)
|
|
|
|
result->Set("service", service->GetShortName());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("downtime", Serialize(downtime));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-10-19 17:31:18 +02:00
|
|
|
BOOST_FOREACH(const EventQueue::Ptr& queue, queues) {
|
|
|
|
queue->ProcessEvent(result);
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
}
|