mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 21:55:03 +02:00
Merge pull request #8083 from Icinga/feature/Implement-new-API-events-7974
Implement new API event streams response
This commit is contained in:
commit
a6af5406f7
@ -1682,6 +1682,9 @@ The following event stream types are available:
|
|||||||
DowntimeRemoved | Downtime removed for hosts and services.
|
DowntimeRemoved | Downtime removed for hosts and services.
|
||||||
DowntimeStarted | Downtime started for hosts and services.
|
DowntimeStarted | Downtime started for hosts and services.
|
||||||
DowntimeTriggered | Downtime triggered 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)
|
Note: Each type requires [API permissions](12-icinga2-api.md#icinga2-api-permissions)
|
||||||
being set.
|
being set.
|
||||||
@ -1694,6 +1697,14 @@ Example for all downtime events:
|
|||||||
-d '{ "types": ["DowntimeAdded", "DowntimeRemoved", "DowntimeTriggered"] }'
|
-d '{ "types": ["DowntimeAdded", "DowntimeRemoved", "DowntimeTriggered"] }'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Example for all object events:
|
||||||
|
|
||||||
|
```
|
||||||
|
&types=ObjectCreated&types=ObjectDeleted&types=ObjectModified
|
||||||
|
|
||||||
|
-d '{ "types": ["ObjectCreated", "ObjectDeleted", "ObjectModified"] }'
|
||||||
|
```
|
||||||
|
|
||||||
#### <a id="icinga2-api-event-streams-type-checkresult"></a> Event Stream Type: CheckResult
|
#### <a id="icinga2-api-event-streams-type-checkresult"></a> Event Stream Type: CheckResult
|
||||||
|
|
||||||
Name | Type | Description
|
Name | Type | Description
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include "icinga/apievents.hpp"
|
#include "icinga/apievents.hpp"
|
||||||
#include "icinga/service.hpp"
|
#include "icinga/service.hpp"
|
||||||
#include "icinga/notificationcommand.hpp"
|
#include "icinga/notificationcommand.hpp"
|
||||||
#include "remote/eventqueue.hpp"
|
|
||||||
#include "base/initialize.hpp"
|
#include "base/initialize.hpp"
|
||||||
#include "base/serializer.hpp"
|
#include "base/serializer.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
@ -30,6 +29,9 @@ void ApiEvents::StaticInitialize()
|
|||||||
Downtime::OnDowntimeRemoved.connect(&ApiEvents::DowntimeRemovedHandler);
|
Downtime::OnDowntimeRemoved.connect(&ApiEvents::DowntimeRemovedHandler);
|
||||||
Downtime::OnDowntimeStarted.connect(&ApiEvents::DowntimeStartedHandler);
|
Downtime::OnDowntimeStarted.connect(&ApiEvents::DowntimeStartedHandler);
|
||||||
Downtime::OnDowntimeTriggered.connect(&ApiEvents::DowntimeTriggeredHandler);
|
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)
|
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));
|
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<EventQueue::Ptr> 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));
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#ifndef APIEVENTS_H
|
#ifndef APIEVENTS_H
|
||||||
#define APIEVENTS_H
|
#define APIEVENTS_H
|
||||||
|
|
||||||
|
#include "remote/eventqueue.hpp"
|
||||||
#include "icinga/checkable.hpp"
|
#include "icinga/checkable.hpp"
|
||||||
#include "icinga/host.hpp"
|
#include "icinga/host.hpp"
|
||||||
|
|
||||||
@ -39,6 +40,10 @@ public:
|
|||||||
static void DowntimeRemovedHandler(const Downtime::Ptr& downtime);
|
static void DowntimeRemovedHandler(const Downtime::Ptr& downtime);
|
||||||
static void DowntimeStartedHandler(const Downtime::Ptr& downtime);
|
static void DowntimeStartedHandler(const Downtime::Ptr& downtime);
|
||||||
static void DowntimeTriggeredHandler(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);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,10 @@ enum class EventType : uint_fast8_t
|
|||||||
DowntimeTriggered,
|
DowntimeTriggered,
|
||||||
Flapping,
|
Flapping,
|
||||||
Notification,
|
Notification,
|
||||||
StateChange
|
StateChange,
|
||||||
|
ObjectCreated,
|
||||||
|
ObjectDeleted,
|
||||||
|
ObjectModified
|
||||||
};
|
};
|
||||||
|
|
||||||
class EventsInbox : public Object
|
class EventsInbox : public Object
|
||||||
|
@ -31,7 +31,10 @@ const std::map<String, EventType> l_EventTypes ({
|
|||||||
{"DowntimeTriggered", EventType::DowntimeTriggered},
|
{"DowntimeTriggered", EventType::DowntimeTriggered},
|
||||||
{"Flapping", EventType::Flapping},
|
{"Flapping", EventType::Flapping},
|
||||||
{"Notification", EventType::Notification},
|
{"Notification", EventType::Notification},
|
||||||
{"StateChange", EventType::StateChange}
|
{"StateChange", EventType::StateChange},
|
||||||
|
{"ObjectCreated", EventType::ObjectCreated},
|
||||||
|
{"ObjectDeleted", EventType::ObjectDeleted},
|
||||||
|
{"ObjectModified", EventType::ObjectModified}
|
||||||
});
|
});
|
||||||
|
|
||||||
const String l_ApiQuery ("<API query>");
|
const String l_ApiQuery ("<API query>");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user