]> granicus.if.org Git - icinga2/blob - lib/icinga/service.hpp
Merge pull request #7109 from Icinga/feature/enhance-cluster-message-send-code-docs
[icinga2] / lib / icinga / service.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef SERVICE_H
4 #define SERVICE_H
5
6 #include "icinga/i2-icinga.hpp"
7 #include "icinga/service-ti.hpp"
8 #include "icinga/macroresolver.hpp"
9 #include "icinga/host.hpp"
10 #include <tuple>
11
12 using std::tie;
13
14 namespace icinga
15 {
16
17 /**
18  * An Icinga service.
19  *
20  * @ingroup icinga
21  */
22 class Service final : public ObjectImpl<Service>, public MacroResolver
23 {
24 public:
25         DECLARE_OBJECT(Service);
26         DECLARE_OBJECTNAME(Service);
27
28         static Service::Ptr GetByNamePair(const String& hostName, const String& serviceName);
29
30         Host::Ptr GetHost() const override;
31         int GetSeverity() const override;
32
33         bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Value *result) const override;
34
35         bool IsStateOK(ServiceState state) const override;
36         void SaveLastState(ServiceState state, double timestamp) override;
37
38         static ServiceState StateFromString(const String& state);
39         static String StateToString(ServiceState state);
40
41         static StateType StateTypeFromString(const String& state);
42         static String StateTypeToString(StateType state);
43
44         static void EvaluateApplyRules(const Host::Ptr& host);
45
46 protected:
47         void OnAllConfigLoaded() override;
48         void CreateChildObjects(const Type::Ptr& childType) override;
49
50 private:
51         Host::Ptr m_Host;
52
53         static bool EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule);
54         static bool EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule);
55 };
56
57 std::pair<Host::Ptr, Service::Ptr> GetHostService(const Checkable::Ptr& checkable);
58
59 }
60
61 #endif /* SERVICE_H */