示例#1
0
void NagiosCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments)
{
	if (arguments.size() < 1)
		throw_exception(invalid_argument("Missing argument: Service must be specified."));

	Value vservice = arguments[0];
	if (!vservice.IsObjectType<DynamicObject>())
		throw_exception(invalid_argument("Argument must be a config object."));

	Service::Ptr service = static_cast<Service::Ptr>(vservice);

	String checkCommand = service->GetCheckCommand();

	vector<Dictionary::Ptr> macroDicts;
	macroDicts.push_back(service->GetMacros());
	macroDicts.push_back(service->GetHost()->GetMacros());
	macroDicts.push_back(IcingaApplication::GetInstance()->GetMacros());
	String command = MacroProcessor::ResolveMacros(checkCommand, macroDicts);

	Process::Ptr process = boost::make_shared<Process>(command);

	NagiosCheckTask ct(task, process);

	ct.m_Result = boost::make_shared<Dictionary>();
	ct.m_Result->Set("schedule_start", Utility::GetTime());

	process->Start(boost::bind(&NagiosCheckTask::ProcessFinishedHandler, ct));
}
示例#2
0
pid_t Application::StartReloadProcess(void)
{
	Log(LogInformation, "Application", "Got reload command: Starting new instance.");

	// prepare arguments
	Array::Ptr args = new Array();
	args->Add(GetExePath(m_ArgV[0]));

	for (int i=1; i < Application::GetArgC(); i++) {
		if (std::string(Application::GetArgV()[i]) != "--reload-internal")
			args->Add(Application::GetArgV()[i]);
		else
			i++;     // the next parameter after --reload-internal is the pid, remove that too
	}

#ifndef _WIN32
	args->Add("--reload-internal");
	args->Add(Convert::ToString(Utility::GetPid()));
#else /* _WIN32 */
	args->Add("--validate");
#endif /* _WIN32 */

	Process::Ptr process = new Process(Process::PrepareCommand(args));
	process->SetTimeout(300);
	process->Run(&ReloadProcessCallback);

	return process->GetPID();
}
void ConfigPackageUtility::AsyncTryActivateStage(const String& packageName, const String& stageName)
{
	// prepare arguments
	Array::Ptr args = new Array();
	args->Add(Application::GetExePath("icinga2"));
	args->Add("daemon");
	args->Add("--validate");
	args->Add("--define");
	args->Add("ActiveStageOverride=" + packageName + ":" + stageName);

	Process::Ptr process = new Process(Process::PrepareCommand(args));
	process->SetTimeout(300);
	process->Run(boost::bind(&TryActivateStageCallback, _1, packageName, stageName));
}
	Array::Ptr export_macros = commandObj->GetExportMacros();

	if (export_macros) {
		BOOST_FOREACH(const String& macro, export_macros) {
			String value;

			if (!MacroProcessor::ResolveMacro(macro, resolvers, cr, &value)) {
				Log(LogWarning, "icinga", "export_macros for notification '" + notification->GetName() + "' refers to unknown macro '" + macro + "'");
				continue;
			}

			envMacros->Set(macro, value);
		}
	}

	Process::Ptr process = make_shared<Process>(Process::SplitCommand(command), envMacros);

	process->SetTimeout(commandObj->GetTimeout());

	ProcessResult pr = process->Run();

	if (pr.ExitStatus != 0) {
		std::ostringstream msgbuf;
		msgbuf << "Notification command '" << command << "' for service '"
		       << service->GetName() << "' failed; exit status: "
		       << pr.ExitStatus << ", output: " << pr.Output;
		Log(LogWarning, "icinga", msgbuf.str());
	}
}