]> granicus.if.org Git - icinga2/blob - lib/icinga/service.hpp
Merge pull request #7127 from Icinga/bugfix/replay-log
[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         bool GetHandled() const override;
33
34         bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Value *result) const override;
35
36         bool IsStateOK(ServiceState state) const override;
37         void SaveLastState(ServiceState state, double timestamp) override;
38
39         static ServiceState StateFromString(const String& state);
40         static String StateToString(ServiceState state);
41
42         static StateType StateTypeFromString(const String& state);
43         static String StateTypeToString(StateType state);
44
45         static void EvaluateApplyRules(const Host::Ptr& host);
46
47 protected:
48         void OnAllConfigLoaded() override;
49         void CreateChildObjects(const Type::Ptr& childType) override;
50
51 private:
52         Host::Ptr m_Host;
53
54         static bool EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule);
55         static bool EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule);
56 };
57
58 std::pair<Host::Ptr, Service::Ptr> GetHostService(const Checkable::Ptr& checkable);
59
60 }
61
62 #endif /* SERVICE_H */