2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2014-03-18 11:44:09 +01:00
|
|
|
|
|
|
|
#ifndef APPLYRULE_H
|
|
|
|
#define APPLYRULE_H
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "config/i2-config.hpp"
|
2014-10-16 17:44:06 +02:00
|
|
|
#include "config/expression.hpp"
|
2014-09-09 14:49:21 +02:00
|
|
|
#include "base/debuginfo.hpp"
|
2014-03-18 11:44:09 +01:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup config
|
|
|
|
*/
|
2017-12-31 07:22:16 +01:00
|
|
|
class ApplyRule
|
2014-03-18 11:44:09 +01:00
|
|
|
{
|
|
|
|
public:
|
2014-11-16 16:20:39 +01:00
|
|
|
typedef std::map<String, std::vector<String> > TypeMap;
|
2014-03-28 13:25:40 +01:00
|
|
|
typedef std::map<String, std::vector<ApplyRule> > RuleMap;
|
2014-03-18 11:44:09 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
String GetTargetType() const;
|
|
|
|
String GetName() const;
|
|
|
|
std::shared_ptr<Expression> GetExpression() const;
|
|
|
|
std::shared_ptr<Expression> GetFilter() const;
|
|
|
|
String GetPackage() const;
|
|
|
|
String GetFKVar() const;
|
|
|
|
String GetFVVar() const;
|
|
|
|
std::shared_ptr<Expression> GetFTerm() const;
|
|
|
|
bool GetIgnoreOnError() const;
|
|
|
|
DebugInfo GetDebugInfo() const;
|
|
|
|
Dictionary::Ptr GetScope() const;
|
|
|
|
void AddMatch();
|
|
|
|
bool HasMatches() const;
|
2014-03-18 11:44:09 +01:00
|
|
|
|
2014-12-12 15:33:02 +01:00
|
|
|
bool EvaluateFilter(ScriptFrame& frame) const;
|
2014-03-28 13:25:40 +01:00
|
|
|
|
2017-11-21 13:20:55 +01:00
|
|
|
static void AddRule(const String& sourceType, const String& targetType, const String& name, const std::shared_ptr<Expression>& expression,
|
2017-12-19 15:50:05 +01:00
|
|
|
const std::shared_ptr<Expression>& filter, const String& package, const String& fkvar, const String& fvvar, const std::shared_ptr<Expression>& fterm,
|
|
|
|
bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope);
|
2014-11-16 16:20:39 +01:00
|
|
|
static std::vector<ApplyRule>& GetRules(const String& type);
|
2014-03-18 11:44:09 +01:00
|
|
|
|
2014-11-16 16:20:39 +01:00
|
|
|
static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes);
|
2014-04-05 12:56:56 +02:00
|
|
|
static bool IsValidSourceType(const String& sourceType);
|
|
|
|
static bool IsValidTargetType(const String& sourceType, const String& targetType);
|
|
|
|
static std::vector<String> GetTargetTypes(const String& sourceType);
|
2014-03-18 11:44:09 +01:00
|
|
|
|
2018-10-09 16:41:17 +02:00
|
|
|
static void CheckMatches(bool silent);
|
2014-11-16 16:20:39 +01:00
|
|
|
|
2014-03-18 11:44:09 +01:00
|
|
|
private:
|
2014-04-05 12:56:56 +02:00
|
|
|
String m_TargetType;
|
2014-03-28 13:25:40 +01:00
|
|
|
String m_Name;
|
2017-11-21 13:20:55 +01:00
|
|
|
std::shared_ptr<Expression> m_Expression;
|
|
|
|
std::shared_ptr<Expression> m_Filter;
|
2015-08-28 17:58:29 +02:00
|
|
|
String m_Package;
|
2014-11-04 11:01:00 +01:00
|
|
|
String m_FKVar;
|
|
|
|
String m_FVVar;
|
2017-11-21 13:20:55 +01:00
|
|
|
std::shared_ptr<Expression> m_FTerm;
|
2015-10-05 12:44:11 +02:00
|
|
|
bool m_IgnoreOnError;
|
2014-03-18 11:44:09 +01:00
|
|
|
DebugInfo m_DebugInfo;
|
2014-11-22 12:21:28 +01:00
|
|
|
Dictionary::Ptr m_Scope;
|
2014-11-16 16:20:39 +01:00
|
|
|
bool m_HasMatches;
|
2014-03-18 11:44:09 +01:00
|
|
|
|
2014-11-16 16:20:39 +01:00
|
|
|
static TypeMap m_Types;
|
2014-03-18 11:44:09 +01:00
|
|
|
static RuleMap m_Rules;
|
|
|
|
|
2018-01-04 08:54:18 +01:00
|
|
|
ApplyRule(String targetType, String name, std::shared_ptr<Expression> expression,
|
|
|
|
std::shared_ptr<Expression> filter, String package, String fkvar, String fvvar, std::shared_ptr<Expression> fterm,
|
|
|
|
bool ignoreOnError, DebugInfo di, Dictionary::Ptr scope);
|
2014-03-18 11:44:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* APPLYRULE_H */
|