]> granicus.if.org Git - icinga2/commitdiff
Add check source to external commands / check result reader.
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 7 Feb 2014 08:48:15 +0000 (09:48 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 7 Feb 2014 08:48:15 +0000 (09:48 +0100)
Fixes #5615

components/compat/checkresultreader.cpp
lib/db_ido/servicedbobject.cpp
lib/icinga/externalcommandprocessor.cpp
lib/icinga/icingaapplication.cpp
lib/icinga/icingaapplication.h
lib/methods/icingachecktask.cpp
lib/methods/nullchecktask.cpp
lib/methods/pluginchecktask.cpp
lib/methods/randomchecktask.cpp

index 1274617b4e18179486508701c3bf7af5563546db..f86d58e91142f5bea7cc5ece47a9fa67b288cb9f 100644 (file)
@@ -20,6 +20,7 @@
 #include "compat/checkresultreader.h"
 #include "icinga/service.h"
 #include "icinga/pluginutility.h"
+#include "icinga/icingaapplication.h"
 #include "base/dynamictype.h"
 #include "base/objectlock.h"
 #include "base/logger_fwd.h"
@@ -120,6 +121,7 @@ void CheckResultReader::ProcessCheckResultFile(const String& path) const
        result->SetState(PluginUtility::ExitStatusToState(Convert::ToLong(attrs["return_code"])));
        result->SetExecutionStart(Convert::ToDouble(attrs["start_time"]));
        result->SetExecutionEnd(Convert::ToDouble(attrs["finish_time"]));
+       result->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
 
        service->ProcessCheckResult(result);
 
index d1eb226879b0be04a7730432a19cc28fb52be7e5..e376b25301eb008906c18785d6ec5ef53bdd0998 100644 (file)
@@ -403,7 +403,7 @@ void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const C
                query1.Table = "comments";
        } else {
                query1.Table = "commenthistory";
-               fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName());
+               fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetNodeName());
        }
        query1.Type = DbQueryInsert;
        query1.Category = DbCatComment;
@@ -569,7 +569,7 @@ void ServiceDbObject::AddDowntimeByType(const DynamicObject::Ptr& object, const
                query1.Table = "scheduleddowntime";
        } else {
                query1.Table = "downtimehistory";
-               fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName());
+               fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetNodeName());
        }
        query1.Type = DbQueryInsert;
        query1.Category = DbCatDowntime;
@@ -746,7 +746,7 @@ void ServiceDbObject::AddAcknowledgementHistory(const Service::Ptr& service, con
        fields1->Set("comment_data", comment);
        fields1->Set("is_sticky", type == AcknowledgementSticky ? 1 : 0);
        fields1->Set("end_time", DbValue::FromTimestamp(end_time));
-       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName());
+       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetNodeName());
        fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
        query1.Fields = fields1;
@@ -797,7 +797,7 @@ void ServiceDbObject::AddNotificationHistory(const Notification::Ptr& notificati
 
        fields1->Set("escalated", 0);
        fields1->Set("contacts_notified", static_cast<long>(users.size()));
-       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName());
+       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetNodeName());
        fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
        query1.Fields = fields1;
@@ -869,7 +869,7 @@ void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const C
                fields1->Set("check_source", cr->GetCheckSource());
        }
 
-       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName());
+       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetNodeName());
        fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
        query1.Fields = fields1;
@@ -1172,7 +1172,7 @@ void ServiceDbObject::AddLogHistory(const Service::Ptr& service, String buffer,
        fields1->Set("object_id", service); // added in 1.10 see #4754
        fields1->Set("logentry_type", type);
        fields1->Set("logentry_data", buffer);
-       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName());
+       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetNodeName());
 
        fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
@@ -1229,7 +1229,7 @@ void ServiceDbObject::AddFlappingHistory(const Service::Ptr& service, FlappingSt
        fields1->Set("percent_state_change", service->GetFlappingCurrent());
        fields1->Set("low_threshold", service->GetFlappingThreshold());
        fields1->Set("high_threshold", service->GetFlappingThreshold());
-       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName());
+       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetNodeName());
 
        fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
@@ -1288,7 +1288,7 @@ void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const
        fields1->Set("output", CompatUtility::GetCheckResultOutput(cr));
        fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
        fields1->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr));
-       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName());
+       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetNodeName());
 
        fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
        fields1->Set("service_object_id", service);
@@ -1336,7 +1336,7 @@ void ServiceDbObject::AddEventHandlerHistory(const Service::Ptr& service)
        fields1->Set("end_time", DbValue::FromTimestamp(time_bag.first));
        fields1->Set("end_time_usec", time_bag.second);
        fields1->Set("command_object_id", service->GetEventCommand());
-       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName());
+       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetNodeName());
 
        fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
@@ -1370,7 +1370,7 @@ void ServiceDbObject::AddExternalCommandHistory(double time, const String& comma
        fields1->Set("command_type", CompatUtility::MapExternalCommandType(command));
        fields1->Set("command_name", command);
        fields1->Set("command_args", boost::algorithm::join(arguments, ";"));
-       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName());
+       fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetNodeName());
 
        fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
