mirror of https://github.com/Icinga/icinga2.git
parent
46e892cc60
commit
0013d26425
|
@ -44,10 +44,10 @@ REGISTER_TYPE(Comment);
|
||||||
|
|
||||||
void Comment::StaticInitialize(void)
|
void Comment::StaticInitialize(void)
|
||||||
{
|
{
|
||||||
l_CommentsExpireTimer = new Timer();
|
l_CommentsExpireTimer = new Timer();
|
||||||
l_CommentsExpireTimer->SetInterval(60);
|
l_CommentsExpireTimer->SetInterval(60);
|
||||||
l_CommentsExpireTimer->OnTimerExpired.connect(boost::bind(&Comment::CommentsExpireTimerHandler));
|
l_CommentsExpireTimer->OnTimerExpired.connect(boost::bind(&Comment::CommentsExpireTimerHandler));
|
||||||
l_CommentsExpireTimer->Start();
|
l_CommentsExpireTimer->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
String CommentNameComposer::MakeName(const String& shortName, const Object::Ptr& context) const
|
String CommentNameComposer::MakeName(const String& shortName, const Object::Ptr& context) const
|
||||||
|
@ -110,9 +110,9 @@ void Comment::Start(bool runtimeCreated)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(l_CommentMutex);
|
boost::mutex::scoped_lock lock(l_CommentMutex);
|
||||||
|
|
||||||
SetLegacyId(l_NextCommentID);
|
SetLegacyId(l_NextCommentID);
|
||||||
l_LegacyCommentsCache[l_NextCommentID] = GetName();
|
l_LegacyCommentsCache[l_NextCommentID] = GetName();
|
||||||
l_NextCommentID++;
|
l_NextCommentID++;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetCheckable()->RegisterComment(this);
|
GetCheckable()->RegisterComment(this);
|
||||||
|
@ -133,7 +133,7 @@ void Comment::Stop(bool runtimeRemoved)
|
||||||
|
|
||||||
Checkable::Ptr Comment::GetCheckable(void) const
|
Checkable::Ptr Comment::GetCheckable(void) const
|
||||||
{
|
{
|
||||||
return m_Checkable;
|
return static_pointer_cast<Checkable>(m_Checkable);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Comment::IsExpired(void) const
|
bool Comment::IsExpired(void) const
|
||||||
|
@ -155,43 +155,43 @@ String Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryTyp
|
||||||
{
|
{
|
||||||
String fullName;
|
String fullName;
|
||||||
|
|
||||||
if (id.IsEmpty())
|
if (id.IsEmpty())
|
||||||
fullName = checkable->GetName() + "!" + Utility::NewUniqueID();
|
fullName = checkable->GetName() + "!" + Utility::NewUniqueID();
|
||||||
else
|
else
|
||||||
fullName = id;
|
fullName = id;
|
||||||
|
|
||||||
Dictionary::Ptr attrs = new Dictionary();
|
Dictionary::Ptr attrs = new Dictionary();
|
||||||
|
|
||||||
attrs->Set("author", author);
|
attrs->Set("author", author);
|
||||||
attrs->Set("text", text);
|
attrs->Set("text", text);
|
||||||
attrs->Set("expire_time", expireTime);
|
attrs->Set("expire_time", expireTime);
|
||||||
attrs->Set("entry_type", entryType);
|
attrs->Set("entry_type", entryType);
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
tie(host, service) = GetHostService(checkable);
|
tie(host, service) = GetHostService(checkable);
|
||||||
|
|
||||||
attrs->Set("host_name", host->GetName());
|
attrs->Set("host_name", host->GetName());
|
||||||
if (service)
|
if (service)
|
||||||
attrs->Set("service_name", service->GetShortName());
|
attrs->Set("service_name", service->GetShortName());
|
||||||
|
|
||||||
String config = ConfigObjectUtility::CreateObjectConfig(Comment::TypeInstance, fullName, true, Array::Ptr(), attrs);
|
String config = ConfigObjectUtility::CreateObjectConfig(Comment::TypeInstance, fullName, true, Array::Ptr(), attrs);
|
||||||
|
|
||||||
Array::Ptr errors = new Array();
|
Array::Ptr errors = new Array();
|
||||||
|
|
||||||
if (!ConfigObjectUtility::CreateObject(Comment::TypeInstance, fullName, config, errors)) {
|
if (!ConfigObjectUtility::CreateObject(Comment::TypeInstance, fullName, config, errors)) {
|
||||||
ObjectLock olock(errors);
|
ObjectLock olock(errors);
|
||||||
BOOST_FOREACH(const String& error, errors) {
|
BOOST_FOREACH(const String& error, errors) {
|
||||||
Log(LogCritical, "Comment", error);
|
Log(LogCritical, "Comment", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_THROW_EXCEPTION(std::runtime_error("Could not create comment."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Could not create comment."));
|
||||||
}
|
}
|
||||||
|
|
||||||
Comment::Ptr comment = Comment::GetByName(fullName);
|
Comment::Ptr comment = Comment::GetByName(fullName);
|
||||||
|
|
||||||
Log(LogNotice, "Comment")
|
Log(LogNotice, "Comment")
|
||||||
<< "Added comment '" << comment->GetName() << "'.";
|
<< "Added comment '" << comment->GetName() << "'.";
|
||||||
|
|
||||||
return fullName;
|
return fullName;
|
||||||
}
|
}
|
||||||
|
@ -205,19 +205,19 @@ void Comment::RemoveComment(const String& id, const MessageOrigin::Ptr& origin)
|
||||||
|
|
||||||
int legacy_id = comment->GetLegacyId();
|
int legacy_id = comment->GetLegacyId();
|
||||||
|
|
||||||
Log(LogNotice, "Comment")
|
Log(LogNotice, "Comment")
|
||||||
<< "Removed comment '" << comment->GetName() << "' from object '" << comment->GetCheckable()->GetName() << "'.";
|
<< "Removed comment '" << comment->GetName() << "' from object '" << comment->GetCheckable()->GetName() << "'.";
|
||||||
|
|
||||||
Array::Ptr errors = new Array();
|
Array::Ptr errors = new Array();
|
||||||
|
|
||||||
if (!ConfigObjectUtility::DeleteObject(comment, false, errors)) {
|
if (!ConfigObjectUtility::DeleteObject(comment, false, errors)) {
|
||||||
ObjectLock olock(errors);
|
ObjectLock olock(errors);
|
||||||
BOOST_FOREACH(const String& error, errors) {
|
BOOST_FOREACH(const String& error, errors) {
|
||||||
Log(LogCritical, "Comment", error);
|
Log(LogCritical, "Comment", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_THROW_EXCEPTION(std::runtime_error("Could not remove comment."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Could not remove comment."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String Comment::GetCommentIDFromLegacyID(int id)
|
String Comment::GetCommentIDFromLegacyID(int id)
|
||||||
|
@ -234,14 +234,14 @@ String Comment::GetCommentIDFromLegacyID(int id)
|
||||||
|
|
||||||
void Comment::CommentsExpireTimerHandler(void)
|
void Comment::CommentsExpireTimerHandler(void)
|
||||||
{
|
{
|
||||||
std::vector<Comment::Ptr> comments;
|
std::vector<Comment::Ptr> comments;
|
||||||
|
|
||||||
BOOST_FOREACH(const Comment::Ptr& comment, ConfigType::GetObjectsByType<Comment>()) {
|
BOOST_FOREACH(const Comment::Ptr& comment, ConfigType::GetObjectsByType<Comment>()) {
|
||||||
comments.push_back(comment);
|
comments.push_back(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FOREACH(const Comment::Ptr& comment, comments) {
|
BOOST_FOREACH(const Comment::Ptr& comment, comments) {
|
||||||
if (comment->IsExpired())
|
if (comment->IsExpired())
|
||||||
RemoveComment(comment->GetName());
|
RemoveComment(comment->GetName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,12 @@
|
||||||
|
|
||||||
#include "icinga/i2-icinga.hpp"
|
#include "icinga/i2-icinga.hpp"
|
||||||
#include "icinga/comment.thpp"
|
#include "icinga/comment.thpp"
|
||||||
|
#include "icinga/checkable.thpp"
|
||||||
#include "remote/messageorigin.hpp"
|
#include "remote/messageorigin.hpp"
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
class Checkable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A comment.
|
* A comment.
|
||||||
*
|
*
|
||||||
|
@ -61,13 +60,13 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void OnAllConfigLoaded(void) override;
|
virtual void OnAllConfigLoaded(void) override;
|
||||||
virtual void Start(bool runtimeCreated) override;
|
virtual void Start(bool runtimeCreated) override;
|
||||||
virtual void Stop(bool runtimeRemoved) override;
|
virtual void Stop(bool runtimeRemoved) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
intrusive_ptr<Checkable> m_Checkable;
|
ObjectImpl<Checkable>::Ptr m_Checkable;
|
||||||
|
|
||||||
static void CommentsExpireTimerHandler(void);
|
static void CommentsExpireTimerHandler(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ void Downtime::Stop(bool runtimeRemoved)
|
||||||
|
|
||||||
Checkable::Ptr Downtime::GetCheckable(void) const
|
Checkable::Ptr Downtime::GetCheckable(void) const
|
||||||
{
|
{
|
||||||
return m_Checkable;
|
return static_pointer_cast<Checkable>(m_Checkable);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Downtime::IsActive(void) const
|
bool Downtime::IsActive(void) const
|
||||||
|
@ -303,7 +303,7 @@ void Downtime::TriggerDowntime(void)
|
||||||
|
|
||||||
double now = Utility::GetTime();
|
double now = Utility::GetTime();
|
||||||
|
|
||||||
if (now < GetStartTime() || now > GetEndTime()) {
|
if (now < GetStartTime() || now > GetEndTime()) {
|
||||||
Log(LogDebug, "Downtime")
|
Log(LogDebug, "Downtime")
|
||||||
<< "Not triggering downtime '" << GetName() << "': current time is outside downtime window.";
|
<< "Not triggering downtime '" << GetName() << "': current time is outside downtime window.";
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -22,13 +22,12 @@
|
||||||
|
|
||||||
#include "icinga/i2-icinga.hpp"
|
#include "icinga/i2-icinga.hpp"
|
||||||
#include "icinga/downtime.thpp"
|
#include "icinga/downtime.thpp"
|
||||||
|
#include "icinga/checkable.thpp"
|
||||||
#include "remote/messageorigin.hpp"
|
#include "remote/messageorigin.hpp"
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
class Checkable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A downtime.
|
* A downtime.
|
||||||
*
|
*
|
||||||
|
@ -75,7 +74,7 @@ protected:
|
||||||
virtual void ValidateEndTime(double value, const ValidationUtils& utils) override;
|
virtual void ValidateEndTime(double value, const ValidationUtils& utils) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
intrusive_ptr<Checkable> m_Checkable;
|
ObjectImpl<Checkable>::Ptr m_Checkable;
|
||||||
|
|
||||||
static void DowntimesExpireTimerHandler(void);
|
static void DowntimesExpireTimerHandler(void);
|
||||||
};
|
};
|
||||||
|
|
|
@ -119,7 +119,7 @@ void Notification::OnAllConfigLoaded(void)
|
||||||
if (!m_Checkable)
|
if (!m_Checkable)
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Notification object refers to a host/service which doesn't exist.", GetDebugInfo()));
|
BOOST_THROW_EXCEPTION(ScriptError("Notification object refers to a host/service which doesn't exist.", GetDebugInfo()));
|
||||||
|
|
||||||
m_Checkable->RegisterNotification(this);
|
GetCheckable()->RegisterNotification(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::Start(bool runtimeCreated)
|
void Notification::Start(bool runtimeCreated)
|
||||||
|
@ -144,7 +144,7 @@ void Notification::Stop(bool runtimeRemoved)
|
||||||
|
|
||||||
Checkable::Ptr Notification::GetCheckable(void) const
|
Checkable::Ptr Notification::GetCheckable(void) const
|
||||||
{
|
{
|
||||||
return m_Checkable;
|
return static_pointer_cast<Checkable>(m_Checkable);
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationCommand::Ptr Notification::GetCommand(void) const
|
NotificationCommand::Ptr Notification::GetCommand(void) const
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "icinga/i2-icinga.hpp"
|
#include "icinga/i2-icinga.hpp"
|
||||||
#include "icinga/notification.thpp"
|
#include "icinga/notification.thpp"
|
||||||
|
#include "icinga/checkable.thpp"
|
||||||
#include "icinga/user.hpp"
|
#include "icinga/user.hpp"
|
||||||
#include "icinga/usergroup.hpp"
|
#include "icinga/usergroup.hpp"
|
||||||
#include "icinga/timeperiod.hpp"
|
#include "icinga/timeperiod.hpp"
|
||||||
|
@ -66,7 +67,6 @@ enum NotificationType
|
||||||
};
|
};
|
||||||
|
|
||||||
class NotificationCommand;
|
class NotificationCommand;
|
||||||
class Checkable;
|
|
||||||
class ApplyRule;
|
class ApplyRule;
|
||||||
struct ScriptFrame;
|
struct ScriptFrame;
|
||||||
class Host;
|
class Host;
|
||||||
|
@ -122,7 +122,7 @@ protected:
|
||||||
virtual void Stop(bool runtimeRemoved) override;
|
virtual void Stop(bool runtimeRemoved) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
intrusive_ptr<Checkable> m_Checkable;
|
ObjectImpl<Checkable>::Ptr m_Checkable;
|
||||||
|
|
||||||
void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
|
void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue