]> granicus.if.org Git - icinga2/commitdiff
Fix problems with PNP4Nagios
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 17 Sep 2014 13:38:39 +0000 (15:38 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 17 Sep 2014 13:38:39 +0000 (15:38 +0200)
fixes #7268

50 files changed:
components/checker/checkercomponent.cpp
components/checker/checkercomponent.hpp
components/compat/checkresultreader.cpp
components/compat/checkresultreader.hpp
components/compat/compatlogger.cpp
components/compat/compatlogger.hpp
components/compat/externalcommandlistener.cpp
components/compat/externalcommandlistener.hpp
components/compat/statusdatawriter.cpp
components/compat/statusdatawriter.hpp
components/db_ido_mysql/idomysqlconnection.cpp
components/db_ido_mysql/idomysqlconnection.hpp
components/db_ido_pgsql/idopgsqlconnection.cpp
components/db_ido_pgsql/idopgsqlconnection.hpp
components/livestatus/livestatuslistener.cpp
components/livestatus/livestatuslistener.hpp
components/notification/notificationcomponent.cpp
components/notification/notificationcomponent.hpp
components/perfdata/graphitewriter.cpp
components/perfdata/graphitewriter.hpp
components/perfdata/perfdatawriter.cpp
components/perfdata/perfdatawriter.hpp
lib/base/filelogger.cpp
lib/base/filelogger.hpp
lib/base/statsfunction.cpp
lib/base/statsfunction.hpp
lib/base/sysloglogger.cpp
lib/base/sysloglogger.hpp
lib/icinga/checkresult.ti
lib/icinga/cib.cpp
lib/icinga/cib.hpp
lib/icinga/externalcommandprocessor.cpp
lib/icinga/icingaapplication.cpp
lib/icinga/icingaapplication.hpp
lib/icinga/icingastatuswriter.cpp
lib/icinga/icingastatuswriter.hpp
lib/icinga/perfdatavalue.cpp
lib/icinga/perfdatavalue.hpp
lib/icinga/perfdatavalue.ti
lib/icinga/pluginutility.cpp
lib/icinga/pluginutility.hpp
lib/methods/clusterchecktask.cpp
lib/methods/icingachecktask.cpp
lib/methods/nullchecktask.cpp
lib/methods/pluginchecktask.cpp
lib/methods/randomchecktask.cpp
lib/remote/apilistener.cpp
lib/remote/apilistener.hpp
test/base-serialize.cpp
test/icinga-perfdata.cpp

index 28ff0736eb896bfb25e570eecc16d975af7c5b53..83c2368a87c6eb89c2a293fcedc1ea828befb0fd 100644 (file)
@@ -20,6 +20,7 @@
 #include "checker/checkercomponent.hpp"
 #include "icinga/icingaapplication.hpp"
 #include "icinga/cib.hpp"
+#include "icinga/perfdatavalue.hpp"
 #include "remote/apilistener.hpp"
 #include "base/dynamictype.hpp"
 #include "base/objectlock.hpp"
@@ -36,7 +37,7 @@ REGISTER_TYPE(CheckerComponent);
 
 REGISTER_STATSFUNCTION(CheckerComponentStats, &CheckerComponent::StatsFunc);
 
-Value CheckerComponent::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
+Value CheckerComponent::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
@@ -51,8 +52,8 @@ Value CheckerComponent::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perf
                nodes->Set(checker->GetName(), stats);
 
                String perfdata_prefix = "checkercomponent_" + checker->GetName() + "_";
-               perfdata->Set(perfdata_prefix + "idle", Convert::ToDouble(idle));
-               perfdata->Set(perfdata_prefix + "pending", Convert::ToDouble(pending));
+               perfdata->Add(make_shared<PerfdataValue>(perfdata_prefix + "idle", Convert::ToDouble(idle)));
+               perfdata->Add(make_shared<PerfdataValue>(perfdata_prefix + "pending", Convert::ToDouble(pending)));
        }
 
        status->Set("checkercomponent", nodes);
index 7ed8b0745a38dc1668c4c8539d9eb1d93aa9a6de..ad83ad980821db38ffd5572de46d8f43b8318302 100644 (file)
@@ -72,7 +72,7 @@ public:
        virtual void Start(void);
        virtual void Stop(void);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
        unsigned long GetIdleCheckables(void);
        unsigned long GetPendingCheckables(void);
 
index 436593168ea6cddf771e99622893239cbcbedea6..cf22abb6eab55f59c4cb3b816ea6631bd0488ab8 100644 (file)
@@ -38,7 +38,7 @@ REGISTER_TYPE(CheckResultReader);
 
 REGISTER_STATSFUNCTION(CheckResultReaderStats, &CheckResultReader::StatsFunc);
 
-Value CheckResultReader::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr&)
+Value CheckResultReader::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
index 12655eebd3491f5746c591bd345a17b57c32f9d4..84d3d23bdc62beeabc7dee743ce4bb99353bbc9b 100644 (file)
@@ -38,7 +38,7 @@ public:
        DECLARE_PTR_TYPEDEFS(CheckResultReader);
        DECLARE_TYPENAME(CheckResultReader);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
 
 protected:
        virtual void Start(void);
index 969cc74485ac4c5ef209a12116ec6e171c4bdcd3..e4ca628e653f9ee2febce4f211ad3d20501c7e0b 100644 (file)
@@ -45,7 +45,7 @@ REGISTER_SCRIPTFUNCTION(ValidateRotationMethod, &CompatLogger::ValidateRotationM
 
 REGISTER_STATSFUNCTION(CompatLoggerStats, &CompatLogger::StatsFunc);
 
-Value CompatLogger::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr&)
+Value CompatLogger::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
index 512d2a349a5e79d1d4088de0b0e710ea727f6a8e..c29c09d4887e7a6bdf558f26c1c92c598f2e2f64 100644 (file)
@@ -39,7 +39,7 @@ public:
        DECLARE_PTR_TYPEDEFS(CompatLogger);
        DECLARE_TYPENAME(CompatLogger);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
 
        static void ValidateRotationMethod(const String& location, const Dictionary::Ptr& attrs);
 
index 9174bb9dbb67104f0798cb143ac13532fa9a453c..dca4ea3f546723fc84d3996f1a12265c8cda525d 100644 (file)
@@ -31,7 +31,7 @@ REGISTER_TYPE(ExternalCommandListener);
 
 REGISTER_STATSFUNCTION(ExternalCommandListenerStats, &ExternalCommandListener::StatsFunc);
 
-Value ExternalCommandListener::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr&)
+Value ExternalCommandListener::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
index 0006aec33567ee64e5f79fb6314b8565cfd50f6c..49494c890f7592584372a895c5b299fab753f412 100644 (file)
@@ -39,7 +39,7 @@ public:
        DECLARE_PTR_TYPEDEFS(ExternalCommandListener);
        DECLARE_TYPENAME(ExternalCommandListener);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
 
 protected:
        virtual void Start(void);
index 328d9b9ec6161d2bd392180b8c06b48e616ab446..e4c3549d48e271cbdb1a5a5b5f7d6c42fa4091a8 100644 (file)
@@ -48,7 +48,7 @@ REGISTER_TYPE(StatusDataWriter);
 
 REGISTER_STATSFUNCTION(StatusDataWriterStats, &StatusDataWriter::StatsFunc);
 
-Value StatusDataWriter::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr&)
+Value StatusDataWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
index 9c8125bffefd408941f77b5417ac8f372df1c366..3024bb101746d5ec5d449cd5ba976a40e0dcf601 100644 (file)
@@ -44,7 +44,7 @@ public:
        DECLARE_PTR_TYPEDEFS(StatusDataWriter);
        DECLARE_TYPENAME(StatusDataWriter);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
 
 protected:
        virtual void Start(void);
