}
#endif /* _WIN32 */
-void CompatComponent::DumpComments(ofstream& fp, const Service::Ptr& owner, CompatObjectType type)
+void CompatComponent::DumpComments(ostream& fp, const Service::Ptr& owner, CompatObjectType type)
{
ObjectLock olock(owner);
}
}
-void CompatComponent::DumpDowntimes(ofstream& fp, const Service::Ptr& owner, CompatObjectType type)
+void CompatComponent::DumpDowntimes(ostream& fp, const Service::Ptr& owner, CompatObjectType type)
{
ObjectLock olock(owner);
}
}
-void CompatComponent::DumpHostStatus(ofstream& fp, const Host::Ptr& host)
+void CompatComponent::DumpHostStatus(ostream& fp, const Host::Ptr& host)
{
Service::Ptr hc;
}
}
-void CompatComponent::DumpHostObject(ofstream& fp, const Host::Ptr& host)
+void CompatComponent::DumpHostObject(ostream& fp, const Host::Ptr& host)
{
ObjectLock olock(host);
<< "\n";
}
-void CompatComponent::DumpServiceStatusAttrs(ofstream& fp, const Service::Ptr& service, CompatObjectType type)
+void CompatComponent::DumpServiceStatusAttrs(ostream& fp, const Service::Ptr& service, CompatObjectType type)
{
String output;
String perfdata;
}
}
-void CompatComponent::DumpServiceStatus(ofstream& fp, const Service::Ptr& service)
+void CompatComponent::DumpServiceStatus(ostream& fp, const Service::Ptr& service)
{
String host_name, short_name;
Host::Ptr host;
DumpComments(fp, service, CompatTypeService);
}
-void CompatComponent::DumpServiceObject(ofstream& fp, const Service::Ptr& service)
+void CompatComponent::DumpServiceObject(ostream& fp, const Service::Ptr& service)
{
set<Service::Ptr> parentServices;
Host::Ptr host;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
Host::Ptr host = static_pointer_cast<Host>(object);
- DumpHostStatus(statusfp, host);
- DumpHostObject(objectfp, host);
+ stringstream tempstatusfp, tempobjectfp;
+
+ DumpHostStatus(tempstatusfp, host);
+ DumpHostObject(tempobjectfp, host);
+
+ statusfp << tempstatusfp.str();
+ objectfp << tempobjectfp.str();
}
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("HostGroup")) {
HostGroup::Ptr hg = static_pointer_cast<HostGroup>(object);
+ stringstream tempobjectfp;
+
{
ObjectLock olock(hg);
- objectfp << "define hostgroup {" << "\n"
+ tempobjectfp << "define hostgroup {" << "\n"
<< "\t" << "hostgroup_name" << "\t" << hg->GetName() << "\n"
<< "\t" << "notes_url" << "\t" << hg->GetNotesUrl() << "\n"
<< "\t" << "action_url" << "\t" << hg->GetActionUrl() << "\n";
}
- objectfp << "\t" << "members" << "\t";
- DumpNameList(objectfp, HostGroup::GetMembers(hg));
- objectfp << "\n"
+ tempobjectfp << "\t" << "members" << "\t";
+ DumpNameList(tempobjectfp, HostGroup::GetMembers(hg));
+ tempobjectfp << "\n"
<< "}" << "\n";
+
+ objectfp << tempobjectfp.str();
}
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
Service::Ptr service = static_pointer_cast<Service>(object);
+ stringstream tempstatusfp, tempobjectfp;
+
DumpServiceStatus(statusfp, service);
DumpServiceObject(objectfp, service);
+
+ statusfp << tempstatusfp.str();
+ objectfp << tempobjectfp.str();
}
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("ServiceGroup")) {
ServiceGroup::Ptr sg = static_pointer_cast<ServiceGroup>(object);
+ stringstream tempobjectfp;
+
{
ObjectLock olock(sg);
- objectfp << "define servicegroup {" << "\n"
+ tempobjectfp << "define servicegroup {" << "\n"
<< "\t" << "servicegroup_name" << "\t" << sg->GetName() << "\n"
<< "\t" << "notes_url" << "\t" << sg->GetNotesUrl() << "\n"
<< "\t" << "action_url" << "\t" << sg->GetActionUrl() << "\n";
}
- objectfp << "\t" << "members" << "\t";
+ tempobjectfp << "\t" << "members" << "\t";
vector<String> sglist;
BOOST_FOREACH(const Service::Ptr& service, ServiceGroup::GetMembers(sg)) {
sglist.push_back(short_name);
}
- DumpStringList(objectfp, sglist);
+ DumpStringList(tempobjectfp, sglist);
- objectfp << "\n"
+ tempobjectfp << "\n"
<< "}" << "\n";
+
+ objectfp << tempobjectfp.str();
}
statusfp.close();
String GetLogPath(void) const;
String GetCommandPath(void) const;
- void DumpDowntimes(ofstream& fp, const Service::Ptr& owner, CompatObjectType type);
- void DumpComments(ofstream& fp, const Service::Ptr& owner, CompatObjectType type);
- void DumpHostStatus(ofstream& fp, const Host::Ptr& host);
- void DumpHostObject(ofstream& fp, const Host::Ptr& host);
+ void DumpDowntimes(ostream& fp, const Service::Ptr& owner, CompatObjectType type);
+ void DumpComments(ostream& fp, const Service::Ptr& owner, CompatObjectType type);
+ void DumpHostStatus(ostream& fp, const Host::Ptr& host);
+ void DumpHostObject(ostream& fp, const Host::Ptr& host);
- void DumpServiceStatusAttrs(ofstream& fp, const Service::Ptr& service, CompatObjectType type);
+ void DumpServiceStatusAttrs(ostream& fp, const Service::Ptr& service, CompatObjectType type);
template<typename T>
- void DumpNameList(ofstream& fp, const T& list)
+ void DumpNameList(ostream& fp, const T& list)
{
typename T::const_iterator it;
bool first = true;
}
template<typename T>
- void DumpStringList(ofstream& fp, const T& list)
+ void DumpStringList(ostream& fp, const T& list)
{
typename T::const_iterator it;
bool first = true;
}
}
- void DumpServiceStatus(ofstream& fp, const Service::Ptr& service);
- void DumpServiceObject(ofstream& fp, const Service::Ptr& service);
+ void DumpServiceStatus(ostream& fp, const Service::Ptr& service);
+ void DumpServiceObject(ostream& fp, const Service::Ptr& service);
void StatusTimerHandler(void);
};
BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' is OK."));
Logger::Write(LogInformation, "icinga", "Setting acknowledgement for service '" + service->GetName() + "'");
- service->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
- service->SetAcknowledgementExpiry(0);
+ service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal);
}
void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const vector<String>& arguments)
BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' is OK."));
Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for service '" + service->GetName() + "'");
- service->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
- service->SetAcknowledgementExpiry(timestamp);
+ service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp);
}
void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const vector<String>& arguments)
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
Logger::Write(LogInformation, "icinga", "Removing acknowledgement for service '" + service->GetName() + "'");
- service->SetAcknowledgement(AcknowledgementNone);
- service->SetAcknowledgementExpiry(0);
+ service->ClearAcknowledgement();
}
void ExternalCommandProcessor::AcknowledgeHostProblem(double, const vector<String>& arguments)
if (service->GetState() == StateOK)
BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' is OK."));
- service->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
- service->SetAcknowledgementExpiry(0);
+ service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal);
}
}
if (service->GetState() == StateOK)
BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' is OK."));
- service->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
- service->SetAcknowledgementExpiry(timestamp);
+ service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp);
}
}
Logger::Write(LogInformation, "icinga", "Removing acknowledgement for host '" + host->GetName() + "'");
Service::Ptr service = host->GetHostCheckService();
if (service) {
- service->SetAcknowledgement(AcknowledgementNone);
- service->SetAcknowledgementExpiry(0);
+ service->ClearAcknowledgement();
}
}
case NotificationDowntimeRemoved:
return "DOWNTIMECANCELLED";
case NotificationCustom:
- return "DOWNTIMECUSTOM";
+ return "CUSTOM";
+ case NotificationAcknowledgement:
+ return "ACKNOWLEDGEMENT";
case NotificationProblem:
return "PROBLEM";
case NotificationRecovery:
NotificationDowntimeEnd,
NotificationDowntimeRemoved,
NotificationCustom,
+ NotificationAcknowledgement,
NotificationProblem,
NotificationRecovery
};
REGISTER_SCRIPTFUNCTION("PluginCheck", &PluginCheckTask::ScriptFunc);
-PluginCheckTask::PluginCheckTask(const ScriptTask::Ptr& task, const Process::Ptr& process)
- : m_Task(task), m_Process(process)
+PluginCheckTask::PluginCheckTask(const ScriptTask::Ptr& task, const Process::Ptr& process, const Value& command)
+ : m_Task(task), m_Process(process), m_Command(command)
{ }
void PluginCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments)
Process::Ptr process = boost::make_shared<Process>(Process::SplitCommand(command), macros);
- PluginCheckTask ct(task, process);
+ PluginCheckTask ct(task, process, command);
process->Start(boost::bind(&PluginCheckTask::ProcessFinishedHandler, ct));
}
String output = pr.Output;
output.Trim();
Dictionary::Ptr result = ParseCheckOutput(output);
+ result->Set("command", ct.m_Command);
result->Set("state", ExitStatusToState(pr.ExitStatus));
result->Set("execution_start", pr.ExecutionStart);
result->Set("execution_end", pr.ExecutionEnd);
private:
static void ProcessFinishedHandler(PluginCheckTask ct);
- PluginCheckTask(const ScriptTask::Ptr& task, const Process::Ptr& process);
+ PluginCheckTask(const ScriptTask::Ptr& task, const Process::Ptr& process, const Value& command);
ScriptTask::Ptr m_Task;
Process::Ptr m_Process;
+ Value m_Command;
};
}
Set("acknowledgement_expiry", timestamp);
}
+void Service::AcknowledgeProblem(AcknowledgementType type, double expiry)
+{
+ SetAcknowledgement(type);
+ SetAcknowledgementExpiry(expiry);
+
+ RequestNotifications(NotificationAcknowledgement);
+}
+
+void Service::ClearAcknowledgement(void)
+{
+ SetAcknowledgement(AcknowledgementNone);
+ SetAcknowledgementExpiry(0);
+}
+
void Service::OnAttributeChanged(const String& name, const Value& oldValue)
{
if (name == "checker")
void ApplyCheckResult(const Dictionary::Ptr& cr);
static void UpdateStatistics(const Dictionary::Ptr& cr);
+ void AcknowledgeProblem(AcknowledgementType type, double expiry = 0);
+ void ClearAcknowledgement(void);
+
static void BeginExecuteCheck(const Service::Ptr& self, const function<void (void)>& callback);
void ProcessCheckResult(const Dictionary::Ptr& cr);