]> granicus.if.org Git - icinga2/blob - lib/config/applyrule.hpp
Ensure that *.icinga.com is used everywhere
[icinga2] / lib / config / applyrule.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/)  *
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 APPLYRULE_H
21 #define APPLYRULE_H
22
23 #include "config/i2-config.hpp"
24 #include "config/expression.hpp"
25 #include "base/debuginfo.hpp"
26 #include <boost/function.hpp>
27
28 namespace icinga
29 {
30
31 /**
32  * @ingroup config
33  */
34 class I2_CONFIG_API ApplyRule
35 {
36 public:
37         typedef std::map<String, std::vector<String> > TypeMap;
38         typedef std::map<String, std::vector<ApplyRule> > RuleMap;
39
40         String GetTargetType(void) const;
41         String GetName(void) const;
42         boost::shared_ptr<Expression> GetExpression(void) const;
43         boost::shared_ptr<Expression> GetFilter(void) const;
44         String GetPackage(void) const;
45         String GetFKVar(void) const;
46         String GetFVVar(void) const;
47         boost::shared_ptr<Expression> GetFTerm(void) const;
48         bool GetIgnoreOnError(void) const;
49         DebugInfo GetDebugInfo(void) const;
50         Dictionary::Ptr GetScope(void) const;
51         void AddMatch(void);
52         bool HasMatches(void) const;
53
54         bool EvaluateFilter(ScriptFrame& frame) const;
55
56         static void AddRule(const String& sourceType, const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
57             const boost::shared_ptr<Expression>& filter, const String& package, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm,
58             bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope);
59         static std::vector<ApplyRule>& GetRules(const String& type);
60
61         static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes);
62         static bool IsValidSourceType(const String& sourceType);
63         static bool IsValidTargetType(const String& sourceType, const String& targetType);
64         static std::vector<String> GetTargetTypes(const String& sourceType);
65
66         static void CheckMatches(void);
67
68 private:
69         String m_TargetType;
70         String m_Name;
71         boost::shared_ptr<Expression> m_Expression;
72         boost::shared_ptr<Expression> m_Filter;
73         String m_Package;
74         String m_FKVar;
75         String m_FVVar;
76         boost::shared_ptr<Expression> m_FTerm;
77         bool m_IgnoreOnError;
78         DebugInfo m_DebugInfo;
79         Dictionary::Ptr m_Scope;
80         bool m_HasMatches;
81
82         static TypeMap m_Types;
83         static RuleMap m_Rules;
84
85         ApplyRule(const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
86             const boost::shared_ptr<Expression>& filter, const String& package, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm,
87             bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope);
88 };
89
90 }
91
92 #endif /* APPLYRULE_H */