index f8a82a68efb2ecc60e963ef2edcfcf825085bba3..61b4f5060f5540916555dbd923ea03984800790a 100644 (file)
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
+#include "icinga/perfdatavalue.hpp"
+#include "db_ido/dbtype.hpp"
+#include "db_ido/dbvalue.hpp"
+#include "db_ido_mysql/idomysqlconnection.hpp"
 #include "base/logger_fwd.hpp"
 #include "base/objectlock.hpp"
 #include "base/convert.hpp"
@@ -25,9 +29,6 @@
 #include "base/dynamictype.hpp"
 #include "base/exception.hpp"
 #include "base/statsfunction.hpp"
-#include "db_ido/dbtype.hpp"
-#include "db_ido/dbvalue.hpp"
-#include "db_ido_mysql/idomysqlconnection.hpp"
 #include <boost/tuple/tuple.hpp>
 #include <boost/foreach.hpp>
 
@@ -38,7 +39,7 @@ using namespace icinga;
 REGISTER_TYPE(IdoMysqlConnection);
 REGISTER_STATSFUNCTION(IdoMysqlConnectionStats, &IdoMysqlConnection::StatsFunc);
 
-Value IdoMysqlConnection::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
+Value IdoMysqlConnection::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
@@ -52,7 +53,7 @@ Value IdoMysqlConnection::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& pe
 
                nodes->Set(idomysqlconnection->GetName(), stats);
 
-               perfdata->Set("idomysqlconnection_" + idomysqlconnection->GetName() + "_query_queue_items", Convert::ToDouble(items));
+               perfdata->Add(make_shared<PerfdataValue>("idomysqlconnection_" + idomysqlconnection->GetName() + "_query_queue_items", items));
        }
 
        status->Set("idomysqlconnection", nodes);
index 188dcaf702fb01a44d3e5c69459b39c6b349b434..aa9c11dcd911da2337c1a8bd38445b943722e6d8 100644 (file)
@@ -42,7 +42,7 @@ public:
        DECLARE_PTR_TYPEDEFS(IdoMysqlConnection);
        DECLARE_TYPENAME(IdoMysqlConnection);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
 
 protected:
        virtual void Resume(void);
index 045c4f3ccded9417238e46e6dc6270efcd911574..cb14e53314023c82bd6732bafc58647cc833a8e4 100644 (file)
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
+#include "db_ido/dbtype.hpp"
+#include "db_ido/dbvalue.hpp"
+#include "db_ido_pgsql/idopgsqlconnection.hpp"
+#include "icinga/perfdatavalue.hpp"
 #include "base/logger_fwd.hpp"
 #include "base/objectlock.hpp"
 #include "base/convert.hpp"
@@ -26,9 +30,6 @@
 #include "base/exception.hpp"
 #include "base/context.hpp"
 #include "base/statsfunction.hpp"
-#include "db_ido/dbtype.hpp"
-#include "db_ido/dbvalue.hpp"
-#include "db_ido_pgsql/idopgsqlconnection.hpp"
 #include <boost/tuple/tuple.hpp>
 #include <boost/foreach.hpp>
 
@@ -40,7 +41,7 @@ REGISTER_TYPE(IdoPgsqlConnection);
 
 REGISTER_STATSFUNCTION(IdoPgsqlConnectionStats, &IdoPgsqlConnection::StatsFunc);
 
-Value IdoPgsqlConnection::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
+Value IdoPgsqlConnection::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
@@ -54,7 +55,7 @@ Value IdoPgsqlConnection::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& pe
 
                nodes->Set(idopgsqlconnection->GetName(), stats);
 
-               perfdata->Set("idopgsqlconnection_" + idopgsqlconnection->GetName() + "_query_queue_items", Convert::ToDouble(items));
+               perfdata->Add(make_shared<PerfdataValue>("idopgsqlconnection_" + idopgsqlconnection->GetName() + "_query_queue_items", items));
        }
 
        status->Set("idopgsqlconnection", nodes);
index ff137dcc5b0c5a3b2e097ee490b15198021466f8..c2da9647c04bc851eafc9598a482e598145aad79 100644 (file)
@@ -42,7 +42,7 @@ public:
        DECLARE_PTR_TYPEDEFS(IdoPgsqlConnection);
        DECLARE_TYPENAME(IdoPgsqlConnection);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
 
 protected:
        virtual void Resume(void);
index 5c67c35ce2bd22930574a28811f6aab994688c94..90baa8b2a33d26ede50c1a07df9164fe67457dcd 100644 (file)
@@ -18,6 +18,7 @@
  ******************************************************************************/
 
 #include "livestatus/livestatuslistener.hpp"
+#include "icinga/perfdatavalue.hpp"
 #include "config/configcompilercontext.hpp"
 #include "base/utility.hpp"
 #include "base/objectlock.hpp"
@@ -43,7 +44,7 @@ static boost::mutex l_ComponentMutex;
 
 REGISTER_STATSFUNCTION(LivestatusListenerStats, &LivestatusListener::StatsFunc);
 
-Value LivestatusListener::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
+Value LivestatusListener::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
@@ -53,7 +54,7 @@ Value LivestatusListener::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& pe
 
                nodes->Set(livestatuslistener->GetName(), stats);
 
-               perfdata->Set("livestatuslistener_" + livestatuslistener->GetName() + "_connections", Convert::ToDouble(l_Connections));
+               perfdata->Add(make_shared<PerfdataValue>("livestatuslistener_" + livestatuslistener->GetName() + "_connections", l_Connections));
        }
 
        status->Set("livestatuslistener", nodes);
index 5ddc0ac188c785e32529cb9a2e8e801be766ea7b..56672721a023bdc975b974556c1aad7ff8bdbb61 100644 (file)
@@ -39,7 +39,7 @@ public:
        DECLARE_PTR_TYPEDEFS(LivestatusListener);
        DECLARE_TYPENAME(LivestatusListener);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
 
        static int GetClientsConnected(void);
        static int GetConnections(void);
index 73999421af57df9264f8b54d206c39a374924c5b..09c08958dfb0a2083d49490de045c21d0f02d7f5 100644 (file)
@@ -34,7 +34,7 @@ REGISTER_TYPE(NotificationComponent);
 
 REGISTER_STATSFUNCTION(NotificationComponentStats, &NotificationComponent::StatsFunc);
 
-Value NotificationComponent::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr&)
+Value NotificationComponent::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
index 6365e8cb0d14864041a5e51deeb6d4f992ad94f9..babca98970c1cd24d6dd9d750597ea3287836831 100644 (file)
@@ -37,7 +37,7 @@ public:
        DECLARE_PTR_TYPEDEFS(NotificationComponent);
        DECLARE_TYPENAME(NotificationComponent);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
 
        virtual void Start(void);
 
index e806089adab5c05df946df3021744a99bedf51a5..fc87a91658d46ba75a9b2ff40c10001ecfba0991 100644 (file)
@@ -46,7 +46,7 @@ REGISTER_TYPE(GraphiteWriter);
 
 REGISTER_STATSFUNCTION(GraphiteWriterStats, &GraphiteWriter::StatsFunc);
 
