mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 21:55:03 +02:00
commit
1f0bf17c0f
@ -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,16 +99,10 @@ 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");
|
||||
Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr);
|
||||
output = output_bag->Get("output");
|
||||
}
|
||||
|
||||
std::ostringstream msgbuf;
|
||||
@ -274,13 +269,9 @@ 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);
|
||||
Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr);
|
||||
output = output_bag->Get("output");
|
||||
}
|
||||
|
||||
std::ostringstream msgbuf;
|
||||
@ -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());
|
||||
}
|
||||
|
@ -517,8 +517,15 @@ Value HostsTable::PluginOutputAccessor(const Value& row)
|
||||
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;
|
||||
}
|
||||
@ -534,8 +541,12 @@ Value HostsTable::PerfDataAccessor(const Value& row)
|
||||
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;
|
||||
}
|
||||
@ -630,8 +641,15 @@ Value HostsTable::LongPluginOutputAccessor(const Value& row)
|
||||
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;
|
||||
}
|
||||
@ -1590,27 +1608,21 @@ Value HostsTable::CustomVariableNamesAccessor(const Value& 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);
|
||||
}
|
||||
|
||||
@ -1624,27 +1636,21 @@ Value HostsTable::CustomVariableValuesAccessor(const Value& 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);
|
||||
}
|
||||
|
||||
@ -1658,27 +1664,21 @@ Value HostsTable::CustomVariablesAccessor(const Value& 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);
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
@ -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);
|
||||
|
@ -13,3 +13,8 @@ Icinga 1.x Classic UI requires this data set as part of its backend.
|
||||
>
|
||||
> 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.
|
||||
|
@ -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.
|
||||
|
@ -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 */
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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())
|
||||
|
@ -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());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user