2014-05-03 20:02:22 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2018-10-18 09:27:04 +02:00
|
|
|
* Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/) *
|
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);
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void ApiEvents::StaticInitialize()
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
|
|
|
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-08-20 17:18:48 +02:00
|
|
|
Comment::OnCommentAdded.connect(&ApiEvents::CommentAddedHandler);
|
|
|
|
Comment::OnCommentRemoved.connect(&ApiEvents::CommentRemovedHandler);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
Downtime::OnDowntimeAdded.connect(&ApiEvents::DowntimeAddedHandler);
|
|
|
|
Downtime::OnDowntimeRemoved.connect(&ApiEvents::DowntimeRemovedHandler);
|
2016-11-11 19:36:19 +01:00
|
|
|
Downtime::OnDowntimeStarted.connect(&ApiEvents::DowntimeStartedHandler);
|
2015-08-20 17:18:48 +02:00
|
|
|
Downtime::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
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const EventQueue::Ptr& queue : queues) {
|
2015-10-19 17:31:18 +02:00
|
|
|
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
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const EventQueue::Ptr& queue : queues) {
|
2015-10-19 17:31:18 +02:00
|
|
|
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,
|
2017-12-19 15:50:05 +01:00
|
|
|
const Checkable::Ptr& checkable, const std::set<User::Ptr>& users, NotificationType type,
|
|
|
|
const CheckResult::Ptr& cr, const String& author, const String& text, 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("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
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
ArrayData userNames;
|
2015-07-02 13:04:38 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const User::Ptr& user : users) {
|
2018-01-11 11:17:38 +01:00
|
|
|
userNames.push_back(user->GetName());
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
result->Set("users", new Array(std::move(userNames)));
|
2015-10-19 17:31:18 +02:00
|
|
|
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
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const EventQueue::Ptr& queue : queues) {
|
2015-10-19 17:31:18 +02:00
|
|
|
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());
|
2017-11-03 17:50:59 +01:00
|
|
|
result->Set("flapping_current", checkable->GetFlappingCurrent());
|
|
|
|
result->Set("threshold_low", checkable->GetFlappingThresholdLow());
|
|
|
|
result->Set("threshold_high", checkable->GetFlappingThresholdHigh());
|
2015-07-02 13:04:38 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const EventQueue::Ptr& queue : queues) {
|
2015-10-19 17:31:18 +02:00
|
|
|
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,
|
2017-12-19 15:50:05 +01:00
|
|
|
const String& author, const String& comment, AcknowledgementType type,
|
|
|
|
bool notify, bool persistent, 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);
|
2017-01-25 21:21:22 +01:00
|
|
|
result->Set("persistent", persistent);
|
2015-10-19 17:31:18 +02:00
|
|
|
result->Set("expiry", expiry);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const EventQueue::Ptr& queue : queues) {
|
2015-10-19 17:31:18 +02:00
|
|
|
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
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const EventQueue::Ptr& queue : queues) {
|
2015-10-19 17:31:18 +02:00
|
|
|
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-08-20 17:18:48 +02:00
|
|
|
void ApiEvents::CommentAddedHandler(const Comment::Ptr& comment)
|
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'.");
|
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
Dictionary::Ptr result = new Dictionary({
|
|
|
|
{ "type", "CommentAdded" },
|
|
|
|
{ "timestamp", Utility::GetTime() },
|
|
|
|
{ "comment", Serialize(comment, FAConfig | FAState) }
|
|
|
|
});
|
2015-07-02 13:04:38 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const EventQueue::Ptr& queue : queues) {
|
2015-10-19 17:31:18 +02:00
|
|
|
queue->ProcessEvent(result);
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
void ApiEvents::CommentRemovedHandler(const Comment::Ptr& comment)
|
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'.");
|
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
Dictionary::Ptr result = new Dictionary({
|
|
|
|
{ "type", "CommentRemoved" },
|
|
|
|
{ "timestamp", Utility::GetTime() },
|
|
|
|
{ "comment", Serialize(comment, FAConfig | FAState) }
|
|
|
|
});
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const EventQueue::Ptr& queue : queues) {
|
2015-10-19 17:31:18 +02:00
|
|
|
queue->ProcessEvent(result);
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
void ApiEvents::DowntimeAddedHandler(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("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'.");
|
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
Dictionary::Ptr result = new Dictionary({
|
|
|
|
{ "type", "DowntimeAdded" },
|
|
|
|
{ "timestamp", Utility::GetTime() },
|
|
|
|
{ "downtime", Serialize(downtime, FAConfig | FAState) }
|
|
|
|
});
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const EventQueue::Ptr& queue : queues) {
|
2015-10-19 17:31:18 +02:00
|
|
|
queue->ProcessEvent(result);
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
void ApiEvents::DowntimeRemovedHandler(const Downtime::Ptr& downtime)
|
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
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
Dictionary::Ptr result = new Dictionary({
|
|
|
|
{ "type", "DowntimeRemoved" },
|
|
|
|
{ "timestamp", Utility::GetTime() },
|
|
|
|
{ "downtime", Serialize(downtime, FAConfig | FAState) }
|
|
|
|
});
|
2014-11-13 11:23:57 +01:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const EventQueue::Ptr& queue : queues) {
|
2015-10-19 17:31:18 +02:00
|
|
|
queue->ProcessEvent(result);
|
2015-02-05 15:36:17 +01:00
|
|
|
}
|
2014-11-13 11:23:57 +01:00
|
|
|
}
|
|
|
|
|
2016-11-11 19:36:19 +01:00
|
|
|
void ApiEvents::DowntimeStartedHandler(const Downtime::Ptr& downtime)
|
|
|
|
{
|
|
|
|
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("DowntimeStarted");
|
|
|
|
|
|
|
|
if (queues.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Log(LogDebug, "ApiEvents", "Processing event type 'DowntimeStarted'.");
|
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
Dictionary::Ptr result = new Dictionary({
|
|
|
|
{ "type", "DowntimeStarted" },
|
|
|
|
{ "timestamp", Utility::GetTime() },
|
|
|
|
{ "downtime", Serialize(downtime, FAConfig | FAState) }
|
|
|
|
});
|
2016-11-11 19:36:19 +01:00
|
|
|
|
|
|
|
for (const EventQueue::Ptr& queue : queues) {
|
|
|
|
queue->ProcessEvent(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
void ApiEvents::DowntimeTriggeredHandler(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
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
Dictionary::Ptr result = new Dictionary({
|
|
|
|
{ "type", "DowntimeTriggered" },
|
|
|
|
{ "timestamp", Utility::GetTime() },
|
|
|
|
{ "downtime", Serialize(downtime, FAConfig | FAState) }
|
|
|
|
});
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const EventQueue::Ptr& queue : queues) {
|
2015-10-19 17:31:18 +02:00
|
|
|
queue->ProcessEvent(result);
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
}
|