1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #ifndef CHECKERCOMPONENT_H
21 #define CHECKERCOMPONENT_H
23 #include "checker/checkercomponent.thpp"
24 #include "icinga/service.hpp"
25 #include "base/configobject.hpp"
26 #include "base/timer.hpp"
27 #include "base/utility.hpp"
28 #include <boost/thread/mutex.hpp>
29 #include <boost/thread/condition_variable.hpp>
30 #include <boost/multi_index_container.hpp>
31 #include <boost/multi_index/ordered_index.hpp>
32 #include <boost/multi_index/key_extractors.hpp>
41 struct CheckableScheduleInfo
43 Checkable::Ptr Object;
50 struct CheckableNextCheckExtractor
52 typedef double result_type;
55 * @threadsafety Always.
57 double operator()(const CheckableScheduleInfo& csi)
66 class CheckerComponent final : public ObjectImpl<CheckerComponent>
69 DECLARE_OBJECT(CheckerComponent);
70 DECLARE_OBJECTNAME(CheckerComponent);
72 typedef boost::multi_index_container<
73 CheckableScheduleInfo,
74 boost::multi_index::indexed_by<
75 boost::multi_index::ordered_unique<boost::multi_index::member<CheckableScheduleInfo, Checkable::Ptr, &CheckableScheduleInfo::Object> >,
76 boost::multi_index::ordered_non_unique<CheckableNextCheckExtractor>
80 void OnConfigLoaded() override;
81 void Start(bool runtimeCreated) override;
82 void Stop(bool runtimeRemoved) override;
84 static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
85 unsigned long GetIdleCheckables();
86 unsigned long GetPendingCheckables();
90 boost::condition_variable m_CV;
91 bool m_Stopped{false};
94 CheckableSet m_IdleCheckables;
95 CheckableSet m_PendingCheckables;
97 Timer::Ptr m_ResultTimer;
99 void CheckThreadProc();
100 void ResultTimerHandler();
102 void ExecuteCheckHelper(const Checkable::Ptr& checkable);
104 void AdjustCheckTimer();
106 void ObjectHandler(const ConfigObject::Ptr& object);
107 void NextCheckChangedHandler(const Checkable::Ptr& checkable);
109 void RescheduleCheckTimer();
111 static CheckableScheduleInfo GetCheckableScheduleInfo(const Checkable::Ptr& checkable);
116 #endif /* CHECKERCOMPONENT_H */