]> granicus.if.org Git - icinga2/commitdiff
CompatUtility: Use functionality in compat/ido/livestatus.
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 31 Oct 2013 13:18:20 +0000 (14:18 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 31 Oct 2013 15:08:55 +0000 (16:08 +0100)
refs #4735

components/compat/compatlogger.cpp
components/livestatus/hoststable.cpp
components/livestatus/servicestable.cpp
doc/3.12-status-data.md
doc/3.13-compat-logging.md
lib/db_ido/servicedbobject.cpp
lib/icinga/compatutility.cpp
lib/icinga/compatutility.h
lib/icinga/service-check.cpp
lib/icinga/service.h

index f0bc0dd3a1782353f6914b70e2c39e424763fd47..92fdf511e981c33417a4324e58147c5a28199011 100644 (file)
@@ -23,6 +23,7 @@
 #include "icinga/notification.h"
 #include "icinga/macroprocessor.h"
 #include "icinga/externalcommandprocessor.h"
+#include "icinga/compatutility.h"
 #include "config/configcompilercontext.h"
 #include "base/dynamictype.h"
 #include "base/objectlock.h"
@@ -98,17 +99,11 @@ void CompatLogger::CheckResultHandler(const Service::Ptr& service, const Diction
                        return; /* Nothing changed, ignore this checkresult. */
        }
 
-        String raw_output;
-        String output;
-
-        if (cr) {
-                raw_output = cr->Get("output");
-                size_t line_end = raw_output.Find("\n");
-
-                output = raw_output.SubStr(0, line_end);
-
-                boost::algorithm::replace_all(output, "\n", "\\n");
-        }
+       String output;
+       if (cr) {
+               Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr);
+               output = output_bag->Get("output");
+       }
 
        std::ostringstream msgbuf;
        msgbuf << "SERVICE ALERT: "
@@ -274,14 +269,10 @@ void CompatLogger::NotificationSentHandler(const Service::Ptr& service, const Us
                 return;
 
        String output;
-       String raw_output;
-
-        if (cr) {
-                raw_output = cr->Get("output");
-                size_t line_end = raw_output.Find("\n");
-
-                output = raw_output.SubStr(0, line_end);
-        }
+       if (cr) {
+               Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr);
+               output = output_bag->Get("output");
+       }
 
         std::ostringstream msgbuf;
         msgbuf << "SERVICE NOTIFICATION: "
@@ -463,13 +454,21 @@ void CompatLogger::ReopenFile(bool rotate)
 
                ObjectLock olock(hc);
 
+               String output;
+               Dictionary::Ptr cr = hc->GetLastCheckResult();
+
+               if (cr) {
+                       Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr);
+                       output = output_bag->Get("output");
+               }
+
                std::ostringstream msgbuf;
                msgbuf << "CURRENT HOST STATE: "
                       << host->GetName() << ";"
                       << Host::StateToString(Host::CalculateState(hc->GetState(), reachable)) << ";"
                       << Service::StateTypeToString(hc->GetStateType()) << ";"
                       << hc->GetCheckAttempt() << ";"
-                      << hc->GetLastCheckOutput() << "";
+                      << output << "";
 
                WriteLine(msgbuf.str());
        }
@@ -480,6 +479,14 @@ void CompatLogger::ReopenFile(bool rotate)
                if (!host)
                        continue;
 
+               String output;
+               Dictionary::Ptr cr = service->GetLastCheckResult();
+
+               if (cr) {
+                       Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr);
+                       output = output_bag->Get("output");
+               }
+
                std::ostringstream msgbuf;
                msgbuf << "CURRENT SERVICE STATE: "
                       << host->GetName() << ";"
@@ -487,7 +494,7 @@ void CompatLogger::ReopenFile(bool rotate)
                       << Service::StateToString(service->GetState()) << ";"
                       << Service::StateTypeToString(service->GetStateType()) << ";"
                       << service->GetCheckAttempt() << ";"
-                      << service->GetLastCheckOutput() << "";
+                      << output << "";
 
                WriteLine(msgbuf.str());
        }
index e49a4c68c91b27599ca977c23de6cfab97cef45d..a385cf527d04b1bcead09df8f43bc7a337759e6f 100644 (file)
@@ -176,7 +176,7 @@ void HostsTable::FetchRows(const AddRowFunction& addRowFn)
 Value HostsTable::NameAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -186,7 +186,7 @@ Value HostsTable::NameAccessor(const Value& row)
 Value HostsTable::DisplayNameAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -196,7 +196,7 @@ Value HostsTable::DisplayNameAccessor(const Value& row)
 Value HostsTable::AddressAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -211,7 +211,7 @@ Value HostsTable::AddressAccessor(const Value& row)
 Value HostsTable::Address6Accessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -227,7 +227,7 @@ Value HostsTable::CheckCommandAccessor(const Value& row)
 {
 
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -248,7 +248,7 @@ Value HostsTable::CheckCommandExpandedAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -299,7 +299,7 @@ Value HostsTable::EventHandlerAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -319,7 +319,7 @@ Value HostsTable::NotificationPeriodAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -345,7 +345,7 @@ Value HostsTable::CheckPeriodAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -365,7 +365,7 @@ Value HostsTable::CheckPeriodAccessor(const Value& row)
 Value HostsTable::NotesAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -428,7 +428,7 @@ Value HostsTable::NotesUrlAccessor(const Value& row)
 Value HostsTable::NotesUrlExpandedAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -476,7 +476,7 @@ Value HostsTable::ActionUrlAccessor(const Value& row)
 Value HostsTable::ActionUrlExpandedAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -510,15 +510,22 @@ Value HostsTable::PluginOutputAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
        Service::Ptr hc = host->GetCheckService();
        String output;
 
-       if(hc)
-               output = hc->GetLastCheckOutput();
+       if(hc) {
+               String output;
+               Dictionary::Ptr cr = hc->GetLastCheckResult();
+
+               if (cr) {
+                       Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr);
+                       output = output_bag->Get("output");
+               }
+       }
 
        return output;
 }
