本文整理汇总了C++中host::Ptr::GetServiceByShortName方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::GetServiceByShortName方法的具体用法?C++ Ptr::GetServiceByShortName怎么用?C++ Ptr::GetServiceByShortName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类host::Ptr
的用法示例。
在下文中一共展示了Ptr::GetServiceByShortName方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetCheckable
Checkable::Ptr ScheduledDowntime::GetCheckable() const
{
Host::Ptr host = Host::GetByName(GetHostName());
if (GetServiceName().IsEmpty())
return host;
else
return host->GetServiceByShortName(GetServiceName());
}
示例2: SendNotificationsAPIHandler
Value ClusterEvents::SendNotificationsAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
{
Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
if (!endpoint) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'send notification' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
return Empty;
}
Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host)
return Empty;
Checkable::Ptr checkable;
if (params->Contains("service"))
checkable = host->GetServiceByShortName(params->Get("service"));
else
checkable = host;
if (!checkable)
return Empty;
if (origin->FromZone && origin->FromZone != Zone::GetLocalZone()) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'send custom notification' message for checkable '" << checkable->GetName()
<< "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
return Empty;
}
CheckResult::Ptr cr;
Array::Ptr vperf;
if (params->Contains("cr")) {
cr = new CheckResult();
Dictionary::Ptr vcr = params->Get("cr");
if (vcr && vcr->Contains("performance_data")) {
vperf = vcr->Get("performance_data");
if (vperf)
vcr->Remove("performance_data");
Deserialize(cr, vcr, true);
}
}
NotificationType type = static_cast<NotificationType>(static_cast<int>(params->Get("type")));
String author = params->Get("author");
String text = params->Get("text");
Checkable::OnNotificationsRequested(checkable, type, cr, author, text, origin);
return Empty;
}
示例3: OnAllConfigLoaded
void Dependency::OnAllConfigLoaded(void)
{
ObjectImpl<Dependency>::OnAllConfigLoaded();
Host::Ptr childHost = Host::GetByName(GetChildHostName());
if (childHost) {
if (GetChildServiceName().IsEmpty()) {
Log(LogDebug, "Dependency")
<< "Dependency '" << GetName() << "' child host '" << GetChildHostName() << ".";
m_Child = childHost;
} else {
Log(LogDebug, "Dependency")
<< "Dependency '" << GetName() << "' child host '" << GetChildHostName() << "' service '" << GetChildServiceName() << "' .";
m_Child = childHost->GetServiceByShortName(GetChildServiceName());
}
}
if (!m_Child)
BOOST_THROW_EXCEPTION(ScriptError("Dependency '" + GetName() + "' references a child host/service which doesn't exist.", GetDebugInfo()));
m_Child->AddDependency(this);
Host::Ptr parentHost = Host::GetByName(GetParentHostName());
if (parentHost) {
if (GetParentServiceName().IsEmpty()) {
Log(LogDebug, "Dependency")
<< "Dependency '" << GetName() << "' parent host '" << GetParentHostName() << ".";
m_Parent = parentHost;
} else {
Log(LogDebug, "Dependency")
<< "Dependency '" << GetName() << "' parent host '" << GetParentHostName() << "' service '" << GetParentServiceName() << "' .";
m_Parent = parentHost->GetServiceByShortName(GetParentServiceName());
}
}
if (!m_Parent)
BOOST_THROW_EXCEPTION(ScriptError("Dependency '" + GetName() + "' references a parent host/service which doesn't exist.", GetDebugInfo()));
m_Parent->AddReverseDependency(this);
}
示例4: OnAllConfigLoaded
void Downtime::OnAllConfigLoaded(void)
{
ObjectImpl<Downtime>::OnAllConfigLoaded();
Host::Ptr host = Host::GetByName(GetHostName());
if (GetServiceName().IsEmpty())
m_Checkable = host;
else
m_Checkable = host->GetServiceByShortName(GetServiceName());
if (!m_Checkable)
BOOST_THROW_EXCEPTION(ScriptError("Downtime '" + GetName() + "' references a host/service which doesn't exist.", GetDebugInfo()));
}
示例5: OnAllConfigLoaded
void Notification::OnAllConfigLoaded(void)
{
ObjectImpl<Notification>::OnAllConfigLoaded();
Host::Ptr host = Host::GetByName(GetHostName());
if (GetServiceName().IsEmpty())
m_Checkable = host;
else
m_Checkable = host->GetServiceByShortName(GetServiceName());
if (!m_Checkable)
BOOST_THROW_EXCEPTION(ScriptError("Notification object refers to a host/service which doesn't exist.", GetDebugInfo()));
GetCheckable()->RegisterNotification(this);
}
示例6: NextCheckChangedAPIHandler
Value ClusterEvents::NextCheckChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
{
Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
if (!endpoint) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'next check changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
return Empty;
}
Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host)
return Empty;
Checkable::Ptr checkable;
if (params->Contains("service"))
checkable = host->GetServiceByShortName(params->Get("service"));
else
checkable = host;
if (!checkable)
return Empty;
if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'next check changed' message for checkable '" << checkable->GetName()
<< "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
return Empty;
}
double nextCheck = params->Get("next_check");
if (nextCheck < Application::GetStartTime() + 60)
return Empty;
checkable->SetNextCheck(params->Get("next_check"), false, origin);
return Empty;
}
示例7: AcknowledgementSetAPIHandler
Value ClusterEvents::AcknowledgementSetAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
{
Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
if (!endpoint) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'acknowledgement set' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
return Empty;
}
Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host)
return Empty;
Checkable::Ptr checkable;
if (params->Contains("service"))
checkable = host->GetServiceByShortName(params->Get("service"));
else
checkable = host;
if (!checkable)
return Empty;
if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'acknowledgement set' message for checkable '" << checkable->GetName()
<< "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
return Empty;
}
checkable->AcknowledgeProblem(params->Get("author"), params->Get("comment"),
static_cast<AcknowledgementType>(static_cast<int>(params->Get("acktype"))),
params->Get("notify"), params->Get("persistent"), params->Get("expiry"), origin);
return Empty;
}
示例8: AcknowledgementClearedAPIHandler
Value ClusterEvents::AcknowledgementClearedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
{
Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
if (!endpoint) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'acknowledgement cleared' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
return Empty;
}
Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host)
return Empty;
Checkable::Ptr checkable;
if (params->Contains("service"))
checkable = host->GetServiceByShortName(params->Get("service"));
else
checkable = host;
if (!checkable)
return Empty;
if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'acknowledgement cleared' message for checkable '" << checkable->GetName()
<< "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
return Empty;
}
checkable->ClearAcknowledgement(origin);
return Empty;
}
示例9: ProcessCheckResultFile
void CheckResultReader::ProcessCheckResultFile(const String& path) const
{
CONTEXT("Processing check result file '" + path + "'");
String crfile = String(path.Begin(), path.End() - 3); /* Remove the ".ok" extension. */
std::ifstream fp;
fp.exceptions(std::ifstream::badbit);
fp.open(crfile.CStr());
std::map<String, String> attrs;
while (fp.good()) {
std::string line;
std::getline(fp, line);
if (line.empty() || line[0] == '#')
continue; /* Ignore comments and empty lines. */
size_t pos = line.find_first_of('=');
if (pos == std::string::npos)
continue; /* Ignore invalid lines. */
String key = line.substr(0, pos);
String value = line.substr(pos + 1);
attrs[key] = value;
}
/* Remove the checkresult files. */
if (unlink(path.CStr()) < 0)
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("unlink")
<< boost::errinfo_errno(errno)
<< boost::errinfo_file_name(path));
if (unlink(crfile.CStr()) < 0)
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("unlink")
<< boost::errinfo_errno(errno)
<< boost::errinfo_file_name(crfile));
Checkable::Ptr checkable;
Host::Ptr host = Host::GetByName(attrs["host_name"]);
if (!host) {
Log(LogWarning, "CheckResultReader")
<< "Ignoring checkresult file for host '" << attrs["host_name"] << "': Host does not exist.";
return;
}
if (attrs.find("service_description") != attrs.end()) {
Service::Ptr service = host->GetServiceByShortName(attrs["service_description"]);
if (!service) {
Log(LogWarning, "CheckResultReader")
<< "Ignoring checkresult file for host '" << attrs["host_name"]
<< "', service '" << attrs["service_description"] << "': Service does not exist.";
return;
}
checkable = service;
} else
checkable = host;
CheckResult::Ptr result = new CheckResult();
String output = CompatUtility::UnEscapeString(attrs["output"]);
std::pair<String, Value> co = PluginUtility::ParseCheckOutput(output);
result->SetOutput(co.first);
result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
result->SetState(PluginUtility::ExitStatusToState(Convert::ToLong(attrs["return_code"])));
if (attrs.find("start_time") != attrs.end())
result->SetExecutionStart(Convert::ToDouble(attrs["start_time"]));
else
result->SetExecutionStart(Utility::GetTime());
if (attrs.find("finish_time") != attrs.end())
result->SetExecutionEnd(Convert::ToDouble(attrs["finish_time"]));
else
result->SetExecutionEnd(result->GetExecutionStart());
checkable->ProcessCheckResult(result);
Log(LogDebug, "CheckResultReader")
<< "Processed checkresult file for object '" << checkable->GetName() << "'";
/* Reschedule the next check. The side effect of this is that for as long
* as we receive check result files for a host/service we won't execute any
* active checks. */
checkable->SetNextCheck(Utility::GetTime() + checkable->GetCheckInterval());
}
示例10: CheckResultAPIHandler
Value ClusterEvents::CheckResultAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
{
Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
if (!endpoint) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'check result' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
return Empty;
}
CheckResult::Ptr cr;
Array::Ptr vperf;
if (params->Contains("cr")) {
cr = new CheckResult();
Dictionary::Ptr vcr = params->Get("cr");
if (vcr && vcr->Contains("performance_data")) {
vperf = vcr->Get("performance_data");
if (vperf)
vcr->Remove("performance_data");
Deserialize(cr, vcr, true);
}
}
if (!cr)
return Empty;
ArrayData rperf;
if (vperf) {
ObjectLock olock(vperf);
for (const Value& vp : vperf) {
Value p;
if (vp.IsObjectType<Dictionary>()) {
PerfdataValue::Ptr val = new PerfdataValue();
Deserialize(val, vp, true);
rperf.push_back(val);
} else
rperf.push_back(vp);
}
}
cr->SetPerformanceData(new Array(std::move(rperf)));
Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host)
return Empty;
Checkable::Ptr checkable;
if (params->Contains("service"))
checkable = host->GetServiceByShortName(params->Get("service"));
else
checkable = host;
if (!checkable)
return Empty;
if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable) && endpoint != checkable->GetCommandEndpoint()) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'check result' message for checkable '" << checkable->GetName()
<< "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
return Empty;
}
if (!checkable->IsPaused() && Zone::GetLocalZone() == checkable->GetZone() && endpoint == checkable->GetCommandEndpoint())
checkable->ProcessCheckResult(cr);
else
checkable->ProcessCheckResult(cr, origin);
return Empty;
}
示例11: NotificationSentToAllUsersAPIHandler
Value ClusterEvents::NotificationSentToAllUsersAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
{
Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
if (!endpoint) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'sent notification to all users' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
return Empty;
}
Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host)
return Empty;
Checkable::Ptr checkable;
if (params->Contains("service"))
checkable = host->GetServiceByShortName(params->Get("service"));
else
checkable = host;
if (!checkable)
return Empty;
if (origin->FromZone && origin->FromZone != Zone::GetLocalZone()) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'sent notification to all users' message for checkable '" << checkable->GetName()
<< "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
return Empty;
}
CheckResult::Ptr cr;
Array::Ptr vperf;
if (params->Contains("cr")) {
cr = new CheckResult();
Dictionary::Ptr vcr = params->Get("cr");
if (vcr && vcr->Contains("performance_data")) {
vperf = vcr->Get("performance_data");
if (vperf)
vcr->Remove("performance_data");
Deserialize(cr, vcr, true);
}
}
NotificationType type = static_cast<NotificationType>(static_cast<int>(params->Get("type")));
String author = params->Get("author");
String text = params->Get("text");
Notification::Ptr notification = Notification::GetByName(params->Get("notification"));
if (!notification)
return Empty;
Array::Ptr ausers = params->Get("users");
if (!ausers)
return Empty;
std::set<User::Ptr> users;
{
ObjectLock olock(ausers);
for (const String& auser : ausers) {
User::Ptr user = User::GetByName(auser);
if (!user)
continue;
users.insert(user);
}
}
notification->SetLastNotification(params->Get("last_notification"));
notification->SetNextNotification(params->Get("next_notification"));
notification->SetNotificationNumber(params->Get("notification_number"));
notification->SetLastProblemNotification(params->Get("last_problem_notification"));
notification->SetNoMoreNotifications(params->Get("no_more_notifications"));
ArrayData notifiedProblemUsers;
for (const User::Ptr& user : users) {
notifiedProblemUsers.push_back(user->GetName());
}
notification->SetNotifiedProblemUsers(new Array(std::move(notifiedProblemUsers)));
Checkable::OnNotificationSentToAllUsers(notification, checkable, users, type, cr, author, text, origin);
return Empty;
}