1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #ifndef CHECKERCOMPONENT_H
4 #define CHECKERCOMPONENT_H
6 #include "checker/checkercomponent-ti.hpp"
7 #include "icinga/service.hpp"
8 #include "base/configobject.hpp"
9 #include "base/timer.hpp"
10 #include "base/utility.hpp"
11 #include <boost/thread/mutex.hpp>
12 #include <boost/thread/condition_variable.hpp>
13 #include <boost/multi_index_container.hpp>
14 #include <boost/multi_index/ordered_index.hpp>
15 #include <boost/multi_index/key_extractors.hpp>
24 struct CheckableScheduleInfo
26 Checkable::Ptr Object;
33 struct CheckableNextCheckExtractor
35 typedef double result_type;
38 * @threadsafety Always.
40 double operator()(const CheckableScheduleInfo& csi)
49 class CheckerComponent final : public ObjectImpl<CheckerComponent>
52 DECLARE_OBJECT(CheckerComponent);
53 DECLARE_OBJECTNAME(CheckerComponent);
55 typedef boost::multi_index_container<
56 CheckableScheduleInfo,
57 boost::multi_index::indexed_by<
58 boost::multi_index::ordered_unique<boost::multi_index::member<CheckableScheduleInfo, Checkable::Ptr, &CheckableScheduleInfo::Object> >,
59 boost::multi_index::ordered_non_unique<CheckableNextCheckExtractor>
63 void OnConfigLoaded() override;
64 void Start(bool runtimeCreated) override;
65 void Stop(bool runtimeRemoved) override;
67 static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
68 unsigned long GetIdleCheckables();
69 unsigned long GetPendingCheckables();
73 boost::condition_variable m_CV;
74 bool m_Stopped{false};
77 CheckableSet m_IdleCheckables;
78 CheckableSet m_PendingCheckables;
80 Timer::Ptr m_ResultTimer;
82 void CheckThreadProc();
83 void ResultTimerHandler();
85 void ExecuteCheckHelper(const Checkable::Ptr& checkable);
87 void AdjustCheckTimer();
89 void ObjectHandler(const ConfigObject::Ptr& object);
90 void NextCheckChangedHandler(const Checkable::Ptr& checkable);
92 void RescheduleCheckTimer();
94 static CheckableScheduleInfo GetCheckableScheduleInfo(const Checkable::Ptr& checkable);
99 #endif /* CHECKERCOMPONENT_H */