@@ -527,15 +534,19 @@ Value HostsTable::PerfDataAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
        Service::Ptr hc = host->GetCheckService();
        String perfdata;
 
-       if (hc)
-               perfdata = hc->GetLastCheckPerfData();
+       if (hc) {
+               Dictionary::Ptr cr = hc->GetLastCheckResult();
+
+               if (cr)
+                       perfdata = CompatUtility::GetCheckResultPerfdata(cr);
+       }
 
        return perfdata;
 }
@@ -544,7 +555,7 @@ Value HostsTable::IconImageAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -559,7 +570,7 @@ Value HostsTable::IconImageAccessor(const Value& row)
 Value HostsTable::IconImageExpandedAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -592,7 +603,7 @@ Value HostsTable::IconImageExpandedAccessor(const Value& row)
 Value HostsTable::IconImageAltAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -607,7 +618,7 @@ Value HostsTable::IconImageAltAccessor(const Value& row)
 Value HostsTable::StatusmapImageAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -623,15 +634,22 @@ Value HostsTable::LongPluginOutputAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
        Service::Ptr hc = host->GetCheckService();
        String long_output;
 
-       if (hc)
-               long_output = hc->GetLastCheckLongOutput();
+       if (hc) {
+               String long_output;
+               Dictionary::Ptr cr = hc->GetLastCheckResult();
+
+               if (cr) {
+                       Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr);
+                       long_output = output_bag->Get("long_output");
+               }
+       }
 
        return long_output;
 }
@@ -640,7 +658,7 @@ Value HostsTable::MaxCheckAttemptsAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -656,7 +674,7 @@ Value HostsTable::FlapDetectionEnabledAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -672,7 +690,7 @@ Value HostsTable::AcceptPassiveChecksAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -688,7 +706,7 @@ Value HostsTable::EventHandlerEnabledAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -708,7 +726,7 @@ Value HostsTable::AcknowledgementTypeAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -727,7 +745,7 @@ Value HostsTable::CheckTypeAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -742,7 +760,7 @@ Value HostsTable::CheckTypeAccessor(const Value& row)
 Value HostsTable::LastStateAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -752,7 +770,7 @@ Value HostsTable::LastStateAccessor(const Value& row)
 Value HostsTable::LastHardStateAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -763,7 +781,7 @@ Value HostsTable::CurrentAttemptAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -779,7 +797,7 @@ Value HostsTable::LastNotificationAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -802,7 +820,7 @@ Value HostsTable::NextNotificationAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -825,7 +843,7 @@ Value HostsTable::NextCheckAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -841,7 +859,7 @@ Value HostsTable::LastHardStateChangeAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -857,7 +875,7 @@ Value HostsTable::HasBeenCheckedAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -873,7 +891,7 @@ Value HostsTable::CurrentNotificationNumberAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -896,7 +914,7 @@ Value HostsTable::CurrentNotificationNumberAccessor(const Value& row)
 Value HostsTable::TotalServicesAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -907,7 +925,7 @@ Value HostsTable::ChecksEnabledAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -923,7 +941,7 @@ Value HostsTable::NotificationsEnabledAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -939,7 +957,7 @@ Value HostsTable::AcknowledgedAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -958,7 +976,7 @@ Value HostsTable::StateAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -969,7 +987,7 @@ Value HostsTable::StateTypeAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -980,7 +998,7 @@ Value HostsTable::NoMoreNotificationsAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1006,7 +1024,7 @@ Value HostsTable::LastCheckAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1022,7 +1040,7 @@ Value HostsTable::LastStateChangeAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1033,7 +1051,7 @@ Value HostsTable::LastTimeUpAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1044,7 +1062,7 @@ Value HostsTable::LastTimeDownAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1055,7 +1073,7 @@ Value HostsTable::LastTimeUnreachableAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1066,7 +1084,7 @@ Value HostsTable::IsFlappingAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1082,7 +1100,7 @@ Value HostsTable::ScheduledDowntimeDepthAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1099,7 +1117,7 @@ Value HostsTable::ActiveChecksEnabledAccessor(const Value& row)
        /* duplicate of ChecksEnableAccessor */
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1121,7 +1139,7 @@ Value HostsTable::ModifiedAttributesAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1143,7 +1161,7 @@ Value HostsTable::CheckIntervalAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1159,7 +1177,7 @@ Value HostsTable::RetryIntervalAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1175,7 +1193,7 @@ Value HostsTable::NotificationIntervalAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1201,7 +1219,7 @@ Value HostsTable::LowFlapThresholdAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1217,7 +1235,7 @@ Value HostsTable::HighFlapThresholdAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1232,7 +1250,7 @@ Value HostsTable::HighFlapThresholdAccessor(const Value& row)
 Value HostsTable::X2dAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1255,7 +1273,7 @@ Value HostsTable::X2dAccessor(const Value& row)
 Value HostsTable::Y2dAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1279,7 +1297,7 @@ Value HostsTable::LatencyAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1295,7 +1313,7 @@ Value HostsTable::ExecutionTimeAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1311,7 +1329,7 @@ Value HostsTable::PercentStateChangeAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1327,7 +1345,7 @@ Value HostsTable::InNotificationPeriodAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1354,7 +1372,7 @@ Value HostsTable::InCheckPeriodAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1376,7 +1394,7 @@ Value HostsTable::ContactsAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1398,7 +1416,7 @@ Value HostsTable::DowntimesAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1433,7 +1451,7 @@ Value HostsTable::DowntimesWithInfoAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1472,7 +1490,7 @@ Value HostsTable::CommentsAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1507,7 +1525,7 @@ Value HostsTable::CommentsWithInfoAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1546,7 +1564,7 @@ Value HostsTable::CommentsWithExtraInfoAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1586,31 +1604,25 @@ Value HostsTable::CommentsWithExtraInfoAccessor(const Value& row)
 Value HostsTable::CustomVariableNamesAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
