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