]> granicus.if.org Git - icinga2/commitdiff
Implement the log() function.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sat, 22 Mar 2014 08:47:29 +0000 (09:47 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sat, 22 Mar 2014 08:47:29 +0000 (09:47 +0100)
Refs #5846

doc/4.1-configuration-syntax.md
lib/config/avalue.cpp [deleted file]
lib/config/avalue.h [deleted file]
lib/methods/utilityfuncs.cpp
lib/methods/utilityfuncs.h

index f602b5cd861de004c28ff1cd642b9c8a98306dec..c644edb9e5661bc245fd9e8666affe7b63befacd 100644 (file)
@@ -200,6 +200,7 @@ intersection(array, array, ...) | Returns an array containing all unique element
 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
 
diff --git a/lib/config/avalue.cpp b/lib/config/avalue.cpp
deleted file mode 100644 (file)
index 742bbca..0000000
+++ /dev/null
@@ -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.");
-       }
-}
diff --git a/lib/config/avalue.h b/lib/config/avalue.h
deleted file mode 100644 (file)
index 37969ca..0000000
+++ /dev/null
@@ -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 */
-
index 4a5ae82e54d8d82056a2bc6d6d6536d21ca450d5..8b305c7ba01b4d9a04b9b9388e3abd582cad83b8 100644 (file)
@@ -23,6 +23,7 @@
 #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>
@@ -34,6 +35,7 @@ REGISTER_SCRIPTFUNCTION(match, &Utility::Match);
 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)
 {
@@ -98,3 +100,8 @@ Array::Ptr UtilityFuncs::Intersection(const std::vector<Value>& arguments)
 
        return result;
 }
+
+void UtilityFuncs::Log(const String& message)
+{
+       ::Log(LogInformation, "config", message);
+}
index 4dbbb57f40294cea500cc8d122ffa54c3ec5ab95..4bf55920d30c12681a34bb186f60a257cf0d6f1f 100644 (file)
@@ -37,6 +37,7 @@ public:
        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);