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 : 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 CheckerComponent(void);
82 virtual void OnConfigLoaded(void) override;
83 virtual void Start(bool runtimeCreated) override;
84 virtual void Stop(bool runtimeRemoved) override;
86 static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
87 unsigned long GetIdleCheckables(void);
88 unsigned long GetPendingCheckables(void);
92 boost::condition_variable m_CV;
96 CheckableSet m_IdleCheckables;
97 CheckableSet m_PendingCheckables;
99 Timer::Ptr m_ResultTimer;
101 void CheckThreadProc(void);
102 void ResultTimerHandler(void);
104 void ExecuteCheckHelper(const Checkable::Ptr& checkable);
106 void AdjustCheckTimer(void);
108 void ObjectHandler(const ConfigObject::Ptr& object);
109 void NextCheckChangedHandler(const Checkable::Ptr& checkable);
111 void RescheduleCheckTimer(void);
113 static CheckableScheduleInfo GetCheckableScheduleInfo(const Checkable::Ptr& checkable);
118 #endif /* CHECKERCOMPONENT_H */