-       Dictionary::Ptr custom = host->GetCustom();
+       Dictionary::Ptr customvars;
 
-       if (!custom)
+       {
+               ObjectLock olock(host);
+               customvars = CompatUtility::GetCustomVariableConfig(host);
+       }
+
+       if (!customvars)
                return Empty;
 
        Array::Ptr cv = boost::make_shared<Array>();
 
-       ObjectLock olock(custom);
-
        String key;
        Value value;
-       BOOST_FOREACH(boost::tie(key, value), custom) {
-               if (key == "notes" ||
-                   key == "action_url" ||
-                   key == "notes_url" ||
-                   key == "icon_image" ||
-                   key == "icon_image_alt" ||
-                   key == "statusmap_image" ||
-                   key == "2d_coords")
-                       continue;
-
+       BOOST_FOREACH(boost::tie(key, value), customvars) {
                cv->Add(key);
        }
 
@@ -1620,31 +1632,25 @@ Value HostsTable::CustomVariableNamesAccessor(const Value& row)
 Value HostsTable::CustomVariableValuesAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
-       Dictionary::Ptr custom = host->GetCustom();
+       Dictionary::Ptr customvars;
 
-       if (!custom)
+       {
+               ObjectLock olock(host);
+               customvars = CompatUtility::GetCustomVariableConfig(host);
+       }
+
+       if (!customvars)
                return Empty;
 
        Array::Ptr cv = boost::make_shared<Array>();
 
-       ObjectLock olock(custom);
-
        String key;
        Value value;
-       BOOST_FOREACH(boost::tie(key, value), custom) {
-               if (key == "notes" ||
-                   key == "action_url" ||
-                   key == "notes_url" ||
-                   key == "icon_image" ||
-                   key == "icon_image_alt" ||
-                   key == "statusmap_image" ||
-                   key == "2d_coords")
-                       continue;
-
+       BOOST_FOREACH(boost::tie(key, value), customvars) {
                cv->Add(value);
        }
 
@@ -1654,31 +1660,25 @@ Value HostsTable::CustomVariableValuesAccessor(const Value& row)
 Value HostsTable::CustomVariablesAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
-       Dictionary::Ptr custom = host->GetCustom();
+       Dictionary::Ptr customvars;
 
-       if (!custom)
+       {
+               ObjectLock olock(host);
+               customvars = CompatUtility::GetCustomVariableConfig(host);
+       }
+
+       if (!customvars)
                return Empty;
 
        Array::Ptr cv = boost::make_shared<Array>();
 
-       ObjectLock olock(custom);
-
        String key;
        Value value;
-       BOOST_FOREACH(boost::tie(key, value), custom) {
-               if (key == "notes" ||
-                   key == "action_url" ||
-                   key == "notes_url" ||
-                   key == "icon_image" ||
-                   key == "icon_image_alt" ||
-                   key == "statusmap_image" ||
-                   key == "2d_coords")
-                       continue;
-
+       BOOST_FOREACH(boost::tie(key, value), customvars) {
                Array::Ptr key_val = boost::make_shared<Array>();
                key_val->Add(key);
                key_val->Add(value);
@@ -1691,7 +1691,7 @@ Value HostsTable::CustomVariablesAccessor(const Value& row)
 Value HostsTable::ParentsAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1707,7 +1707,7 @@ Value HostsTable::ParentsAccessor(const Value& row)
 Value HostsTable::ChildsAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1724,7 +1724,7 @@ Value HostsTable::NumServicesAccessor(const Value& row)
 {
        /* duplicate of TotalServices */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1734,7 +1734,7 @@ Value HostsTable::NumServicesAccessor(const Value& row)
 Value HostsTable::WorstServiceStateAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1751,7 +1751,7 @@ Value HostsTable::WorstServiceStateAccessor(const Value& row)
 Value HostsTable::NumServicesOkAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1768,7 +1768,7 @@ Value HostsTable::NumServicesOkAccessor(const Value& row)
 Value HostsTable::NumServicesWarnAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1785,7 +1785,7 @@ Value HostsTable::NumServicesWarnAccessor(const Value& row)
 Value HostsTable::NumServicesCritAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1802,7 +1802,7 @@ Value HostsTable::NumServicesCritAccessor(const Value& row)
 Value HostsTable::NumServicesUnknownAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1819,7 +1819,7 @@ Value HostsTable::NumServicesUnknownAccessor(const Value& row)
 Value HostsTable::NumServicesPendingAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1836,7 +1836,7 @@ Value HostsTable::NumServicesPendingAccessor(const Value& row)
 Value HostsTable::WorstServiceHardStateAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1855,7 +1855,7 @@ Value HostsTable::WorstServiceHardStateAccessor(const Value& row)
 Value HostsTable::NumServicesHardOkAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1872,7 +1872,7 @@ Value HostsTable::NumServicesHardOkAccessor(const Value& row)
 Value HostsTable::NumServicesHardWarnAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1889,7 +1889,7 @@ Value HostsTable::NumServicesHardWarnAccessor(const Value& row)
 Value HostsTable::NumServicesHardCritAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1906,7 +1906,7 @@ Value HostsTable::NumServicesHardCritAccessor(const Value& row)
 Value HostsTable::NumServicesHardUnknownAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1924,7 +1924,7 @@ Value HostsTable::HardStateAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1945,7 +1945,7 @@ Value HostsTable::StalenessAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1963,7 +1963,7 @@ Value HostsTable::StalenessAccessor(const Value& row)
 Value HostsTable::GroupsAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -1979,7 +1979,7 @@ Value HostsTable::ContactGroupsAccessor(const Value& row)
 {
        /* use hostcheck service */
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -2000,7 +2000,7 @@ Value HostsTable::ContactGroupsAccessor(const Value& row)
 Value HostsTable::ServicesAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -2016,7 +2016,7 @@ Value HostsTable::ServicesAccessor(const Value& row)
 Value HostsTable::ServicesWithStateAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -2037,7 +2037,7 @@ Value HostsTable::ServicesWithStateAccessor(const Value& row)
 Value HostsTable::ServicesWithInfoAccessor(const Value& row)
 {
        Host::Ptr host = static_cast<Host::Ptr>(row);
-       
+
        if (!host)
                return Empty;
 
@@ -2049,7 +2049,16 @@ Value HostsTable::ServicesWithInfoAccessor(const Value& row)
                svc_add->Add(service->GetShortName());
                svc_add->Add(service->GetState());
                svc_add->Add(service->HasBeenChecked() ? 1 : 0);
-               svc_add->Add(service->GetLastCheckOutput());
+
+               String output;
+               Dictionary::Ptr cr = service->GetLastCheckResult();
+
+               if (cr) {
+                       Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr);
+                       output = output_bag->Get("output");
+               }
+
+               svc_add->Add(output);
                services->Add(svc_add);
        }
 
index 48f4ed3219645d5a708f3c256a688c9891a47d22..92692460df77e1e579e818b18366292ad2d4b626 100644 (file)
@@ -150,9 +150,9 @@ Object::Ptr ServicesTable::HostAccessor(const Value& row, const Column::ObjectAc
                service = parentObjectAccessor(row);
        else
                service = row;
-       
+
        Service::Ptr svc = static_cast<Service::Ptr>(service);
-       
+
        if (!svc)
                return Object::Ptr();
 
@@ -197,7 +197,7 @@ Value ServicesTable::CheckCommandAccessor(const Value& row)
 Value ServicesTable::CheckCommandExpandedAccessor(const Value& row)
 {
        Service::Ptr service = static_cast<Service::Ptr>(row);
-       
+
        if (!service)
                return Empty;
 
@@ -242,7 +242,7 @@ Value ServicesTable::CheckCommandExpandedAccessor(const Value& row)
 Value ServicesTable::EventHandlerAccessor(const Value& row)
 {
        Service::Ptr service = static_cast<Service::Ptr>(row);
-       
+
        if (!service)
                return Empty;
 
@@ -261,7 +261,15 @@ Value ServicesTable::PluginOutputAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return service->GetLastCheckOutput();
+       String output;
+       Dictionary::Ptr cr = service->GetLastCheckResult();
+
+       if (cr) {
+               Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr);
+               output = output_bag->Get("output");
+       }
+
+       return output;
 }
 
 Value ServicesTable::LongPluginOutputAccessor(const Value& row)
@@ -271,7 +279,15 @@ Value ServicesTable::LongPluginOutputAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return service->GetLastCheckLongOutput();
+       String long_output;
+       Dictionary::Ptr cr = service->GetLastCheckResult();
+
+       if (cr) {
+               Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr);
+               long_output = output_bag->Get("long_output");
+       }
+
+       return long_output;
 }
 
 Value ServicesTable::PerfDataAccessor(const Value& row)
@@ -281,7 +297,13 @@ Value ServicesTable::PerfDataAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return service->GetLastCheckPerfData();
+       String perfdata;
+       Dictionary::Ptr cr = service->GetLastCheckResult();
+
+       if (cr)
+               perfdata = CompatUtility::GetCheckResultPerfdata(cr);
+
+       return perfdata;
 }
 
 Value ServicesTable::NotificationPeriodAccessor(const Value& row)
@@ -337,7 +359,7 @@ Value ServicesTable::NotesAccessor(const Value& row)
 Value ServicesTable::NotesExpandedAccessor(const Value& row)
 {
        Service::Ptr service = static_cast<Service::Ptr>(row);
-       
+
        if (!service)
                return Empty;
 
@@ -377,7 +399,7 @@ Value ServicesTable::NotesUrlAccessor(const Value& row)
 Value ServicesTable::NotesUrlExpandedAccessor(const Value& row)
 {
        Service::Ptr service = static_cast<Service::Ptr>(row);
-       
+
        if (!service)
                return Empty;
 
@@ -417,7 +439,7 @@ Value ServicesTable::ActionUrlAccessor(const Value& row)
 Value ServicesTable::ActionUrlExpandedAccessor(const Value& row)
 {
        Service::Ptr service = static_cast<Service::Ptr>(row);
-       
+
        if (!service)
                return Empty;
 
@@ -457,7 +479,7 @@ Value ServicesTable::IconImageAccessor(const Value& row)
 Value ServicesTable::IconImageExpandedAccessor(const Value& row)
 {
        Service::Ptr service = static_cast<Service::Ptr>(row);
-       
+
        if (!service)
                return Empty;
 
@@ -1186,26 +1208,21 @@ Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr custom = service->GetCustom();
+       Dictionary::Ptr customvars;
 
-       if (!custom)
+       {
+               ObjectLock olock(service);
+               customvars = CompatUtility::GetCustomVariableConfig(service);
+       }
+
+       if (!customvars)
                return Empty;
 
        Array::Ptr cv = boost::make_shared<Array>();
 
-       ObjectLock olock(custom);
        String key;
        Value value;
-       BOOST_FOREACH(boost::tie(key, value), custom) {
-               if (key == "notes" ||
-                   key == "action_url" ||
-                   key == "notes_url" ||
-                   key == "icon_image" ||
-                   key == "icon_image_alt" ||
-                   key == "statusmap_image" ||
-                   key == "2d_coords")
-                       continue;
-
+       BOOST_FOREACH(boost::tie(key, value), customvars) {
                cv->Add(key);
        }
 
@@ -1219,26 +1236,21 @@ Value ServicesTable::CustomVariableValuesAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr custom = service->GetCustom();
+       Dictionary::Ptr customvars;
 
-       if (!custom)
+       {
+               ObjectLock olock(service);
+               customvars = CompatUtility::GetCustomVariableConfig(service);
+       }
+
+       if (!customvars)
                return Empty;
 
        Array::Ptr cv = boost::make_shared<Array>();
 
-       ObjectLock olock(custom);
        String key;
        Value value;
-       BOOST_FOREACH(boost::tie(key, value), custom) {
-               if (key == "notes" ||
-                   key == "action_url" ||
-                   key == "notes_url" ||
-                   key == "icon_image" ||
-                   key == "icon_image_alt" ||
-                   key == "statusmap_image" ||
-                   key == "2d_coords")
-                       continue;
-
+       BOOST_FOREACH(boost::tie(key, value), customvars) {
                cv->Add(value);
        }
 
@@ -1252,26 +1264,21 @@ Value ServicesTable::CustomVariablesAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr custom = service->GetCustom();
+       Dictionary::Ptr customvars;
 
-       if (!custom)
+       {
+               ObjectLock olock(service);
+               customvars = CompatUtility::GetCustomVariableConfig(service);
+       }
+
+       if (!customvars)
                return Empty;
 
        Array::Ptr cv = boost::make_shared<Array>();
 
-       ObjectLock olock(custom);
        String key;
        Value value;
-       BOOST_FOREACH(boost::tie(key, value), custom) {
-               if (key == "notes" ||
-                   key == "action_url" ||
-                   key == "notes_url" ||
-                   key == "icon_image" ||
-                   key == "icon_image_alt" ||
-                   key == "statusmap_image" ||
-                   key == "2d_coords")
-                       continue;
-
+       BOOST_FOREACH(boost::tie(key, value), customvars) {
                Array::Ptr key_val = boost::make_shared<Array>();
                key_val->Add(key);
                key_val->Add(value);
index a74aa40ecccebf165460e4e244d773fffe7ff4f8..3b93c2ea4b7da50c74abdfcdcd84a4c5aa1f3c1e 100644 (file)
@@ -6,10 +6,15 @@ the `StatusDataWriter` object which dumps all configuration objects and
 status updates in a regular interval.
 
     # icinga2-enable-feature statusdata
-    
+
 Icinga 1.x Classic UI requires this data set as part of its backend.
-    
+
 > **Note**
 >
 > If you are not using any web interface or addon requiring this output
 > do not enable this feature.
+
+> **Note**
+>
+> Semi-colons in the check result output are replaced with colons because
+> they are used as attribute separators.
index cd160ebeba00db2776550e8224e1d29529ee2e9a..0b18ed31c6f95047c38a688b0e65f6486c13d3d7 100644 (file)
@@ -10,7 +10,7 @@ sla reports and trends in Icinga 1.x Classic UI.
 The `CompatLogger` object can be enabled with
 
     # icinga2-enable-feature compatlog
-    
+
 By default, the Icinga 1.x log file called `icinga.log` is located
 in `/var/log/icinga2/compat`. Rotated log files are moved into
 `var/log/icinga2/compat/archives`.
@@ -42,3 +42,7 @@ existing log parsers.
     [1382115731] EXTERNAL COMMAND: PROCESS_SERVICE_CHECK_RESULT;localhost;ping6;2;critical test|
     [1382115731] SERVICE ALERT: localhost;ping6;CRITICAL;SOFT;2;critical test
 
+> **Note**
+>
+> Semi-colons in the check result output are replaced with colons because
+> they are used as attribute separators.
index 78dfb88117fe975670cb59b1f11e076ed92b2b8e..13a7be4d13b8f8d5f1c8d676e1377b7777ec0fa1 100644 (file)
@@ -511,9 +511,9 @@ void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionar
 
        /* History - update deletion time for service (and host in case) */
        unsigned long entry_time = static_cast<long>(comment->Get("entry_time"));
+
        double now = Utility::GetTime();
-       unsigned long deletion_time = static_cast<long>(now);
-       unsigned long deletion_time_usec = (now - deletion_time) * 1000 * 1000;
+       Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now);
 
        DbQuery query2;
        query2.Table = "commenthistory";
@@ -521,8 +521,8 @@ void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionar
        query2.Category = DbCatComment;
 
        Dictionary::Ptr fields2 = boost::make_shared<Dictionary>();
-       fields2->Set("deletion_time", DbValue::FromTimestamp(deletion_time));
-       fields2->Set("deletion_time_usec", deletion_time_usec);
+       fields2->Set("deletion_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields2->Set("deletion_time_usec", time_bag->Get("time_usec"));
        query2.Fields = fields2;
 
        query2.WhereCriteria = boost::make_shared<Dictionary>();
@@ -681,8 +681,7 @@ void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Dictiona
 
        /* History - update actual_end_time, was_cancelled for service (and host in case) */
        double now = Utility::GetTime();
-       unsigned long actual_end_time = static_cast<long>(now);
-       unsigned long actual_end_time_usec = (now - actual_end_time) * 1000 * 1000;
+       Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now);
 
        DbQuery query3;
        query3.Table = "downtimehistory";
@@ -691,8 +690,8 @@ void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Dictiona
 
        Dictionary::Ptr fields3 = boost::make_shared<Dictionary>();
        fields3->Set("was_cancelled", downtime->Get("was_cancelled") ? 1 : 0);
-       fields3->Set("actual_end_time", DbValue::FromTimestamp(actual_end_time));
-       fields3->Set("actual_end_time_usec", actual_end_time_usec);
+       fields3->Set("actual_end_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields3->Set("actual_end_time_usec", time_bag->Get("time_usec"));
        query3.Fields = fields3;
 
        query3.WhereCriteria = boost::make_shared<Dictionary>();
@@ -720,8 +719,7 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction
        Log(LogDebug, "db_ido", "updating triggered service downtime (id = " + downtime->Get("legacy_id") + ") for '" + service->GetName() + "'");
 
        double now = Utility::GetTime();
-       unsigned long actual_start_time = static_cast<long>(now);
-       unsigned long actual_start_time_usec = static_cast<long>((now - actual_start_time) * 1000 * 1000);
+       Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now);
 
        /* Status */
        DbQuery query1;
@@ -731,8 +729,8 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
        fields1->Set("was_started", 1);
-       fields1->Set("actual_start_time", DbValue::FromTimestamp(actual_start_time));
-       fields1->Set("actual_start_time_usec", actual_start_time_usec);
+       fields1->Set("actual_start_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields1->Set("actual_start_time_usec", time_bag->Get("time_usec"));
        fields1->Set("is_in_effect", 1);
        fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->Get("trigger_time")));
        fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
@@ -759,8 +757,8 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction
        Dictionary::Ptr fields3 = boost::make_shared<Dictionary>();
        fields3->Set("was_started", 1);
        fields3->Set("is_in_effect", 1);
-       fields3->Set("actual_start_time", DbValue::FromTimestamp(actual_start_time));
-       fields3->Set("actual_start_time_usec", actual_start_time_usec);
+       fields3->Set("actual_start_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields3->Set("actual_start_time_usec", time_bag->Get("time_usec"));
        fields3->Set("trigger_time", DbValue::FromTimestamp(downtime->Get("trigger_time")));
        query3.Fields = fields3;
 
@@ -786,8 +784,8 @@ void ServiceDbObject::AddAcknowledgementHistory(const Service::Ptr& service, con
        Log(LogDebug, "db_ido", "add acknowledgement history for '" + service->GetName() + "'");
 
        double now = Utility::GetTime();
-       unsigned long entry_time = static_cast<long>(now);
-       unsigned long entry_time_usec = (now - entry_time) * 1000 * 1000;
+       Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now);
+
        unsigned long end_time = static_cast<long>(expiry);
 
        DbQuery query1;
@@ -796,8 +794,8 @@ void ServiceDbObject::AddAcknowledgementHistory(const Service::Ptr& service, con
        query1.Category = DbCatAcknowledgement;
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
-       fields1->Set("entry_time", DbValue::FromTimestamp(entry_time));
-       fields1->Set("entry_time_usec", entry_time_usec);
+       fields1->Set("entry_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields1->Set("entry_time_usec", time_bag->Get("time_usec"));
        fields1->Set("acknowledgement_type", type);
        fields1->Set("object_id", service);
        fields1->Set("state", service->GetState());
@@ -831,10 +829,7 @@ void ServiceDbObject::AddContactNotificationHistory(const Service::Ptr& service,
 
        /* start and end happen at the same time */
        double now = Utility::GetTime();
-       unsigned long start_time = static_cast<long>(now);
-       unsigned long end_time = start_time;
-       unsigned long start_time_usec = (now - start_time) * 1000 * 1000;
-       unsigned long end_time_usec = start_time_usec;
+       Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now);
 
        DbQuery query1;
        query1.Table = "contactnotifications";
@@ -843,10 +838,10 @@ void ServiceDbObject::AddContactNotificationHistory(const Service::Ptr& service,
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
        fields1->Set("contact_object_id", user);
-       fields1->Set("start_time", DbValue::FromTimestamp(start_time));
-       fields1->Set("start_time_usec", start_time_usec);
-       fields1->Set("end_time", DbValue::FromTimestamp(end_time));
-       fields1->Set("end_time_usec", end_time_usec);
+       fields1->Set("start_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields1->Set("start_time_usec", time_bag->Get("time_usec"));
+       fields1->Set("end_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields1->Set("end_time_usec", time_bag->Get("time_usec"));
 
        fields1->Set("notification_id", 0); /* DbConnection class fills in real ID */
        fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
@@ -872,10 +867,7 @@ void ServiceDbObject::AddNotificationHistory(const Service::Ptr& service, const
 
        /* start and end happen at the same time */
        double now = Utility::GetTime();
-       unsigned long start_time = static_cast<long>(now);
-       unsigned long end_time = start_time;
-       unsigned long start_time_usec = (now - start_time) * 1000 * 1000;
-       unsigned long end_time_usec = start_time_usec;
+       Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now);
 
        DbQuery query1;
        query1.Table = "notifications";
@@ -886,10 +878,10 @@ void ServiceDbObject::AddNotificationHistory(const Service::Ptr& service, const
        fields1->Set("notification_type", 1); /* service */
        fields1->Set("notification_reason", CompatUtility::MapNotificationReasonType(type));
        fields1->Set("object_id", service);
-       fields1->Set("start_time", DbValue::FromTimestamp(start_time));
-       fields1->Set("start_time_usec", start_time_usec);
-       fields1->Set("end_time", DbValue::FromTimestamp(end_time));
-       fields1->Set("end_time_usec", end_time_usec);
+       fields1->Set("start_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields1->Set("start_time_usec", time_bag->Get("time_usec"));
+       fields1->Set("end_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields1->Set("end_time_usec", time_bag->Get("time_usec"));
        fields1->Set("state", service->GetState());
 
        if (cr) {
@@ -925,8 +917,7 @@ void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const D
        Log(LogDebug, "db_ido", "add state change history for '" + service->GetName() + "'");
 
        double now = Utility::GetTime();
-       unsigned long state_time = static_cast<long>(now);
-       unsigned long state_time_usec = (now - state_time) * 1000 * 1000;
+       Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now);
 
        DbQuery query1;
        query1.Table = "statehistory";
@@ -934,8 +925,8 @@ void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const D
        query1.Category = DbCatStateHistory;
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
-       fields1->Set("state_time", DbValue::FromTimestamp(state_time));
-       fields1->Set("state_time_usec", state_time_usec);
+       fields1->Set("state_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields1->Set("state_time_usec", time_bag->Get("time_usec"));
        fields1->Set("object_id", service);
        fields1->Set("state_change", 1); /* service */
        fields1->Set("state", service->GetState());
@@ -1260,8 +1251,7 @@ void ServiceDbObject::AddLogHistory(const Service::Ptr& service, String buffer,
        Log(LogDebug, "db_ido", "add log entry history for '" + service->GetName() + "'");
 
        double now = Utility::GetTime();
-       unsigned long entry_time = static_cast<long>(now);
-       unsigned long entry_time_usec = (now - entry_time) * 1000 * 1000;
+       Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now);
 
        DbQuery query1;
        query1.Table = "logentries";
@@ -1269,9 +1259,9 @@ void ServiceDbObject::AddLogHistory(const Service::Ptr& service, String buffer,
        query1.Category = DbCatLog;
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
-       fields1->Set("logentry_time", DbValue::FromTimestamp(entry_time));
-       fields1->Set("entry_time", DbValue::FromTimestamp(entry_time));
-       fields1->Set("entry_time_usec", entry_time_usec);
+       fields1->Set("logentry_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields1->Set("entry_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields1->Set("entry_time_usec", time_bag->Get("time_usec"));
        fields1->Set("object_id", service); // added in 1.10 see #4754
        fields1->Set("logentry_type", type);
        fields1->Set("logentry_data", buffer);
@@ -1299,8 +1289,7 @@ void ServiceDbObject::AddFlappingHistory(const Service::Ptr& service, FlappingSt
        Log(LogDebug, "db_ido", "add flapping history for '" + service->GetName() + "'");
 
        double now = Utility::GetTime();
-       unsigned long event_time = static_cast<long>(now);
-       unsigned long event_time_usec = (now - event_time) * 1000 * 1000;
+       Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now);
 
        DbQuery query1;
        query1.Table = "flappinghistory";
@@ -1309,8 +1298,8 @@ void ServiceDbObject::AddFlappingHistory(const Service::Ptr& service, FlappingSt
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
 
-       fields1->Set("event_time", DbValue::FromTimestamp(event_time));
-       fields1->Set("event_time_usec", event_time_usec);
+       fields1->Set("event_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields1->Set("event_time_usec", time_bag->Get("time_usec"));
 
        switch (flapping_state) {
                case FlappingStarted:
@@ -1378,17 +1367,15 @@ void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const
        fields1->Set("state_type", attrs->Get("state_type"));
 
        double now = Utility::GetTime();
-       unsigned long start_time = static_cast<long>(now);
-       unsigned long start_time_usec = (now - start_time) * 1000 * 1000;
+       Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now);
 
        double end = now + attrs->Get("check_execution_time");
-       unsigned long end_time = static_cast<long>(end);
-       unsigned long end_time_usec = (end - end_time) * 1000 * 1000;
+       Dictionary::Ptr time_bag_end = CompatUtility::ConvertTimestamp(end);
 
-       fields1->Set("start_time", DbValue::FromTimestamp(start_time));
-       fields1->Set("start_time_usec", start_time_usec);
-       fields1->Set("end_time", DbValue::FromTimestamp(end_time));
-       fields1->Set("end_time_usec", end_time_usec);
+       fields1->Set("start_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields1->Set("start_time_usec", time_bag->Get("time_usec"));
+       fields1->Set("end_time", DbValue::FromTimestamp(time_bag_end->Get("time_sec")));
+       fields1->Set("end_time_usec", time_bag_end->Get("time_usec"));
        fields1->Set("command_object_id", service->GetCheckCommand());
        fields1->Set("command_args", Empty);
        fields1->Set("command_line", cr->Get("command"));
@@ -1427,8 +1414,7 @@ void ServiceDbObject::AddEventHandlerHistory(const Service::Ptr& service)
        Log(LogDebug, "db_ido", "add eventhandler history for '" + service->GetName() + "'");
 
        double now = Utility::GetTime();
-       unsigned long event_time = static_cast<long>(now);
-       unsigned long event_time_usec = (now - event_time) * 1000 * 1000;
+       Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now);
 
        DbQuery query1;
        query1.Table = "eventhandlers";
@@ -1442,10 +1428,10 @@ void ServiceDbObject::AddEventHandlerHistory(const Service::Ptr& service)
        fields1->Set("state", service->GetState());
        fields1->Set("state_type", service->GetStateType());
 
-       fields1->Set("start_time", DbValue::FromTimestamp(event_time));
-       fields1->Set("start_time_usec", event_time_usec);
-       fields1->Set("end_time", DbValue::FromTimestamp(event_time));
-       fields1->Set("end_time_usec", event_time_usec);
+       fields1->Set("start_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields1->Set("start_time_usec", time_bag->Get("time_usec"));
+       fields1->Set("end_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
+       fields1->Set("end_time_usec", time_bag->Get("time_usec"));
        fields1->Set("command_object_id", service->GetEventCommand());
 
        fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
index 04b33791e62ebad87f01143d107c6d7a32ebe4ac..b2360fcf481d0c186d8d693e6f5e31f0e8483189 100644 (file)
@@ -531,6 +531,13 @@ Dictionary::Ptr CompatUtility::GetCheckResultOutput(const Dictionary::Ptr& cr)
        Dictionary::Ptr bag = boost::make_shared<Dictionary>();
 
        String raw_output = cr->Get("output");
+
+       /*
+        * replace semi-colons with colons in output
+        * semi-colon is used as delimiter in various interfaces
+        */
+       boost::algorithm::replace_all(raw_output, ";", ":");
+
        size_t line_end = raw_output.Find("\n");
 
        output = raw_output.SubStr(0, line_end);
@@ -565,6 +572,19 @@ String CompatUtility::EscapeString(const String& str)
        return result;
 }
 
+Dictionary::Ptr CompatUtility::ConvertTimestamp(double time)
+{
+       Dictionary::Ptr time_bag = boost::make_shared<Dictionary>();
+
+       unsigned long time_sec = static_cast<long>(time);
+       unsigned long time_usec = (time - time_sec) * 1000 * 1000;
+
+       time_bag->Set("time_sec", time_sec);
+       time_bag->Set("time_usec", time_usec);
+
+       return time_bag;
+}
+
 int CompatUtility::MapNotificationReasonType(NotificationType type)
 {
        switch (type) {
index 1875dfcc504843a938823e1c2a6fa00e469b53e9..533f177da708cadc1b1bad6ce6980fc13bbf8b3c 100644 (file)
@@ -62,6 +62,8 @@ public:
        static Dictionary::Ptr GetCheckResultOutput(const Dictionary::Ptr& cr);
        static String GetCheckResultPerfdata(const Dictionary::Ptr& cr);
 
+       static Dictionary::Ptr ConvertTimestamp(double time);
+
        static int MapNotificationReasonType(NotificationType type);
        static int MapExternalCommandType(const String& name);
 
index 6fd8dc0e8eeabf1bf392338080a7296ff4b0c318..9a7b95b7e8535e4064f22635489a05ceb7704260 100644 (file)
@@ -139,52 +139,6 @@ double Service::GetLastCheck(void) const
        return schedule_end;
 }
 
-String Service::GetLastCheckOutput(void) const
-{
-       Dictionary::Ptr cr = GetLastCheckResult();
-       String output;
-
-       if (cr) {
-               String raw_output = cr->Get("output");
-               size_t line_end = raw_output.Find("\n");
-               output = raw_output.SubStr(0, line_end);
-       }
-
-       return output;
-}
-
-String Service::GetLastCheckLongOutput(void) const
-{
-       Dictionary::Ptr cr = GetLastCheckResult();
-       String long_output;
-
-       if (cr) {
-               String raw_output = cr->Get("output");
-               size_t line_end = raw_output.Find("\n");
-
-               if (line_end > 0 && line_end != String::NPos) {
-                       long_output = raw_output.SubStr(line_end + 1, raw_output.GetLength());
-                       boost::algorithm::replace_all(long_output, "\n", "\\n");
-               }
-       }
-
-       return long_output;
-}
-
-String Service::GetLastCheckPerfData(void) const
-{
-       Dictionary::Ptr cr = GetLastCheckResult();
-       String perfdata;
-
-       if (cr) {
-               perfdata = cr->Get("performance_data_raw");
-
-               boost::algorithm::replace_all(perfdata, "\n", "\\n");
-       }
-
-       return perfdata;
-}
-
 bool Service::GetEnableActiveChecks(void) const
 {
        if (!GetOverrideEnableActiveChecks().IsEmpty())
index 99c617b74300bffdee2d08715d9f2a8e4609d89c..b2eb4541f53b1748e2e1c8bb5216136645a51496 100644 (file)
@@ -163,10 +163,6 @@ public:
 
        double GetLastCheck(void) const;
 
-       String GetLastCheckOutput(void) const;
-       String GetLastCheckLongOutput(void) const;
-       String GetLastCheckPerfData(void) const;
-
        bool GetEnableActiveChecks(void) const;
        void SetEnableActiveChecks(bool enabled, const String& authority = String());