]> granicus.if.org Git - icinga2/blob - lib/icinga/host.h
bf1ae422eb79b0fc831fda39f0bc52ac442a7ef1
[icinga2] / lib / icinga / host.h
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)    *
4  *                                                                            *
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.                     *
9  *                                                                            *
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.                               *
14  *                                                                            *
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  ******************************************************************************/
19
20 #ifndef HOST_H
21 #define HOST_H
22
23 #include "icinga/i2-icinga.h"
24 #include "icinga/host.th"
25 #include "icinga/macroresolver.h"
26 #include "icinga/checkresult.h"
27 #include "config/applyrule.h"
28 #include "base/array.h"
29 #include "base/dictionary.h"
30
31 namespace icinga
32 {
33
34 class Service;
35 class Dependency;
36
37 /**
38  * The state of a host.
39  *
40  * @ingroup icinga
41  */
42 enum HostState
43 {
44         HostUp = 0,
45         HostDown = 1,
46         HostUnreachable = 2
47 };
48
49 enum DependencyType
50 {
51         DependencyState,
52         DependencyCheckExecution,
53         DependencyNotification
54 };
55
56 /**
57  * An Icinga host.
58  *
59  * @ingroup icinga
60  */
61 class I2_ICINGA_API Host : public ObjectImpl<Host>, public MacroResolver
62 {
63 public:
64         DECLARE_PTR_TYPEDEFS(Host);
65         DECLARE_TYPENAME(Host);
66
67         shared_ptr<Service> GetCheckService(void) const;
68
69         std::set<Host::Ptr> GetParentHosts(void) const;
70         std::set<Host::Ptr> GetChildHosts(void) const;
71         std::set<shared_ptr<Service> > GetParentServices(void) const;
72         std::set<shared_ptr<Service> > GetChildServices(void) const;
73
74         bool IsReachable(DependencyType dt = DependencyState, shared_ptr<Dependency> *failedDependency = NULL) const;
75
76         shared_ptr<Service> GetServiceByShortName(const Value& name) const;
77
78         std::set<shared_ptr<Service> > GetServices(void) const;
79         void AddService(const shared_ptr<Service>& service);
80         void RemoveService(const shared_ptr<Service>& service);
81
82         int GetTotalServices(void) const;
83
84         static HostState CalculateState(ServiceState state, bool reachable);
85
86         HostState GetState(void) const;
87         StateType GetStateType(void) const;
88         HostState GetLastState(void) const;
89         HostState GetLastHardState(void) const;
90         StateType GetLastStateType(void) const;
91         double GetLastStateChange(void) const;
92         double GetLastHardStateChange(void) const;
93         double GetLastStateUp(void) const;
94         double GetLastStateDown(void) const;
95         double GetLastStateUnreachable(void) const;
96
97         static HostState StateFromString(const String& state);
98         static String StateToString(HostState state);
99
100         static StateType StateTypeFromString(const String& state);
101         static String StateTypeToString(StateType state);
102
103         virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const;
104
105         static void RegisterApplyRuleHandler(void);
106         static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
107
108 protected:
109         virtual void Stop(void);
110
111         virtual void OnConfigLoaded(void);
112
113 private:
114         mutable boost::mutex m_ServicesMutex;
115         std::map<String, shared_ptr<Service> > m_Services;
116
117         static void RefreshServicesCache(void);
118 };
119
120 }
121
122 #endif /* HOST_H */