From 56ae875861ab260b80a030f50c4aff9f9dc8fff0 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:32:39 +0200 Subject: Adding upstream version 2.14.2. Signed-off-by: Daniel Baumann --- lib/checker/checkercomponent.hpp | 99 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 lib/checker/checkercomponent.hpp (limited to 'lib/checker/checkercomponent.hpp') diff --git a/lib/checker/checkercomponent.hpp b/lib/checker/checkercomponent.hpp new file mode 100644 index 0000000..5ace757 --- /dev/null +++ b/lib/checker/checkercomponent.hpp @@ -0,0 +1,99 @@ +/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ + +#ifndef CHECKERCOMPONENT_H +#define CHECKERCOMPONENT_H + +#include "checker/checkercomponent-ti.hpp" +#include "icinga/service.hpp" +#include "base/configobject.hpp" +#include "base/timer.hpp" +#include "base/utility.hpp" +#include +#include +#include +#include +#include +#include + +namespace icinga +{ + +/** + * @ingroup checker + */ +struct CheckableScheduleInfo +{ + Checkable::Ptr Object; + double NextCheck; +}; + +/** + * @ingroup checker + */ +struct CheckableNextCheckExtractor +{ + typedef double result_type; + + /** + * @threadsafety Always. + */ + double operator()(const CheckableScheduleInfo& csi) + { + return csi.NextCheck; + } +}; + +/** + * @ingroup checker + */ +class CheckerComponent final : public ObjectImpl +{ +public: + DECLARE_OBJECT(CheckerComponent); + DECLARE_OBJECTNAME(CheckerComponent); + + typedef boost::multi_index_container< + CheckableScheduleInfo, + boost::multi_index::indexed_by< + boost::multi_index::ordered_unique >, + boost::multi_index::ordered_non_unique + > + > CheckableSet; + + void OnConfigLoaded() override; + void Start(bool runtimeCreated) override; + void Stop(bool runtimeRemoved) override; + + static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata); + unsigned long GetIdleCheckables(); + unsigned long GetPendingCheckables(); + +private: + std::mutex m_Mutex; + std::condition_variable m_CV; + bool m_Stopped{false}; + std::thread m_Thread; + + CheckableSet m_IdleCheckables; + CheckableSet m_PendingCheckables; + + Timer::Ptr m_ResultTimer; + + void CheckThreadProc(); + void ResultTimerHandler(); + + void ExecuteCheckHelper(const Checkable::Ptr& checkable); + + void AdjustCheckTimer(); + + void ObjectHandler(const ConfigObject::Ptr& object); + void NextCheckChangedHandler(const Checkable::Ptr& checkable); + + void RescheduleCheckTimer(); + + static CheckableScheduleInfo GetCheckableScheduleInfo(const Checkable::Ptr& checkable); +}; + +} + +#endif /* CHECKERCOMPONENT_H */ -- cgit v1.2.3