mirror of
				https://github.com/Icinga/icinga2.git
				synced 2025-11-03 21:25:56 +01:00 
			
		
		
		
	Add check source to external commands / check result reader.
Fixes #5615
This commit is contained in:
		
							parent
							
								
									3f989e24dc
								
							
						
					
					
						commit
						5f26bb9147
					
				@ -20,6 +20,7 @@
 | 
				
			|||||||
#include "compat/checkresultreader.h"
 | 
					#include "compat/checkresultreader.h"
 | 
				
			||||||
#include "icinga/service.h"
 | 
					#include "icinga/service.h"
 | 
				
			||||||
#include "icinga/pluginutility.h"
 | 
					#include "icinga/pluginutility.h"
 | 
				
			||||||
 | 
					#include "icinga/icingaapplication.h"
 | 
				
			||||||
#include "base/dynamictype.h"
 | 
					#include "base/dynamictype.h"
 | 
				
			||||||
#include "base/objectlock.h"
 | 
					#include "base/objectlock.h"
 | 
				
			||||||
#include "base/logger_fwd.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->SetState(PluginUtility::ExitStatusToState(Convert::ToLong(attrs["return_code"])));
 | 
				
			||||||
	result->SetExecutionStart(Convert::ToDouble(attrs["start_time"]));
 | 
						result->SetExecutionStart(Convert::ToDouble(attrs["start_time"]));
 | 
				
			||||||
	result->SetExecutionEnd(Convert::ToDouble(attrs["finish_time"]));
 | 
						result->SetExecutionEnd(Convert::ToDouble(attrs["finish_time"]));
 | 
				
			||||||
 | 
						result->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	service->ProcessCheckResult(result);
 | 
						service->ProcessCheckResult(result);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -403,7 +403,7 @@ void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const C
 | 
				
			|||||||
		query1.Table = "comments";
 | 
							query1.Table = "comments";
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		query1.Table = "commenthistory";
 | 
							query1.Table = "commenthistory";
 | 
				
			||||||
		fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName());
 | 
							fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetNodeName());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	query1.Type = DbQueryInsert;
 | 
						query1.Type = DbQueryInsert;
 | 
				
			||||||
	query1.Category = DbCatComment;
 | 
						query1.Category = DbCatComment;
 | 
				
			||||||
@ -569,7 +569,7 @@ void ServiceDbObject::AddDowntimeByType(const DynamicObject::Ptr& object, const
 | 
				
			|||||||
		query1.Table = "scheduleddowntime";
 | 
							query1.Table = "scheduleddowntime";
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		query1.Table = "downtimehistory";
 | 
							query1.Table = "downtimehistory";
 | 
				
			||||||
		fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName());
 | 
							fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetNodeName());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	query1.Type = DbQueryInsert;
 | 
						query1.Type = DbQueryInsert;
 | 
				
			||||||
	query1.Category = DbCatDowntime;
 | 
						query1.Category = DbCatDowntime;
 | 
				
			||||||
