]> granicus.if.org Git - icinga2/blob - lib/icinga/host.hpp
Merge pull request #6727 from Icinga/feature/cluster-config-sync-stage
[icinga2] / lib / icinga / host.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef HOST_H
4 #define HOST_H
5
6 #include "icinga/i2-icinga.hpp"
7 #include "icinga/host-ti.hpp"
8 #include "icinga/macroresolver.hpp"
9 #include "icinga/checkresult.hpp"
10
11 namespace icinga
12 {
13
14 class Service;
15
16 /**
17  * An Icinga host.
18  *
19  * @ingroup icinga
20  */
21 class Host final : public ObjectImpl<Host>, public MacroResolver
22 {
23 public:
24         DECLARE_OBJECT(Host);
25         DECLARE_OBJECTNAME(Host);
26
27         intrusive_ptr<Service> GetServiceByShortName(const Value& name);
28
29         std::vector<intrusive_ptr<Service> > GetServices() const;
30         void AddService(const intrusive_ptr<Service>& service);
31         void RemoveService(const intrusive_ptr<Service>& service);
32
33         int GetTotalServices() const;
34
35         static HostState CalculateState(ServiceState state);
36
37         HostState GetState() const override;
38         HostState GetLastState() const override;
39         HostState GetLastHardState() const override;
40         int GetSeverity() const override;
41
42         bool IsStateOK(ServiceState state) const override;
43         void SaveLastState(ServiceState state, double timestamp) override;
44
45         static HostState StateFromString(const String& state);
46         static String StateToString(HostState state);
47
48         static StateType StateTypeFromString(const String& state);
49         static String StateTypeToString(StateType state);
50
51         bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Value *result) const override;
52
53 protected:
54         void Stop(bool runtimeRemoved) override;
55
56         void OnAllConfigLoaded() override;
57         void CreateChildObjects(const Type::Ptr& childType) override;
58
59 private:
60         mutable boost::mutex m_ServicesMutex;
61         std::map<String, intrusive_ptr<Service> > m_Services;
62
63         static void RefreshServicesCache();
64 };
65
66 }
67
68 #endif /* HOST_H */
69
70 #include "icinga/service.hpp"