-Value GraphiteWriter::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr&)
+Value GraphiteWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
@@ -134,34 +134,28 @@ void GraphiteWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
 
 void GraphiteWriter::SendPerfdata(const String& prefix, const CheckResult::Ptr& cr)
 {
-       Value pdv = cr->GetPerformanceData();
-
-       if (pdv.IsEmpty())
-               return;
-
-       if (!pdv.IsObjectType<Dictionary>())
-       {
-               CONTEXT("Processing performance data value '" + String(pdv) + "'");
-               Log(LogWarning, "GraphiteWriter", "Could not send performance data: unparsed data.");
-               return;
-       }
-
-       Dictionary::Ptr perfdata = pdv;
+       Array::Ptr perfdata = cr->GetPerformanceData();
 
        ObjectLock olock(perfdata);
-       BOOST_FOREACH(const Dictionary::Pair& kv, perfdata) {
-               double valueNum;
-
-               if (!kv.second.IsObjectType<PerfdataValue>())
-                       valueNum = kv.second;
-               else
-                       valueNum = static_cast<PerfdataValue::Ptr>(kv.second)->GetValue();
-
-               String escaped_key = kv.first;
+       BOOST_FOREACH(const Value& val, perfdata) {
+               PerfdataValue::Ptr pdv;
+               
+               if (val.IsObjectType<PerfdataValue>())
+                       pdv = val;
+               else {
+                       try {
+                               pdv = PerfdataValue::Parse(val);
+                       } catch (const std::exception&) {
+                               Log(LogWarning, "GraphiteWriter", "Ignoring invalid perfdata value: " + val);
+                               continue;
+                       }
+               }
+               
+               String escaped_key = pdv->GetLabel();
                SanitizeMetric(escaped_key);
                boost::algorithm::replace_all(escaped_key, "::", ".");
 
-               SendMetric(prefix, escaped_key, valueNum);
+               SendMetric(prefix, escaped_key, pdv->GetValue());
        }
 }
 
index 7eeb595a3ea8585b0d996256d0ba34c37d33c7f1..c2ca0519168531653f62c1e82d827e7563565494 100644 (file)
@@ -41,7 +41,7 @@ public:
        DECLARE_PTR_TYPEDEFS(GraphiteWriter);
        DECLARE_TYPENAME(GraphiteWriter);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
 
 protected:
        virtual void Start(void);
index 213d7b9bd4f360343509a56f9bb970dd48248607..92c4b6784459f104af6dc28911fc080085c704fd 100644 (file)
@@ -36,7 +36,7 @@ REGISTER_TYPE(PerfdataWriter);
 
 REGISTER_STATSFUNCTION(PerfdataWriterStats, &PerfdataWriter::StatsFunc);
 
-Value PerfdataWriter::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr&)
+Value PerfdataWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
index e8a5bdb12386ad0b34264b2a3dbee6773196dccc..b7d48e560490398184c174b9f43667c53bf90e73 100644 (file)
@@ -40,7 +40,7 @@ public:
        DECLARE_PTR_TYPEDEFS(PerfdataWriter);
        DECLARE_TYPENAME(PerfdataWriter);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
 
 protected:
        virtual void Start(void);
index e075e8cb2a0f3a989b6fead81f696b37d7562afe..f92ced19861ea7723fac28548cccec144e351b1d 100644 (file)
@@ -29,7 +29,7 @@ REGISTER_TYPE(FileLogger);
 
 REGISTER_STATSFUNCTION(FileLoggerStats, &FileLogger::StatsFunc);
 
-Value FileLogger::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr&)
+Value FileLogger::StatsFunc(Dictionary::Ptr& status, Array::Ptr&)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
index 072caa6afae899549bb1ba224acd8042729464d4..4130d6d0e2ffd76d105ad3d34d22c825b37181d8 100644 (file)
@@ -37,7 +37,7 @@ public:
        DECLARE_PTR_TYPEDEFS(FileLogger);
        DECLARE_TYPENAME(FileLogger);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(Dictionary::Ptr& status, Array::Ptr& perfdata);
 
        virtual void Start(void);
 
index cfaa50fc2353bb2ed100c10b4ef3567d1b2ca1cb..42d12b9c4284df408284225be55ce3f99fbcf7b8 100644 (file)
@@ -27,7 +27,7 @@ StatsFunction::StatsFunction(const Callback& function)
        : m_Callback(function)
 { }
 