@ -746,7 +746,7 @@ void ServiceDbObject::AddAcknowledgementHistory(const Service::Ptr& service, con
 | 
				
			|||||||
	fields1->Set("comment_data", comment);
 | 
						fields1->Set("comment_data", comment);
 | 
				
			||||||
	fields1->Set("is_sticky", type == AcknowledgementSticky ? 1 : 0);
 | 
						fields1->Set("is_sticky", type == AcknowledgementSticky ? 1 : 0);
 | 
				
			||||||
	fields1->Set("end_time", DbValue::FromTimestamp(end_time));
 | 
						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 */
 | 
						fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	query1.Fields = fields1;
 | 
						query1.Fields = fields1;
 | 
				
			||||||
@ -797,7 +797,7 @@ void ServiceDbObject::AddNotificationHistory(const Notification::Ptr& notificati
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	fields1->Set("escalated", 0);
 | 
						fields1->Set("escalated", 0);
 | 
				
			||||||
	fields1->Set("contacts_notified", static_cast<long>(users.size()));
 | 
						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 */
 | 
						fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	query1.Fields = fields1;
 | 
						query1.Fields = fields1;
 | 
				
			||||||
@ -869,7 +869,7 @@ void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const C
 | 
				
			|||||||
		fields1->Set("check_source", cr->GetCheckSource());
 | 
							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 */
 | 
						fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	query1.Fields = fields1;
 | 
						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("object_id", service); // added in 1.10 see #4754
 | 
				
			||||||
	fields1->Set("logentry_type", type);
 | 
						fields1->Set("logentry_type", type);
 | 
				
			||||||
	fields1->Set("logentry_data", buffer);
 | 
						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 */
 | 
						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("percent_state_change", service->GetFlappingCurrent());
 | 
				
			||||||
	fields1->Set("low_threshold", service->GetFlappingThreshold());
 | 
						fields1->Set("low_threshold", service->GetFlappingThreshold());
 | 
				
			||||||
	fields1->Set("high_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 */
 | 
						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("output", CompatUtility::GetCheckResultOutput(cr));
 | 
				
			||||||
	fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
 | 
						fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
 | 
				
			||||||
	fields1->Set("perfdata", CompatUtility::GetCheckResultPerfdata(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("instance_id", 0); /* DbConnection class fills in real ID */
 | 
				
			||||||
	fields1->Set("service_object_id", service);
 | 
						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", DbValue::FromTimestamp(time_bag.first));
 | 
				
			||||||
	fields1->Set("end_time_usec", time_bag.second);
 | 
						fields1->Set("end_time_usec", time_bag.second);
 | 
				
			||||||
	fields1->Set("command_object_id", service->GetEventCommand());
 | 
						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 */
 | 
						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_type", CompatUtility::MapExternalCommandType(command));
 | 
				
			||||||
	fields1->Set("command_name", command);
 | 
						fields1->Set("command_name", command);
 | 
				
			||||||
	fields1->Set("command_args", boost::algorithm::join(arguments, ";"));
 | 
						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 */
 | 
						fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -252,6 +252,7 @@ void ExternalCommandProcessor::ProcessHostCheckResult(double time, const std::ve
 | 
				
			|||||||
	result->SetExecutionStart(time);
 | 
						result->SetExecutionStart(time);
 | 
				
			||||||
	result->SetExecutionEnd(time);
 | 
						result->SetExecutionEnd(time);
 | 
				
			||||||
	result->SetActive(false);
 | 
						result->SetActive(false);
 | 
				
			||||||
 | 
						result->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Log(LogInformation, "icinga", "Processing passive check result for host '" + arguments[0] + "'");
 | 
						Log(LogInformation, "icinga", "Processing passive check result for host '" + arguments[0] + "'");
 | 
				
			||||||
	hc->ProcessCheckResult(result);
 | 
						hc->ProcessCheckResult(result);
 | 
				
			||||||
@ -288,6 +289,7 @@ void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const std:
 | 
				
			|||||||
	result->SetExecutionStart(time);
 | 
						result->SetExecutionStart(time);
 | 
				
			||||||
	result->SetExecutionEnd(time);
 | 
						result->SetExecutionEnd(time);
 | 
				
			||||||
	result->SetActive(false);
 | 
						result->SetActive(false);
 | 
				
			||||||
 | 
						result->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Log(LogInformation, "icinga", "Processing passive check result for service '" + arguments[1] + "'");
 | 
						Log(LogInformation, "icinga", "Processing passive check result for service '" + arguments[1] + "'");
 | 
				
			||||||
	service->ProcessCheckResult(result);
 | 
						service->ProcessCheckResult(result);
 | 
				
			||||||
 | 
				
			|||||||
@ -94,7 +94,7 @@ Dictionary::Ptr IcingaApplication::GetMacros(void) const
 | 
				
			|||||||
	return ScriptVariable::Get("IcingaMacros");
 | 
						return ScriptVariable::Get("IcingaMacros");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
String IcingaApplication::GetIcingaNodeName(void) const
 | 
					String IcingaApplication::GetNodeName(void) const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return 	ScriptVariable::Get("IcingaNodeName");
 | 
						return 	ScriptVariable::Get("IcingaNodeName");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -46,7 +46,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	String GetPidPath(void) const;
 | 
						String GetPidPath(void) const;
 | 
				
			||||||
	Dictionary::Ptr GetMacros(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;
 | 
						virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -65,7 +65,7 @@ CheckResult::Ptr IcingaCheckTask::ScriptFunc(const Service::Ptr&)
 | 
				
			|||||||
	cr->SetOutput("Icinga 2 is running.");
 | 
						cr->SetOutput("Icinga 2 is running.");
 | 
				
			||||||
	cr->SetPerformanceData(perfdata);
 | 
						cr->SetPerformanceData(perfdata);
 | 
				
			||||||
	cr->SetState(StateOK);
 | 
						cr->SetState(StateOK);
 | 
				
			||||||
	cr->SetCheckSource(IcingaApplication::GetInstance()->GetIcingaNodeName());
 | 
						cr->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return cr;
 | 
						return cr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -32,13 +32,8 @@ REGISTER_SCRIPTFUNCTION(NullCheck, &NullCheckTask::ScriptFunc);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
CheckResult::Ptr NullCheckTask::ScriptFunc(const Service::Ptr&)
 | 
					CheckResult::Ptr NullCheckTask::ScriptFunc(const Service::Ptr&)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char name[255];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (gethostname(name, sizeof(name)) < 0)
 | 
					 | 
				
			||||||
		strcpy(name, "<unknown host>");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	String output = "Hello from ";
 | 
						String output = "Hello from ";
 | 
				
			||||||
	output += name;
 | 
						output += Utility::GetHostName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Dictionary::Ptr perfdata = make_shared<Dictionary>();
 | 
						Dictionary::Ptr perfdata = make_shared<Dictionary>();
 | 
				
			||||||
	perfdata->Set("time", Utility::GetTime());
 | 
						perfdata->Set("time", Utility::GetTime());
 | 
				
			||||||
 | 
				
			|||||||
@ -79,7 +79,7 @@ CheckResult::Ptr PluginCheckTask::ScriptFunc(const Service::Ptr& service)
 | 
				
			|||||||
	result->SetExitStatus(pr.ExitStatus);
 | 
						result->SetExitStatus(pr.ExitStatus);
 | 
				
			||||||
	result->SetExecutionStart(pr.ExecutionStart);
 | 
						result->SetExecutionStart(pr.ExecutionStart);
 | 
				
			||||||
	result->SetExecutionEnd(pr.ExecutionEnd);
 | 
						result->SetExecutionEnd(pr.ExecutionEnd);
 | 
				
			||||||
	result->SetCheckSource(IcingaApplication::GetInstance()->GetIcingaNodeName());
 | 
						result->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return result;
 | 
						return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -33,13 +33,8 @@ REGISTER_SCRIPTFUNCTION(RandomCheck, &RandomCheckTask::ScriptFunc);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
CheckResult::Ptr RandomCheckTask::ScriptFunc(const Service::Ptr&)
 | 
					CheckResult::Ptr RandomCheckTask::ScriptFunc(const Service::Ptr&)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char name[255];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (gethostname(name, sizeof(name)) < 0)
 | 
					 | 
				
			||||||
		strcpy(name, "<unknown host>");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	String output = "Hello from ";
 | 
						String output = "Hello from ";
 | 
				
			||||||
	output += name;
 | 
						output += Utility::GetHostName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Dictionary::Ptr perfdata = make_shared<Dictionary>();
 | 
						Dictionary::Ptr perfdata = make_shared<Dictionary>();
 | 
				
			||||||
	perfdata->Set("time", Utility::GetTime());
 | 
						perfdata->Set("time", Utility::GetTime());
 | 
				
			||||||
@ -48,7 +43,7 @@ CheckResult::Ptr RandomCheckTask::ScriptFunc(const Service::Ptr&)
 | 
				
			|||||||
	cr->SetOutput(output);
 | 
						cr->SetOutput(output);
 | 
				
			||||||
	cr->SetPerformanceData(perfdata);
 | 
						cr->SetPerformanceData(perfdata);
 | 
				
			||||||
	cr->SetState(static_cast<ServiceState>(Utility::Random() % 4));
 | 
						cr->SetState(static_cast<ServiceState>(Utility::Random() % 4));
 | 
				
			||||||
	cr->SetCheckSource(IcingaApplication::GetInstance()->GetIcingaNodeName());
 | 
						cr->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return cr;
 | 
						return cr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user