string(value) | Converts the value to a string.
number(value) | Converts the value to a number.
bool(value) | Converts to value to a bool.
+log(string) | Writes a message to the log.
### <a id="operators"></a> Dictionary Operators
+++ /dev/null
-/******************************************************************************
- * 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.");
- }
-}
+++ /dev/null
-/******************************************************************************
- * 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 */
-
#include "base/convert.h"
#include "base/array.h"
#include "base/dictionary.h"
+#include "base/logger_fwd.h"
#include <boost/regex.hpp>
#include <algorithm>
#include <set>
REGISTER_SCRIPTFUNCTION(len, &UtilityFuncs::Len);
REGISTER_SCRIPTFUNCTION(union, &UtilityFuncs::Union);
REGISTER_SCRIPTFUNCTION(intersection, &UtilityFuncs::Intersection);
+REGISTER_SCRIPTFUNCTION(log, &UtilityFuncs::Log);
bool UtilityFuncs::Regex(const String& pattern, const String& text)
{
return result;
}
+
+void UtilityFuncs::Log(const String& message)
+{
+ ::Log(LogInformation, "config", message);
+}
static int Len(const Value& value);
static Array::Ptr Union(const std::vector<Value>& arguments);
static Array::Ptr Intersection(const std::vector<Value>& arguments);
+ static void Log(const String& message);
private:
UtilityFuncs(void);