1 /******************************************************************************
3 * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
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 ******************************************************************************/
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"
38 * The state of a host.
52 DependencyCheckExecution,
53 DependencyNotification
61 class I2_ICINGA_API Host : public ObjectImpl<Host>, public MacroResolver
64 DECLARE_PTR_TYPEDEFS(Host);
65 DECLARE_TYPENAME(Host);
67 shared_ptr<Service> GetCheckService(void) const;
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;
74 bool IsReachable(DependencyType dt = DependencyState, shared_ptr<Dependency> *failedDependency = NULL) const;
76 shared_ptr<Service> GetServiceByShortName(const Value& name) const;
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);
82 int GetTotalServices(void) const;
84 static HostState CalculateState(ServiceState state, bool reachable);
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;
97 static HostState StateFromString(const String& state);
98 static String StateToString(HostState state);
100 static StateType StateTypeFromString(const String& state);
101 static String StateTypeToString(StateType state);
103 virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const;
105 static void RegisterApplyRuleHandler(void);
106 static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
109 virtual void Stop(void);
111 virtual void OnConfigLoaded(void);
114 mutable boost::mutex m_ServicesMutex;
115 std::map<String, shared_ptr<Service> > m_Services;
117 static void RefreshServicesCache(void);