mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 23:54:07 +02:00
parent
3afad7a96d
commit
ddbbd42c4b
@ -200,6 +200,7 @@ intersection(array, array, ...) | Returns an array containing all unique element
|
|||||||
string(value) | Converts the value to a string.
|
string(value) | Converts the value to a string.
|
||||||
number(value) | Converts the value to a number.
|
number(value) | Converts the value to a number.
|
||||||
bool(value) | Converts to value to a bool.
|
bool(value) | Converts to value to a bool.
|
||||||
|
log(string) | Writes a message to the log.
|
||||||
|
|
||||||
### <a id="operators"></a> Dictionary Operators
|
### <a id="operators"></a> Dictionary Operators
|
||||||
|
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* Icinga 2 *
|
|
||||||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or *
|
|
||||||
* modify it under the terms of the GNU General Public License *
|
|
||||||
* as published by the Free Software Foundation; either version 2 *
|
|
||||||
* of the License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the Free Software Foundation *
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#include "config/avalue.h"
|
|
||||||
#include "config/aexpression.h"
|
|
||||||
#include "base/scriptvariable.h"
|
|
||||||
|
|
||||||
using namespace icinga;
|
|
||||||
|
|
||||||
AValue::AValue(void)
|
|
||||||
: m_Type(ATSimple)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
AValue::AValue(const AExpression::Ptr& expr)
|
|
||||||
: m_Type(ATExpression), m_Expression(expr)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
AValue::AValue(AValueType type, const Value& value)
|
|
||||||
: m_Type(type), m_Value(value)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
Value AValue::Evaluate(const Dictionary::Ptr& locals) const
|
|
||||||
{
|
|
||||||
switch (m_Type) {
|
|
||||||
case ATSimple:
|
|
||||||
return m_Value;
|
|
||||||
case ATVariable:
|
|
||||||
if (locals && locals->Contains(m_Value))
|
|
||||||
return locals->Get(m_Value);
|
|
||||||
else
|
|
||||||
return ScriptVariable::Get(m_Value);
|
|
||||||
case ATThisRef:
|
|
||||||
VERIFY(!"Not implemented.");
|
|
||||||
case ATExpression:
|
|
||||||
return m_Expression->Evaluate(locals);
|
|
||||||
default:
|
|
||||||
ASSERT(!"Invalid type.");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* Icinga 2 *
|
|
||||||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or *
|
|
||||||
* modify it under the terms of the GNU General Public License *
|
|
||||||
* as published by the Free Software Foundation; either version 2 *
|
|
||||||
* of the License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the Free Software Foundation *
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef AVALUE_H
|
|
||||||
#define AVALUE_H
|
|
||||||
|
|
||||||
#include "config/i2-config.h"
|
|
||||||
#include "base/value.h"
|
|
||||||
#include "base/dictionary.h"
|
|
||||||
|
|
||||||
namespace icinga
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ingroup config
|
|
||||||
*/
|
|
||||||
enum AValueType
|
|
||||||
{
|
|
||||||
ATSimple,
|
|
||||||
ATVariable,
|
|
||||||
ATThisRef,
|
|
||||||
ATExpression
|
|
||||||
};
|
|
||||||
|
|
||||||
class AExpression;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ingroup config
|
|
||||||
*/
|
|
||||||
class I2_CONFIG_API AValue
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AValue(void);
|
|
||||||
AValue(const shared_ptr<AExpression>& expr);
|
|
||||||
AValue(AValueType type, const Value& value);
|
|
||||||
|
|
||||||
Value Evaluate(const Dictionary::Ptr& locals) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
AValueType m_Type;
|
|
||||||
Value m_Value;
|
|
||||||
shared_ptr<AExpression> m_Expression;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* AVALUE_H */
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
|||||||
#include "base/convert.h"
|
#include "base/convert.h"
|
||||||
#include "base/array.h"
|
#include "base/array.h"
|
||||||
#include "base/dictionary.h"
|
#include "base/dictionary.h"
|
||||||
|
#include "base/logger_fwd.h"
|
||||||
#include <boost/regex.hpp>
|
#include <boost/regex.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <set>
|
#include <set>
|
||||||
@ -34,6 +35,7 @@ REGISTER_SCRIPTFUNCTION(match, &Utility::Match);
|
|||||||
REGISTER_SCRIPTFUNCTION(len, &UtilityFuncs::Len);
|
REGISTER_SCRIPTFUNCTION(len, &UtilityFuncs::Len);
|
||||||
REGISTER_SCRIPTFUNCTION(union, &UtilityFuncs::Union);
|
REGISTER_SCRIPTFUNCTION(union, &UtilityFuncs::Union);
|
||||||
REGISTER_SCRIPTFUNCTION(intersection, &UtilityFuncs::Intersection);
|
REGISTER_SCRIPTFUNCTION(intersection, &UtilityFuncs::Intersection);
|
||||||
|
REGISTER_SCRIPTFUNCTION(log, &UtilityFuncs::Log);
|
||||||
|
|
||||||
bool UtilityFuncs::Regex(const String& pattern, const String& text)
|
bool UtilityFuncs::Regex(const String& pattern, const String& text)
|
||||||
{
|
{
|
||||||
@ -98,3 +100,8 @@ Array::Ptr UtilityFuncs::Intersection(const std::vector<Value>& arguments)
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UtilityFuncs::Log(const String& message)
|
||||||
|
{
|
||||||
|
::Log(LogInformation, "config", message);
|
||||||
|
}
|
||||||
|
@ -37,6 +37,7 @@ public:
|
|||||||
static int Len(const Value& value);
|
static int Len(const Value& value);
|
||||||
static Array::Ptr Union(const std::vector<Value>& arguments);
|
static Array::Ptr Union(const std::vector<Value>& arguments);
|
||||||
static Array::Ptr Intersection(const std::vector<Value>& arguments);
|
static Array::Ptr Intersection(const std::vector<Value>& arguments);
|
||||||
|
static void Log(const String& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UtilityFuncs(void);
|
UtilityFuncs(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user