-Value StatsFunction::Invoke(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
+Value StatsFunction::Invoke(Dictionary::Ptr& status, Array::Ptr& perfdata)
 {
        return m_Callback(status, perfdata);
 }
index d38073a5a174c0beb2d7bfa84d56355bc219e128..3f08565deacda305d873785ac6d8c3423bad141c 100644 (file)
@@ -24,6 +24,7 @@
 #include "base/registry.hpp"
 #include "base/value.hpp"
 #include "base/dictionary.hpp"
+#include "base/array.hpp"
 #include <boost/function.hpp>
 
 namespace icinga
@@ -39,11 +40,11 @@ class I2_BASE_API StatsFunction : public Object
 public:
        DECLARE_PTR_TYPEDEFS(StatsFunction);
 
-       typedef boost::function<Value (Dictionary::Ptr& status, Dictionary::Ptr& perfdata)> Callback;
+       typedef boost::function<Value (Dictionary::Ptr& status, Array::Ptr& perfdata)> Callback;
 
        StatsFunction(const Callback& function);
 
-       Value Invoke(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       Value Invoke(Dictionary::Ptr& status, Array::Ptr& perfdata);
 
 private:
        Callback m_Callback;
index 01a9cff0dd0f1cb4819e4ed0061b540556651473..d0f26dddcf5790f4a819b1d1c4d34451fc9952ce 100644 (file)
@@ -28,7 +28,7 @@ REGISTER_TYPE(SyslogLogger);
 
 REGISTER_STATSFUNCTION(SyslogLoggerStats, &SyslogLogger::StatsFunc);
 
-Value SyslogLogger::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr&)
+Value SyslogLogger::StatsFunc(Dictionary::Ptr& status, Array::Ptr&)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
index 968840f480392d3a6ad23e9eadb260ffd6a28a80..694e44b01377cbf7f1fa424c50884c0651079a0a 100644 (file)
@@ -38,7 +38,7 @@ public:
        DECLARE_PTR_TYPEDEFS(SyslogLogger);
        DECLARE_TYPENAME(SyslogLogger);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(Dictionary::Ptr& status, Array::Ptr& perfdata);
 
 protected:
        virtual void ProcessLogEntry(const LogEntry& entry);
index 8f1ff12c69ba399714b07bc3097296ce860c90fa..91c7e8d6be62bcb21ebc9e0b3e1abf709eead640 100644 (file)
@@ -50,7 +50,7 @@ safe class CheckResult
 
        [state, enum] ServiceState "state";
        [state] String output;
-       [state] Value performance_data;
+       [state] Array::Ptr performance_data;
 
        [state] bool active {
                default {{{ return true; }}}
index c6dcae7a3c8681c0c569d6895d834bc1e832ac6e..245734a1d072571ab2601d291b3a344844f51582 100644 (file)
@@ -238,10 +238,10 @@ HostStatistics CIB::CalculateHostStats(void)
  * 'perfdata' must be a flat dictionary with double values
  * 'status' dictionary can contain multiple levels of dictionaries
  */
-std::pair<Dictionary::Ptr, Dictionary::Ptr> CIB::GetFeatureStats(void)
+std::pair<Dictionary::Ptr, Array::Ptr> CIB::GetFeatureStats(void)
 {
        Dictionary::Ptr status = make_shared<Dictionary>();
-       Dictionary::Ptr perfdata = make_shared<Dictionary>();
+       Array::Ptr perfdata = make_shared<Array>();
 
        String name;
        Value ret;
index 8269f92504d3d7c93fc1897c1204caae5d0c2ff8..c475f0daf3a9d2e12f17b677978b7c4210d5a0cc 100644 (file)
@@ -23,6 +23,7 @@
 #include "icinga/i2-icinga.hpp"
 #include "base/ringbuffer.hpp"
 #include "base/dictionary.hpp"
+#include "base/array.hpp"
 
 namespace icinga
 {
@@ -84,7 +85,7 @@ public:
        static HostStatistics CalculateHostStats(void);
        static ServiceStatistics CalculateServiceStats(void);
 
-       static std::pair<Dictionary::Ptr, Dictionary::Ptr> GetFeatureStats(void);
+       static std::pair<Dictionary::Ptr, Array::Ptr> GetFeatureStats(void);
 
 private:
        CIB(void);
index 5fdf49592488e5c2e762c92884d15cc3e6da5641..2a7b632d9a724c26661676b67165737a78c62815 100644 (file)
@@ -306,13 +306,7 @@ void ExternalCommandProcessor::ProcessHostCheckResult(double time, const std::ve
        CheckResult::Ptr result = make_shared<CheckResult>();
        std::pair<String, String> co = PluginUtility::ParseCheckOutput(arguments[2]);
        result->SetOutput(co.first);
-
-       Value perfdata = co.second;
-
-       if (host->GetEnablePerfdata())
-               perfdata = PluginUtility::ParsePerfdata(perfdata);
-
-       result->SetPerformanceData(perfdata);
+       result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
 
        ServiceState state;
 
@@ -358,13 +352,7 @@ void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const std:
        CheckResult::Ptr result = make_shared<CheckResult>();
        std::pair<String, String> co = PluginUtility::ParseCheckOutput(arguments[3]);
        result->SetOutput(co.first);
-
-       Value perfdata = co.second;
-
-       if (service->GetEnablePerfdata())
-               perfdata = PluginUtility::ParsePerfdata(perfdata);
-
-       result->SetPerformanceData(perfdata);
+       result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
        result->SetState(PluginUtility::ExitStatusToState(exitStatus));
 
        result->SetScheduleStart(time);
index f6c51666530351c38352e3ebd1ad9a7b371e40be..c0393b319d2899e57e1127ec2d0db6d4c358d345 100644 (file)
@@ -63,7 +63,7 @@ void IcingaApplication::StaticInitialize(void)
 
 REGISTER_STATSFUNCTION(IcingaApplicationStats, &IcingaApplication::StatsFunc);
 
-Value IcingaApplication::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
+Value IcingaApplication::StatsFunc(Dictionary::Ptr& status, Array::Ptr& perfdata)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
index 7071c4a25e3d7f1cce13e3e316f9e76fe6803a35..4f159a8bfbb6acebde14d6baf4ec5fef953af102 100644 (file)
@@ -42,7 +42,7 @@ public:
 
        int Main(void);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(Dictionary::Ptr& status, Array::Ptr& perfdata);
 
        static IcingaApplication::Ptr GetInstance(void);
 
index f3c8283dd92bdfe9f2bae8358c3f9112e5f2e537..a0c52f5d1b409dbf4b2ca741c0711a0bd9569e92 100644 (file)
@@ -34,7 +34,7 @@ REGISTER_TYPE(IcingaStatusWriter);
 
 REGISTER_STATSFUNCTION(IcingaStatusWriterStats, &IcingaStatusWriter::StatsFunc);
 
-Value IcingaStatusWriter::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
+Value IcingaStatusWriter::StatsFunc(Dictionary::Ptr& status, Array::Ptr& perfdata)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
 
@@ -72,7 +72,7 @@ Dictionary::Ptr IcingaStatusWriter::GetStatusData(void)
        Dictionary::Ptr bag = make_shared<Dictionary>();
 
        /* features */
-       std::pair<Dictionary::Ptr, Dictionary::Ptr> stats = CIB::GetFeatureStats();
+       std::pair<Dictionary::Ptr, Array::Ptr> stats = CIB::GetFeatureStats();
 
        bag->Set("feature_status", stats.first);
        bag->Set("feature_perfdata", stats.second);
index b60412abb596a5aa15006ebaf0882047e9a3beef..738abbcf6fd65855c052e402ba42bcde23df7713 100644 (file)
@@ -35,7 +35,7 @@ public:
        DECLARE_PTR_TYPEDEFS(IcingaStatusWriter);
        DECLARE_TYPENAME(IcingaStatusWriter);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(Dictionary::Ptr& status, Array::Ptr& perfdata);
        static Dictionary::Ptr GetStatusData(void);
 
 protected:
index e34d833ee7b7d1fbb4df465d8d8752e5fd3d964a..4a0f3d601563671fceccf61973e7129bf46a0a5f 100644 (file)
@@ -31,9 +31,11 @@ REGISTER_TYPE(PerfdataValue);
 PerfdataValue::PerfdataValue(void)
 { }
 
-PerfdataValue::PerfdataValue(double value, bool counter, const String& unit,
-    const Value& warn, const Value& crit, const Value& min, const Value& max)
+PerfdataValue::PerfdataValue(String label, double value, bool counter,
+    const String& unit, const Value& warn, const Value& crit, const Value& min,
+    const Value& max)
 {
+       SetLabel(label);
        SetValue(value);
        SetCounter(counter);
        SetUnit(unit);
@@ -43,23 +45,38 @@ PerfdataValue::PerfdataValue(double value, bool counter, const String& unit,
        SetMax(max);
 }
 
-Value PerfdataValue::Parse(const String& perfdata)
+PerfdataValue::Ptr PerfdataValue::Parse(const String& perfdata)
 {
-       size_t pos = perfdata.FindFirstNotOf("+-0123456789.e");
+       size_t eqp = perfdata.FindFirstOf('=');
 
-       double value = Convert::ToDouble(perfdata.SubStr(0, pos));
+       if (eqp == String::NPos)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid performance data value: " + perfdata));
 
-       if (pos == String::NPos)
-               return value;
+       String label = perfdata.SubStr(0, eqp);
+
+       if (label.GetLength() > 2 && label[0] == '\'' && label[label.GetLength() - 1] == '\'')
+               label = label.SubStr(1, label.GetLength() - 2);
+
+       size_t spq = perfdata.FindFirstOf(' ', eqp);
+
+       if (spq == String::NPos)
+               spq = perfdata.GetLength();
+
+       String valueStr = perfdata.SubStr(eqp + 1, spq - eqp - 1);
+               
+       size_t pos = valueStr.FindFirstNotOf("+-0123456789.e");
+
+       double value = Convert::ToDouble(valueStr.SubStr(0, pos));
 
        std::vector<String> tokens;
-       boost::algorithm::split(tokens, perfdata, boost::is_any_of(";"));
+       boost::algorithm::split(tokens, valueStr, boost::is_any_of(";"));
 
        bool counter = false;
        String unit;
        Value warn, crit, min, max;
 
-       unit = perfdata.SubStr(pos, tokens[0].GetLength() - pos);
+       if (pos != String::NPos)
+               unit = valueStr.SubStr(pos, tokens[0].GetLength() - pos);
 
        boost::algorithm::to_lower(unit);
 
@@ -122,48 +139,48 @@ Value PerfdataValue::Parse(const String& perfdata)
        if (!max.IsEmpty())
                max = max * base;
 
-       return make_shared<PerfdataValue>(value, counter, unit, warn, crit, min, max);
+       return make_shared<PerfdataValue>(label, value, counter, unit, warn, crit, min, max);
 }
 
-String PerfdataValue::Format(const Value& perfdata)
+String PerfdataValue::Format(void) const
 {
-       if (perfdata.IsObjectType<PerfdataValue>()) {
-               PerfdataValue::Ptr pdv = perfdata;
-               std::ostringstream result;
+       std::ostringstream result;
 
-               result << Convert::ToString(pdv->GetValue());
+       if (GetLabel().FindFirstOf(" ") != String::NPos)
+               result << "'" << GetLabel() << "'";
+       else
+               result << GetLabel();
 
-               String unit;
+       result << "=" << Convert::ToString(GetValue());
 
-               if (pdv->GetCounter())
-                       unit = "c";
-               else if (pdv->GetUnit() == "seconds")
-                       unit = "s";
-               else if (pdv->GetUnit() == "percent")
-                       unit = "%";
-               else if (pdv->GetUnit() == "bytes")
-                       unit = "B";
+       String unit;
+
+       if (GetCounter())
+               unit = "c";
+       else if (GetUnit() == "seconds")
+               unit = "s";
+       else if (GetUnit() == "percent")
+               unit = "%";
+       else if (GetUnit() == "bytes")
+               unit = "B";
 
-               result << unit;
+       result << unit;
 
-               if (!pdv->GetWarn().IsEmpty()) {
-                       result << ";" << pdv->GetWarn();
+       if (!GetWarn().IsEmpty()) {
+               result << ";" << Convert::ToString(GetWarn());
 
-                       if (!pdv->GetCrit().IsEmpty()) {
-                               result << ";" << pdv->GetCrit();
+               if (!GetCrit().IsEmpty()) {
+                       result << ";" << Convert::ToString(GetCrit());
 
-                               if (!pdv->GetMin().IsEmpty()) {
-                                       result << ";" << pdv->GetMin();
+                       if (!GetMin().IsEmpty()) {
+                               result << ";" << Convert::ToString(GetMin());
 
-                                       if (!pdv->GetMax().IsEmpty()) {
-                                               result << ";" << pdv->GetMax();
-                                       }
+                               if (!GetMax().IsEmpty()) {
+                                       result << ";" << Convert::ToString(GetMax());
                                }
                        }
                }
-
-               return result.str();
-       } else {
-               return perfdata;
        }
+
+       return result.str();
 }
index 6d299e03c45cfa571ef84383334086d07af44a42..019f590aa5a1b311932da9e8bef1cb7a7a077f45 100644 (file)
@@ -33,12 +33,12 @@ public:
 
        PerfdataValue(void);
 
-       PerfdataValue(double value, bool counter = false, const String& unit = "",
+       PerfdataValue(String label, double value, bool counter = false, const String& unit = "",
            const Value& warn = Empty, const Value& crit = Empty,
            const Value& min = Empty, const Value& max = Empty);
 
-       static Value Parse(const String& perfdata);
-       static String Format(const Value& perfdata);
+       static PerfdataValue::Ptr Parse(const String& perfdata);
+       String Format(void) const;
 };
 
 }
index 0c6ad37029a2ba001c080148fc97a8751c95aee0..752d2f1a9dbe26e772f137589f04d2bba92f4010 100644 (file)
@@ -5,6 +5,7 @@ namespace icinga
 
 safe class PerfdataValue
 {
+       [state] String label;
        [state] double value;
        [state] bool counter;
        [state] String unit;
index ab34b9821b94a62c42487674f8f0f8eddac1041b..715ea66ee248e877157b771d6cb32eb5cb72d150 100644 (file)
@@ -220,80 +220,73 @@ std::pair<String, String> PluginUtility::ParseCheckOutput(const String& output)
        return std::make_pair(text, perfdata);
 }
 
-Value PluginUtility::ParsePerfdata(const String& perfdata)
+Array::Ptr PluginUtility::SplitPerfdata(const String& perfdata)
 {
-       try {
-               Dictionary::Ptr result = make_shared<Dictionary>();
+       Array::Ptr result = make_shared<Array>();
 
-               size_t begin = 0;
-               String multi_prefix;
+       size_t begin = 0;
+       String multi_prefix;
 
-               for (;;) {
-                       size_t eqp = perfdata.FindFirstOf('=', begin);
+       for (;;) {
+               size_t eqp = perfdata.FindFirstOf('=', begin);
 
-                       if (eqp == String::NPos)
-                               break;
+               if (eqp == String::NPos)
+                       break;
 
-                       String key = perfdata.SubStr(begin, eqp - begin);
+               String label = perfdata.SubStr(begin, eqp - begin);
 
-                       if (key.GetLength() > 2 && key[0] == '\'' && key[key.GetLength() - 1] == '\'')
-                               key = key.SubStr(1, key.GetLength() - 2);
+               if (label.GetLength() > 2 && label[0] == '\'' && label[label.GetLength() - 1] == '\'')
+                       label = label.SubStr(1, label.GetLength() - 2);
 
-                       size_t multi_index = key.RFind("::");
+               size_t multi_index = label.RFind("::");
 
-                       if (multi_index != String::NPos)
-                               multi_prefix = "";
+               if (multi_index != String::NPos)
+                       multi_prefix = "";
 
-                       size_t spq = perfdata.FindFirstOf(' ', eqp);
+               size_t spq = perfdata.FindFirstOf(' ', eqp);
 
-                       if (spq == String::NPos)
-                               spq = perfdata.GetLength();
+               if (spq == String::NPos)
+                       spq = perfdata.GetLength();
 
-                       String value = perfdata.SubStr(eqp + 1, spq - eqp - 1);
+               String value = perfdata.SubStr(eqp + 1, spq - eqp - 1);
 
-                       if (!multi_prefix.IsEmpty())
-                               key = multi_prefix + "::" + key;
+               if (!multi_prefix.IsEmpty())
+                       label = multi_prefix + "::" + label;
 
-                       result->Set(key, PerfdataValue::Parse(value));
+               String pdv;
+               if (label.FindFirstOf(" ") != String::NPos)
+                       pdv = "'" + label + "'=" + value;
+               else
+                       pdv = label + "=" + value;
 
-                       if (multi_index != String::NPos)
-                               multi_prefix = key.SubStr(0, multi_index);
+               result->Add(pdv);
 
-                       begin = spq + 1;
-               }
+               if (multi_index != String::NPos)
+                       multi_prefix = label.SubStr(0, multi_index);
 
-               return result;
-       } catch (const std::exception& ex) {
-               Log(LogWarning, "PluginUtility", "Error parsing performance data '" + perfdata + "': " + ex.what());
-               return perfdata;
+               begin = spq + 1;
        }
+
+       return result;
 }
 
-String PluginUtility::FormatPerfdata(const Value& perfdata)
+String PluginUtility::FormatPerfdata(const Array::Ptr& perfdata)
 {
        std::ostringstream result;
 
-       if (!perfdata.IsObjectType<Dictionary>())
-               return perfdata;
-
-       Dictionary::Ptr dict = perfdata;
-
-       ObjectLock olock(dict);
+       ObjectLock olock(perfdata);
 
        bool first = true;
-       BOOST_FOREACH(const Dictionary::Pair& kv, dict) {
-               String key;
-               if (kv.first.FindFirstOf(" ") != String::NPos)
-                       key = "'" + kv.first + "'";
-               else
-                       key = kv.first;
-
+       BOOST_FOREACH(const Value& pdv, perfdata) {
                if (!first)
                        result << " ";
                else
                        first = false;
 
-               result << key << "=" << PerfdataValue::Format(kv.second);
+               if (pdv.IsObjectType<PerfdataValue>())
+                       result << static_cast<PerfdataValue::Ptr>(pdv)->Format();
+               else
+                       result << pdv;
        }
 
        return result.str();
index 94a6819d8deab1abe0fe5f44cd85d31e69135713..309aaa26f466ffca56b8fa18a751ed7a5eac08c2 100644 (file)
@@ -46,8 +46,8 @@ public:
        static ServiceState ExitStatusToState(int exitStatus);
        static std::pair<String, String> ParseCheckOutput(const String& output);
 
-       static Value ParsePerfdata(const String& perfdata);
-       static String FormatPerfdata(const Value& perfdata);
+       static Array::Ptr SplitPerfdata(const String& perfdata);
+       static String FormatPerfdata(const Array::Ptr& perfdata);
 
 private:
        PluginUtility(void);
index 51cc0c65c014f6d2c0f42320951d3c7530a53c65..efbe4ad0882bd25c89262f42b9612c602ccef4e7 100644 (file)
@@ -52,7 +52,7 @@ void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRe
        Dictionary::Ptr status = stats.first;
 
        /* use feature stats perfdata */
-       std::pair<Dictionary::Ptr, Dictionary::Ptr> feature_stats = CIB::GetFeatureStats();
+       std::pair<Dictionary::Ptr, Array::Ptr> feature_stats = CIB::GetFeatureStats();
        cr->SetPerformanceData(feature_stats.second);
 
        String connected_endpoints = FormatArray(status->Get("conn_endpoints"));
index 47d5adeb09ad4008ea46e88ab4cea16b251ec417..445f367ec00fbefb77fd61b0e05fd378fb04beb1 100644 (file)
@@ -21,6 +21,7 @@
 #include "icinga/cib.hpp"
 #include "icinga/service.hpp"
 #include "icinga/icingaapplication.hpp"
+#include "icinga/perfdatavalue.hpp"
 #include "base/application.hpp"
 #include "base/objectlock.hpp"
 #include "base/utility.hpp"
@@ -38,58 +39,58 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResul
        if (interval > 60)
                interval = 60;
 
-       Dictionary::Ptr perfdata = make_shared<Dictionary>();
-
-       perfdata->Set("active_host_checks", CIB::GetActiveHostChecksStatistics(interval) / interval);
-       perfdata->Set("passive_host_checks", CIB::GetPassiveHostChecksStatistics(interval) / interval);
-       perfdata->Set("active_host_checks_1min", CIB::GetActiveHostChecksStatistics(60));
-       perfdata->Set("passive_host_checks_1min", CIB::GetPassiveHostChecksStatistics(60));
-       perfdata->Set("active_host_checks_5min", CIB::GetActiveHostChecksStatistics(60 * 5));
-       perfdata->Set("passive_host_checks_5min", CIB::GetPassiveHostChecksStatistics(60 * 5));
-       perfdata->Set("active_host_checks_15min", CIB::GetActiveHostChecksStatistics(60 * 15));
-       perfdata->Set("passive_host_checks_15min", CIB::GetPassiveHostChecksStatistics(60 * 15));
-
-       perfdata->Set("active_service_checks", CIB::GetActiveServiceChecksStatistics(interval) / interval);
-       perfdata->Set("passive_service_checks", CIB::GetPassiveServiceChecksStatistics(interval) / interval);
-       perfdata->Set("active_service_checks_1min", CIB::GetActiveServiceChecksStatistics(60));
-       perfdata->Set("passive_service_checks_1min", CIB::GetPassiveServiceChecksStatistics(60));
-       perfdata->Set("active_service_checks_5min", CIB::GetActiveServiceChecksStatistics(60 * 5));
-       perfdata->Set("passive_service_checks_5min", CIB::GetPassiveServiceChecksStatistics(60 * 5));
-       perfdata->Set("active_service_checks_15min", CIB::GetActiveServiceChecksStatistics(60 * 15));
-       perfdata->Set("passive_service_checks_15min", CIB::GetPassiveServiceChecksStatistics(60 * 15));
+       Array::Ptr perfdata = make_shared<Array>();
+
+       perfdata->Add(make_shared<PerfdataValue>("active_host_checks", CIB::GetActiveHostChecksStatistics(interval) / interval));
+       perfdata->Add(make_shared<PerfdataValue>("passive_host_checks", CIB::GetPassiveHostChecksStatistics(interval) / interval));
+       perfdata->Add(make_shared<PerfdataValue>("active_host_checks_1min", CIB::GetActiveHostChecksStatistics(60)));
+       perfdata->Add(make_shared<PerfdataValue>("passive_host_checks_1min", CIB::GetPassiveHostChecksStatistics(60)));
+       perfdata->Add(make_shared<PerfdataValue>("active_host_checks_5min", CIB::GetActiveHostChecksStatistics(60 * 5)));
+       perfdata->Add(make_shared<PerfdataValue>("passive_host_checks_5min", CIB::GetPassiveHostChecksStatistics(60 * 5)));
+       perfdata->Add(make_shared<PerfdataValue>("active_host_checks_15min", CIB::GetActiveHostChecksStatistics(60 * 15)));
+       perfdata->Add(make_shared<PerfdataValue>("passive_host_checks_15min", CIB::GetPassiveHostChecksStatistics(60 * 15)));
+
+       perfdata->Add(make_shared<PerfdataValue>("active_service_checks", CIB::GetActiveServiceChecksStatistics(interval) / interval));
+       perfdata->Add(make_shared<PerfdataValue>("passive_service_checks", CIB::GetPassiveServiceChecksStatistics(interval) / interval));
+       perfdata->Add(make_shared<PerfdataValue>("active_service_checks_1min", CIB::GetActiveServiceChecksStatistics(60)));
+       perfdata->Add(make_shared<PerfdataValue>("passive_service_checks_1min", CIB::GetPassiveServiceChecksStatistics(60)));
+       perfdata->Add(make_shared<PerfdataValue>("active_service_checks_5min", CIB::GetActiveServiceChecksStatistics(60 * 5)));
+       perfdata->Add(make_shared<PerfdataValue>("passive_service_checks_5min", CIB::GetPassiveServiceChecksStatistics(60 * 5)));
+       perfdata->Add(make_shared<PerfdataValue>("active_service_checks_15min", CIB::GetActiveServiceChecksStatistics(60 * 15)));
+       perfdata->Add(make_shared<PerfdataValue>("passive_service_checks_15min", CIB::GetPassiveServiceChecksStatistics(60 * 15)));
 
        CheckableCheckStatistics scs = CIB::CalculateServiceCheckStats();
 
-       perfdata->Set("min_latency", scs.min_latency);
-       perfdata->Set("max_latency", scs.max_latency);
-       perfdata->Set("avg_latency", scs.avg_latency);
-       perfdata->Set("min_execution_time", scs.min_latency);
-       perfdata->Set("max_execution_time", scs.max_latency);
-       perfdata->Set("avg_execution_time", scs.avg_execution_time);
+       perfdata->Add(make_shared<PerfdataValue>("min_latency", scs.min_latency));
+       perfdata->Add(make_shared<PerfdataValue>("max_latency", scs.max_latency));
+       perfdata->Add(make_shared<PerfdataValue>("avg_latency", scs.avg_latency));
+       perfdata->Add(make_shared<PerfdataValue>("min_execution_time", scs.min_latency));
+       perfdata->Add(make_shared<PerfdataValue>("max_execution_time", scs.max_latency));
+       perfdata->Add(make_shared<PerfdataValue>("avg_execution_time", scs.avg_execution_time));
 
        ServiceStatistics ss = CIB::CalculateServiceStats();
 
-       perfdata->Set("num_services_ok", ss.services_ok);
-       perfdata->Set("num_services_warning", ss.services_warning);
-       perfdata->Set("num_services_critical", ss.services_critical);
-       perfdata->Set("num_services_unknown", ss.services_unknown);
-       perfdata->Set("num_services_pending", ss.services_pending);
-       perfdata->Set("num_services_unreachable", ss.services_unreachable);
-       perfdata->Set("num_services_flapping", ss.services_flapping);
-       perfdata->Set("num_services_in_downtime", ss.services_in_downtime);
-       perfdata->Set("num_services_acknowledged", ss.services_acknowledged);
+       perfdata->Add(make_shared<PerfdataValue>("num_services_ok", ss.services_ok));
+       perfdata->Add(make_shared<PerfdataValue>("num_services_warning", ss.services_warning));
+       perfdata->Add(make_shared<PerfdataValue>("num_services_critical", ss.services_critical));
+       perfdata->Add(make_shared<PerfdataValue>("num_services_unknown", ss.services_unknown));
+       perfdata->Add(make_shared<PerfdataValue>("num_services_pending", ss.services_pending));
+       perfdata->Add(make_shared<PerfdataValue>("num_services_unreachable", ss.services_unreachable));
+       perfdata->Add(make_shared<PerfdataValue>("num_services_flapping", ss.services_flapping));
+       perfdata->Add(make_shared<PerfdataValue>("num_services_in_downtime", ss.services_in_downtime));
+       perfdata->Add(make_shared<PerfdataValue>("num_services_acknowledged", ss.services_acknowledged));
 
        double uptime = Utility::GetTime() - Application::GetStartTime();
-       perfdata->Set("uptime", uptime);
+       perfdata->Add(make_shared<PerfdataValue>("uptime", uptime));
 
        HostStatistics hs = CIB::CalculateHostStats();
 
-       perfdata->Set("num_hosts_up", hs.hosts_up);
-       perfdata->Set("num_hosts_down", hs.hosts_down);
-       perfdata->Set("num_hosts_unreachable", hs.hosts_unreachable);
-       perfdata->Set("num_hosts_flapping", hs.hosts_flapping);
-       perfdata->Set("num_hosts_in_downtime", hs.hosts_in_downtime);
-       perfdata->Set("num_hosts_acknowledged", hs.hosts_acknowledged);
+       perfdata->Add(make_shared<PerfdataValue>("num_hosts_up", hs.hosts_up));
+       perfdata->Add(make_shared<PerfdataValue>("num_hosts_down", hs.hosts_down));
+       perfdata->Add(make_shared<PerfdataValue>("num_hosts_unreachable", hs.hosts_unreachable));
+       perfdata->Add(make_shared<PerfdataValue>("num_hosts_flapping", hs.hosts_flapping));
+       perfdata->Add(make_shared<PerfdataValue>("num_hosts_in_downtime", hs.hosts_in_downtime));
+       perfdata->Add(make_shared<PerfdataValue>("num_hosts_acknowledged", hs.hosts_acknowledged));
 
        cr->SetOutput("Icinga 2 has been running for " + Utility::FormatDuration(uptime) +
            ". Version: " + Application::GetVersion());
index e3f5142acc863823867274f3d50fb1ff98b99c15..b0e558d8309d62d1a9de5ff53a77b158d49a5b29 100644 (file)
@@ -21,6 +21,7 @@
 #      include <stdlib.h>
 #endif /* _WIN32 */
 #include "methods/nullchecktask.hpp"
+#include "icinga/perfdatavalue.hpp"
 #include "base/utility.hpp"
 #include "base/convert.hpp"
 #include "base/scriptfunction.hpp"
@@ -35,8 +36,8 @@ void NullCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult:
        String output = "Hello from ";
        output += Utility::GetFQDN();
 
-       Dictionary::Ptr perfdata = make_shared<Dictionary>();
-       perfdata->Set("time", Convert::ToDouble(Utility::GetTime()));
+       Array::Ptr perfdata = make_shared<Array>();
+       perfdata->Add(make_shared<PerfdataValue>("time", Convert::ToDouble(Utility::GetTime())));
 
        cr->SetOutput(output);
        cr->SetPerformanceData(perfdata);
index 39716cce253cf868a19da9d6872561368bd43ff1..e261f56fd64842e5b57d6135887010fc18b3c08e 100644 (file)
@@ -68,13 +68,7 @@ void PluginCheckTask::ProcessFinishedHandler(const Checkable::Ptr& checkable, co
        std::pair<String, String> co = PluginUtility::ParseCheckOutput(output);
        cr->SetCommand(commandLine);
        cr->SetOutput(co.first);
-
-       Value perfdata = co.second;
-
-       if (checkable->GetEnablePerfdata())
-               perfdata = PluginUtility::ParsePerfdata(perfdata);
-
-       cr->SetPerformanceData(perfdata);
+       cr->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
        cr->SetState(PluginUtility::ExitStatusToState(pr.ExitStatus));
        cr->SetExitStatus(pr.ExitStatus);
        cr->SetExecutionStart(pr.ExecutionStart);
index f4f78111b8f475cd4ccc12480a0a4a7e26283f6e..6034a9a453a35a15bf74fab7a91b18c084a94846 100644 (file)
@@ -20,8 +20,8 @@
 #ifndef _WIN32
 #      include <stdlib.h>
 #endif /* _WIN32 */
-#include "icinga/icingaapplication.hpp"
 #include "methods/randomchecktask.hpp"
+#include "icinga/perfdatavalue.hpp"
 #include "base/utility.hpp"
 #include "base/convert.hpp"
 #include "base/scriptfunction.hpp"
@@ -36,8 +36,8 @@ void RandomCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResul
        String output = "Hello from ";
        output += Utility::GetFQDN();
 
-       Dictionary::Ptr perfdata = make_shared<Dictionary>();
-       perfdata->Set("time", Convert::ToDouble(Utility::GetTime()));
+       Array::Ptr perfdata = make_shared<Array>();
+       perfdata->Add(make_shared<PerfdataValue>("time", Convert::ToDouble(Utility::GetTime())));
 
        cr->SetOutput(output);
        cr->SetPerformanceData(perfdata);
index d2e19a284e90767393128a991a6dd69e57ff3cf5..d2015f345fcff1e72274fd0f909dc8d5cd133bca 100644 (file)
@@ -712,7 +712,7 @@ void ApiListener::ReplayLog(const ApiClient::Ptr& client)
        }
 }
 
-Value ApiListener::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
+Value ApiListener::StatsFunc(Dictionary::Ptr& status, Array::Ptr& perfdata)
 {
        Dictionary::Ptr nodes = make_shared<Dictionary>();
        std::pair<Dictionary::Ptr, Dictionary::Ptr> stats;
@@ -724,8 +724,8 @@ Value ApiListener::StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata)
 
        stats = listener->GetStatus();
 
-       BOOST_FOREACH(Dictionary::Pair const& kv, stats.second)
-               perfdata->Set("api_" + kv.first, kv.second);
+       BOOST_FOREACH(const Dictionary::Pair& kv, stats.second)
+               perfdata->Add("'api_" + kv.first + "'=" + Convert::ToString(kv.second));
 
        status->Set("api", stats.first);
 
index 4d0c925d9ffa9625396eec32d80b77a9b7063d75..855ae2df72fd3eb67dac8237ec5de3e9f5910176 100644 (file)
@@ -58,7 +58,7 @@ public:
 
        void RelayMessage(const MessageOrigin& origin, const DynamicObject::Ptr& secobj, const Dictionary::Ptr& message, bool log);
 
-       static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
+       static Value StatsFunc(Dictionary::Ptr& status, Array::Ptr& perfdata);
        std::pair<Dictionary::Ptr, Dictionary::Ptr> GetStatus(void);
 
        void AddAnonymousClient(const ApiClient::Ptr& aclient);
index 1e9b8698551e856034bf7eced5eb7c22de1e4bb9..26d6dc471da2cae94973b693ef4c7f76b497552d 100644 (file)
@@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(dictionary)
 
 BOOST_AUTO_TEST_CASE(object)
 {
-       PerfdataValue::Ptr pdv = make_shared<PerfdataValue>(100, true, "bytes");
+       PerfdataValue::Ptr pdv = make_shared<PerfdataValue>("size", 100, true, "bytes");
 
        PerfdataValue::Ptr result = Deserialize(Serialize(pdv));
 
index acca81a00d600006be1c1651dc2b4dfd9b85ffa4..a84b0de1e8a6879f050c28459917b3b4b0738bb8 100644 (file)
@@ -27,30 +27,34 @@ BOOST_AUTO_TEST_SUITE(icinga_perfdata)
 
 BOOST_AUTO_TEST_CASE(empty)
 {
-       Dictionary::Ptr pd = PluginUtility::ParsePerfdata("");
+       Array::Ptr pd = PluginUtility::SplitPerfdata("");
        BOOST_CHECK(pd->GetLength() == 0);
 }
 
 BOOST_AUTO_TEST_CASE(simple)
 {
-       Dictionary::Ptr pd = PluginUtility::ParsePerfdata("test=123456");
-       BOOST_CHECK(pd->Get("test") == 123456);
+       PerfdataValue::Ptr pdv = PerfdataValue::Parse("test=123456");
+       BOOST_CHECK(pdv->GetLabel() == "test");
+       BOOST_CHECK(pdv->GetValue() == 123456);
 
-       String str = PluginUtility::FormatPerfdata(pd);
+       String str = pdv->Format();
        BOOST_CHECK(str == "test=123456");
 }
 
 BOOST_AUTO_TEST_CASE(quotes)
 {
-       Dictionary::Ptr pd = PluginUtility::ParsePerfdata("'hello world'=123456");
-       BOOST_CHECK(pd->Get("hello world") == 123456);
+       Array::Ptr pd = PluginUtility::SplitPerfdata("'hello world'=123456");
+       BOOST_CHECK(pd->GetLength() == 1);
+       
+       PerfdataValue::Ptr pdv = PerfdataValue::Parse("'hello world'=123456");
+       BOOST_CHECK(pdv->GetLabel() == "hello world");
+       BOOST_CHECK(pdv->GetValue() == 123456);
 }
 
 BOOST_AUTO_TEST_CASE(multiple)
 {
-       Dictionary::Ptr pd = PluginUtility::ParsePerfdata("testA=123456 testB=123456");
-       BOOST_CHECK(pd->Get("testA") == 123456);
-       BOOST_CHECK(pd->Get("testB") == 123456);
+       Array::Ptr pd = PluginUtility::SplitPerfdata("testA=123456 testB=123456");
+       BOOST_CHECK(pd->GetLength() == 2);
 
        String str = PluginUtility::FormatPerfdata(pd);
        BOOST_CHECK(str == "testA=123456 testB=123456");
@@ -58,9 +62,7 @@ BOOST_AUTO_TEST_CASE(multiple)
 
 BOOST_AUTO_TEST_CASE(uom)
 {
-       Dictionary::Ptr pd = PluginUtility::ParsePerfdata("test=123456B");
-
-       PerfdataValue::Ptr pv = pd->Get("test");
+       PerfdataValue::Ptr pv = PerfdataValue::Parse("test=123456B");
        BOOST_CHECK(pv);
 
        BOOST_CHECK(pv->GetValue() == 123456);
@@ -71,13 +73,10 @@ BOOST_AUTO_TEST_CASE(uom)
        BOOST_CHECK(pv->GetMin() == Empty);
        BOOST_CHECK(pv->GetMax() == Empty);
 
-       String str = PluginUtility::FormatPerfdata(pd);
+       String str = pv->Format();
        BOOST_CHECK(str == "test=123456B");
 
-       pd = PluginUtility::ParsePerfdata("test=1000ms;200;500");
-       BOOST_CHECK(pd);
-
-       pv = pd->Get("test");
+       pv = PerfdataValue::Parse("test=1000ms;200;500");
        BOOST_CHECK(pv);
 
        BOOST_CHECK(pv->GetValue() == 1);
@@ -85,10 +84,7 @@ BOOST_AUTO_TEST_CASE(uom)
        BOOST_CHECK(pv->GetWarn() == 0.2);
        BOOST_CHECK(pv->GetCrit() == 0.5);
 
-       pd = PluginUtility::ParsePerfdata("test=1000ms");
-       BOOST_CHECK(pd);
-
-       pv = pd->Get("test");
+       pv = PerfdataValue::Parse("test=1000ms");
        BOOST_CHECK(pv);
 
        BOOST_CHECK(pv->GetValue() == 1);
@@ -98,15 +94,13 @@ BOOST_AUTO_TEST_CASE(uom)
        BOOST_CHECK(pv->GetMin() == Empty);
        BOOST_CHECK(pv->GetMax() == Empty);
 
-       str = PluginUtility::FormatPerfdata(pd);
+       str = pv->Format();
        BOOST_CHECK(str == "test=1s");
 }
 
 BOOST_AUTO_TEST_CASE(warncritminmax)
 {
-       Dictionary::Ptr pd = PluginUtility::ParsePerfdata("test=123456B;1000;2000;3000;4000");
-
-       PerfdataValue::Ptr pv = pd->Get("test");
+       PerfdataValue::Ptr pv = PerfdataValue::Parse("test=123456B;1000;2000;3000;4000");
        BOOST_CHECK(pv);
 
        BOOST_CHECK(pv->GetValue() == 123456);
@@ -117,21 +111,20 @@ BOOST_AUTO_TEST_CASE(warncritminmax)
        BOOST_CHECK(pv->GetMin() == 3000);
        BOOST_CHECK(pv->GetMax() == 4000);
 
-       String str = PluginUtility::FormatPerfdata(pd);
-       BOOST_CHECK(str == "test=123456B;1000;2000;3000;4000");
+       BOOST_CHECK(pv->Format() == "test=123456B;1000;2000;3000;4000");
 }
 
 BOOST_AUTO_TEST_CASE(invalid)
 {
-       BOOST_CHECK(PluginUtility::ParsePerfdata("test=1,23456") == "test=1,23456");
-       BOOST_CHECK(PluginUtility::ParsePerfdata("test=123456;10%;20%") == "test=123456;10%;20%");
+       BOOST_CHECK_THROW(PerfdataValue::Parse("test=1,23456"), boost::exception);
+       BOOST_CHECK_THROW(PerfdataValue::Parse("test=123456;10%;20%"), boost::exception);
 }
 
 BOOST_AUTO_TEST_CASE(multi)
 {
-       Dictionary::Ptr pd = PluginUtility::ParsePerfdata("test::a=3 b=4");
-       BOOST_CHECK(pd->Get("test::a") == 3);
-       BOOST_CHECK(pd->Get("test::b") == 4);
+       Array::Ptr pd = PluginUtility::SplitPerfdata("test::a=3 b=4");
+       BOOST_CHECK(pd->Get(0) == "test::a=3");
+       BOOST_CHECK(pd->Get(1) == "test::b=4");
 }
 
 BOOST_AUTO_TEST_SUITE_END()