index b93ef0fd1f3828c6ab4677986a49d84a301c3e5f..00a43cfae3762811c43e1313ddff811a3a0fa398 100644 (file)
@@ -252,6 +252,7 @@ void ExternalCommandProcessor::ProcessHostCheckResult(double time, const std::ve
        result->SetExecutionStart(time);
        result->SetExecutionEnd(time);
        result->SetActive(false);
+       result->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
 
        Log(LogInformation, "icinga", "Processing passive check result for host '" + arguments[0] + "'");
        hc->ProcessCheckResult(result);
@@ -288,6 +289,7 @@ void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const std:
        result->SetExecutionStart(time);
        result->SetExecutionEnd(time);
        result->SetActive(false);
+       result->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
 
        Log(LogInformation, "icinga", "Processing passive check result for service '" + arguments[1] + "'");
        service->ProcessCheckResult(result);
index cef46b7266267458fe51030c8bab630a020deb39..5d705318215a419c5d550b071b510bb4692529c1 100644 (file)
@@ -94,7 +94,7 @@ Dictionary::Ptr IcingaApplication::GetMacros(void) const
        return ScriptVariable::Get("IcingaMacros");
 }
 
-String IcingaApplication::GetIcingaNodeName(void) const
+String IcingaApplication::GetNodeName(void) const
 {
        return  ScriptVariable::Get("IcingaNodeName");
 }
index c8b6be81c11d1e131b82c80b076b4f9895d8687b..cc8b1369d5ac10f602ce0a53f5d0feb3702c82bb 100644 (file)
@@ -46,7 +46,7 @@ public:
 
        String GetPidPath(void) const;
        Dictionary::Ptr GetMacros(void) const;
-        String GetIcingaNodeName(void) const;
+        String GetNodeName(void) const;
 
        virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const;
 
index a165d2133161fbc3a4e93fe5e08e6f83241a5402..e4e29c74177398c7082b4a419b6789c1db79bce8 100644 (file)
@@ -65,7 +65,7 @@ CheckResult::Ptr IcingaCheckTask::ScriptFunc(const Service::Ptr&)
        cr->SetOutput("Icinga 2 is running.");
        cr->SetPerformanceData(perfdata);
        cr->SetState(StateOK);
-       cr->SetCheckSource(IcingaApplication::GetInstance()->GetIcingaNodeName());
+       cr->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
 
        return cr;
 }
index 0ace1cdd0177c91336627163c49ef7502aaaf6d2..cf17dd940340225b7ad51b930331058ab13e7d9b 100644 (file)
@@ -32,13 +32,8 @@ REGISTER_SCRIPTFUNCTION(NullCheck, &NullCheckTask::ScriptFunc);
 
 CheckResult::Ptr NullCheckTask::ScriptFunc(const Service::Ptr&)
 {
-       char name[255];
-
-       if (gethostname(name, sizeof(name)) < 0)
-               strcpy(name, "<unknown host>");
-
        String output = "Hello from ";
-       output += name;
+       output += Utility::GetHostName();
 
        Dictionary::Ptr perfdata = make_shared<Dictionary>();
        perfdata->Set("time", Utility::GetTime());
index 0456cc31c6945ce705398800a8cd4a8e67fe3ac3..3cd2077bdf379487b4bf31053e35bf9368d0d2bc 100644 (file)
@@ -79,7 +79,7 @@ CheckResult::Ptr PluginCheckTask::ScriptFunc(const Service::Ptr& service)
        result->SetExitStatus(pr.ExitStatus);
        result->SetExecutionStart(pr.ExecutionStart);
        result->SetExecutionEnd(pr.ExecutionEnd);
-       result->SetCheckSource(IcingaApplication::GetInstance()->GetIcingaNodeName());
+       result->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
 
        return result;
 }
index 16e4f9eeef37a04139ba5d67c25efee51ee79aee..555139f19a84c2fb9f3131e99790b5ab4e31e35e 100644 (file)
@@ -33,13 +33,8 @@ REGISTER_SCRIPTFUNCTION(RandomCheck, &RandomCheckTask::ScriptFunc);
 
 CheckResult::Ptr RandomCheckTask::ScriptFunc(const Service::Ptr&)
 {
-       char name[255];
-
-       if (gethostname(name, sizeof(name)) < 0)
-               strcpy(name, "<unknown host>");
-
        String output = "Hello from ";
-       output += name;
+       output += Utility::GetHostName();
 
        Dictionary::Ptr perfdata = make_shared<Dictionary>();
        perfdata->Set("time", Utility::GetTime());
@@ -48,7 +43,7 @@ CheckResult::Ptr RandomCheckTask::ScriptFunc(const Service::Ptr&)
        cr->SetOutput(output);
        cr->SetPerformanceData(perfdata);
        cr->SetState(static_cast<ServiceState>(Utility::Random() % 4));
-       cr->SetCheckSource(IcingaApplication::GetInstance()->GetIcingaNodeName());
+       cr->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
 
        return cr;
 }