check_interval = len(MyGroups) * 1m
}
-Function | Description
----------------------|-----------------------
-regex(pattern, text) | Returns true if the regex pattern matches the text, false otherwise.
-match(pattern, text) | Returns true if the wildcard pattern matches the text, false otherwise.
-len(value) | Returns the length of the value, i.e. the number of elements for an array or dictionary, or the length of the string in bytes.
-string(value) | Converts the value to a string.
-number(value) | Converts the value to a number.
-bool(value) | Converts to value to a bool.
+Function | Description
+--------------------------------|-----------------------
+regex(pattern, text) | Returns true if the regex pattern matches the text, false otherwise.
+match(pattern, text) | Returns true if the wildcard pattern matches the text, false otherwise.
+len(value) | Returns the length of the value, i.e. the number of elements for an array or dictionary, or the length of the string in bytes.
+union(array, array, ...) | Returns an array containing all unique elements from the specified arrays.
+intersection(array, array, ...) | Returns an array containing all unique elements which are common to all specified arrays.
+string(value) | Converts the value to a string.
+number(value) | Converts the value to a number.
+bool(value) | Converts to value to a bool.
### <a id="operators"></a> Dictionary Operators
m_Data.erase(it);
}
+void Array::Resize(size_t new_size)
+{
+ ASSERT(!OwnsLock());
+ ObjectLock olock(this);
+
+ m_Data.resize(new_size);
+}
+
void Array::CopyTo(const Array::Ptr& dest) const
{
ASSERT(!OwnsLock());
void Remove(unsigned int index);
void Remove(Iterator it);
+ void Resize(size_t new_size);
+
void CopyTo(const Array::Ptr& dest) const;
Array::Ptr ShallowClone(void) const;
{
return boost::bind(&ScriptFunctionWrapperVV, function, _1);
}
-
-boost::function<Value (const std::vector<Value>& arguments)> icinga::WrapScriptFunction(Value (*function)(const std::vector<Value>&))
-{
- return boost::bind(function, _1);
-}
return boost::bind(&ScriptFunctionWrapperR<TR, T0, T1, T2, T3, T4, T5>, function, _1);
}
-boost::function<Value (const std::vector<Value>& arguments)> I2_BASE_API WrapScriptFunction(Value (*function)(const std::vector<Value>&));
+template<typename TR>
+boost::function<TR (const std::vector<Value>& arguments)> WrapScriptFunction(TR (*function)(const std::vector<Value>&))
+{
+ return boost::bind(function, _1);
+}
}
#include "base/array.h"
#include "base/dictionary.h"
#include <boost/regex.hpp>
+#include <algorithm>
using namespace icinga;
REGISTER_SCRIPTFUNCTION(regex, &UtilityFuncs::Regex);
REGISTER_SCRIPTFUNCTION(match, &Utility::Match);
REGISTER_SCRIPTFUNCTION(len, &UtilityFuncs::Len);
+REGISTER_SCRIPTFUNCTION(union, &UtilityFuncs::Union);
+REGISTER_SCRIPTFUNCTION(intersection, &UtilityFuncs::Intersection);
bool UtilityFuncs::Regex(const String& pattern, const String& text)
{
} else {
return Convert::ToString(value).GetLength();
}
-}
\ No newline at end of file
+}
+
+Array::Ptr UtilityFuncs::Union(const std::vector<Value>& arguments)
+{
+ std::set<Value> values;
+
+ BOOST_FOREACH(const Value& varr, arguments) {
+ Array::Ptr arr = varr;
+
+ BOOST_FOREACH(const Value& value, arr) {
+ values.insert(value);
+ }
+ }
+
+ Array::Ptr result = make_shared<Array>();
+ BOOST_FOREACH(const Value& value, values) {
+ result->Add(value);
+ }
+
+ return result;
+}
+
+Array::Ptr UtilityFuncs::Intersection(const std::vector<Value>& arguments)
+{
+ if (arguments.size() == 0)
+ return make_shared<Array>();
+
+ Array::Ptr result = make_shared<Array>();
+
+ Array::Ptr arr1 = static_cast<Array::Ptr>(arguments[0])->ShallowClone();
+
+ for (int i = 1; i < arguments.size(); i++) {
+ std::sort(arr1->Begin(), arr1->End());
+
+ Array::Ptr arr2 = static_cast<Array::Ptr>(arguments[i])->ShallowClone();
+ std::sort(arr2->Begin(), arr2->End());
+
+ result->Resize(std::max(arr1->GetLength(), arr2->GetLength()));
+ Array::Iterator it = std::set_intersection(arr1->Begin(), arr1->End(), arr2->Begin(), arr2->End(), result->Begin());
+ result->Resize(it - result->Begin());
+ arr1 = result;
+ }
+
+ return result;
+}
#include "methods/i2-methods.h"
#include "base/qstring.h"
+#include "base/array.h"
namespace icinga
{
public:
static bool Regex(const String& pattern, const String& text);
static int Len(const Value& value);
+ static Array::Ptr Union(const std::vector<Value>& arguments);
+ static Array::Ptr Intersection(const std::vector<Value>& arguments);
private:
UtilityFuncs(void);