2019-02-25 08:48:22 -05:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2012-07-09 14:32:02 -04:00
|
|
|
|
2012-06-13 07:42:55 -04:00
|
|
|
#ifndef MACROPROCESSOR_H
|
|
|
|
|
#define MACROPROCESSOR_H
|
|
|
|
|
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "icinga/i2-icinga.hpp"
|
|
|
|
|
#include "icinga/checkable.hpp"
|
|
|
|
|
#include "base/value.hpp"
|
2014-05-11 11:14:35 -04:00
|
|
|
#include <vector>
|
2020-09-30 10:35:47 -04:00
|
|
|
#include <utility>
|
2013-03-17 15:19:29 -04:00
|
|
|
|
2012-06-13 07:42:55 -04:00
|
|
|
namespace icinga
|
|
|
|
|
{
|
|
|
|
|
|
2012-09-17 07:35:55 -04:00
|
|
|
/**
|
|
|
|
|
* Resolves macros.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup icinga
|
|
|
|
|
*/
|
2017-12-31 01:22:16 -05:00
|
|
|
class MacroProcessor
|
2012-06-13 07:42:55 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2020-09-30 10:35:47 -04:00
|
|
|
struct ResolverSpec
|
|
|
|
|
{
|
|
|
|
|
String Name;
|
|
|
|
|
Object::Ptr Obj;
|
|
|
|
|
|
|
|
|
|
// Whether to resolve not only e.g. $host.address$, but also just $address$
|
|
|
|
|
bool ResolveShortMacros;
|
|
|
|
|
|
|
|
|
|
inline ResolverSpec(String name, Object::Ptr obj, bool resolveShortMacros = true)
|
|
|
|
|
: Name(std::move(name)), Obj(std::move(obj)), ResolveShortMacros(resolveShortMacros)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-11-21 05:52:55 -05:00
|
|
|
typedef std::function<Value (const Value&)> EscapeCallback;
|
2014-04-08 07:23:24 -04:00
|
|
|
typedef std::vector<ResolverSpec> ResolverList;
|
2013-03-22 05:58:47 -04:00
|
|
|
|
2014-04-08 07:23:24 -04:00
|
|
|
static Value ResolveMacros(const Value& str, const ResolverList& resolvers,
|
2017-12-19 09:50:05 -05:00
|
|
|
const CheckResult::Ptr& cr = nullptr, String *missingMacro = nullptr,
|
|
|
|
|
const EscapeCallback& escapeFn = EscapeCallback(),
|
|
|
|
|
const Dictionary::Ptr& resolvedMacros = nullptr,
|
|
|
|
|
bool useResolvedMacros = false, int recursionLevel = 0);
|
2015-08-27 02:22:35 -04:00
|
|
|
|
|
|
|
|
static Value ResolveArguments(const Value& command, const Dictionary::Ptr& arguments,
|
2017-12-19 09:50:05 -05:00
|
|
|
const MacroProcessor::ResolverList& resolvers, const CheckResult::Ptr& cr,
|
|
|
|
|
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int recursionLevel = 0);
|
2013-02-13 14:08:09 -05:00
|
|
|
|
2015-02-11 10:08:02 -05:00
|
|
|
static bool ValidateMacroString(const String& macro);
|
2015-09-22 12:18:29 -04:00
|
|
|
static void ValidateCustomVars(const ConfigObject::Ptr& object, const Dictionary::Ptr& value);
|
2015-02-11 10:08:02 -05:00
|
|
|
|
2013-02-13 14:08:09 -05:00
|
|
|
private:
|
2018-01-03 22:25:35 -05:00
|
|
|
MacroProcessor();
|
2013-03-14 18:52:52 -04:00
|
|
|
|
2014-04-10 02:46:36 -04:00
|
|
|
static bool ResolveMacro(const String& macro, const ResolverList& resolvers,
|
2014-11-26 14:43:42 -05:00
|
|
|
const CheckResult::Ptr& cr, Value *result, bool *recursive_macro);
|
|
|
|
|
static Value InternalResolveMacros(const String& str,
|
2017-12-19 09:50:05 -05:00
|
|
|
const ResolverList& resolvers, const CheckResult::Ptr& cr,
|
|
|
|
|
String *missingMacro, const EscapeCallback& escapeFn,
|
|
|
|
|
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros,
|
|
|
|
|
int recursionLevel = 0);
|
2015-01-29 04:09:53 -05:00
|
|
|
static Value EvaluateFunction(const Function::Ptr& func, const ResolverList& resolvers,
|
2023-03-31 06:38:24 -04:00
|
|
|
const CheckResult::Ptr& cr,
|
2017-12-19 09:50:05 -05:00
|
|
|
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int recursionLevel);
|
2015-01-29 04:09:53 -05:00
|
|
|
|
2015-08-27 02:22:35 -04:00
|
|
|
static void AddArgumentHelper(const Array::Ptr& args, const String& key, const String& value,
|
2022-05-11 11:50:12 -04:00
|
|
|
bool add_key, bool add_value, const Value& separator);
|
2015-08-27 02:22:35 -04:00
|
|
|
static Value EscapeMacroShellArg(const Value& value);
|
|
|
|
|
|
2012-06-13 07:42:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-13 05:29:23 -04:00
|
|
|
#endif /* MACROPROCESSOR_H */
|