diff --git a/doc/12-icinga2-api.md b/doc/12-icinga2-api.md
index e0acf0369..c903a71d5 100644
--- a/doc/12-icinga2-api.md
+++ b/doc/12-icinga2-api.md
@@ -1682,6 +1682,9 @@ The following event stream types are available:
DowntimeRemoved | Downtime removed for hosts and services.
DowntimeStarted | Downtime started for hosts and services.
DowntimeTriggered | Downtime triggered for hosts and services.
+ ObjectCreated | Object created for all Icinga 2 objects.
+ ObjectDeleted | Object deleted for all Icinga 2 objects.
+ ObjectModified | Object modified for all Icinga 2 objects.
Note: Each type requires [API permissions](12-icinga2-api.md#icinga2-api-permissions)
being set.
@@ -1694,6 +1697,14 @@ Example for all downtime events:
-d '{ "types": ["DowntimeAdded", "DowntimeRemoved", "DowntimeTriggered"] }'
```
+Example for all object events:
+
+```
+&types=ObjectCreated&types=ObjectDeleted&types=ObjectModified
+
+-d '{ "types": ["ObjectCreated", "ObjectDeleted", "ObjectModified"] }'
+```
+
#### Event Stream Type: CheckResult
Name | Type | Description
diff --git a/lib/icinga/apievents.cpp b/lib/icinga/apievents.cpp
index 5e7fef79c..53008fdb1 100644
--- a/lib/icinga/apievents.cpp
+++ b/lib/icinga/apievents.cpp
@@ -3,7 +3,6 @@
#include "icinga/apievents.hpp"
#include "icinga/service.hpp"
#include "icinga/notificationcommand.hpp"
-#include "remote/eventqueue.hpp"
#include "base/initialize.hpp"
#include "base/serializer.hpp"
#include "base/logger.hpp"
@@ -30,6 +29,9 @@ void ApiEvents::StaticInitialize()
Downtime::OnDowntimeRemoved.connect(&ApiEvents::DowntimeRemovedHandler);
Downtime::OnDowntimeStarted.connect(&ApiEvents::DowntimeStartedHandler);
Downtime::OnDowntimeTriggered.connect(&ApiEvents::DowntimeTriggeredHandler);
+
+ ConfigObject::OnActiveChanged.connect(&ApiEvents::OnActiveChangedHandler);
+ ConfigObject::OnVersionChanged.connect(&ApiEvents::OnVersionChangedHandler);
}
void ApiEvents::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin)
@@ -397,3 +399,40 @@ void ApiEvents::DowntimeTriggeredHandler(const Downtime::Ptr& downtime)
inboxes.Push(std::move(result));
}
+
+void ApiEvents::OnActiveChangedHandler(const ConfigObject::Ptr& object, const Value&)
+{
+ if (object->IsActive()) {
+ ApiEvents::SendObjectChangeEvent(object, EventType::ObjectCreated, "ObjectCreated");
+ } else if (!object->IsActive() && !object->GetExtension("ConfigObjectDeleted").IsEmpty()) {
+ ApiEvents::SendObjectChangeEvent(object, EventType::ObjectDeleted, "ObjectDeleted");
+ }
+}
+
+void ApiEvents::OnVersionChangedHandler(const ConfigObject::Ptr& object, const Value&)
+{
+ ApiEvents::SendObjectChangeEvent(object, EventType::ObjectModified, "ObjectModified");
+}
+
+void ApiEvents::SendObjectChangeEvent(const ConfigObject::Ptr& object, const EventType& eventType, const String& eventQueue) {
+ std::vector queues = EventQueue::GetQueuesForType(eventQueue);
+ auto inboxes (EventsRouter::GetInstance().GetInboxes(eventType));
+
+ if (queues.empty() && !inboxes)
+ return;
+
+ Log(LogDebug, "ApiEvents") << "Processing event type '" + eventQueue + "'.";
+
+ Dictionary::Ptr result = new Dictionary ({
+ {"type", eventQueue},
+ {"timestamp", Utility::GetTime()},
+ {"object_type", object->GetReflectionType()->GetName()},
+ {"object_name", object->GetName()},
+ });
+
+ for (const EventQueue::Ptr& queue : queues) {
+ queue->ProcessEvent(result);
+ }
+
+ inboxes.Push(std::move(result));
+}
diff --git a/lib/icinga/apievents.hpp b/lib/icinga/apievents.hpp
index 67dca6238..07d5c6013 100644
--- a/lib/icinga/apievents.hpp
+++ b/lib/icinga/apievents.hpp
@@ -3,6 +3,7 @@
#ifndef APIEVENTS_H
#define APIEVENTS_H
+#include "remote/eventqueue.hpp"
#include "icinga/checkable.hpp"
#include "icinga/host.hpp"
@@ -39,6 +40,10 @@ public:
static void DowntimeRemovedHandler(const Downtime::Ptr& downtime);
static void DowntimeStartedHandler(const Downtime::Ptr& downtime);
static void DowntimeTriggeredHandler(const Downtime::Ptr& downtime);
+
+ static void OnActiveChangedHandler(const ConfigObject::Ptr& object, const Value&);
+ static void OnVersionChangedHandler(const ConfigObject::Ptr& object, const Value&);
+ static void SendObjectChangeEvent(const ConfigObject::Ptr& object, const EventType& eventType, const String& eventQueue);
};
}
diff --git a/lib/remote/eventqueue.hpp b/lib/remote/eventqueue.hpp
index 33013836e..e9e5de88f 100644
--- a/lib/remote/eventqueue.hpp
+++ b/lib/remote/eventqueue.hpp
@@ -81,7 +81,10 @@ enum class EventType : uint_fast8_t
DowntimeTriggered,
Flapping,
Notification,
- StateChange
+ StateChange,
+ ObjectCreated,
+ ObjectDeleted,
+ ObjectModified
};
class EventsInbox : public Object
diff --git a/lib/remote/eventshandler.cpp b/lib/remote/eventshandler.cpp
index e92b14a2d..e05ef229b 100644
--- a/lib/remote/eventshandler.cpp
+++ b/lib/remote/eventshandler.cpp
@@ -31,7 +31,10 @@ const std::map l_EventTypes ({
{"DowntimeTriggered", EventType::DowntimeTriggered},
{"Flapping", EventType::Flapping},
{"Notification", EventType::Notification},
- {"StateChange", EventType::StateChange}
+ {"StateChange", EventType::StateChange},
+ {"ObjectCreated", EventType::ObjectCreated},
+ {"ObjectDeleted", EventType::ObjectDeleted},
+ {"ObjectModified", EventType::ObjectModified}
});
const String l_ApiQuery ("");