mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
DB IDO: Update child object reachability if parentchanges to !{OK,UP}
fixes #7683
This commit is contained in:
parent
b8e7c5bc40
commit
d11286e9a5
@ -61,6 +61,8 @@ void DbEvents::StaticInitialize(void)
|
||||
Checkable::OnEnablePerfdataChanged.connect(boost::bind(&DbEvents::EnablePerfdataChangedHandler, _1, _2));
|
||||
Checkable::OnEnableFlappingChanged.connect(boost::bind(&DbEvents::EnableFlappingChangedHandler, _1, _2));
|
||||
|
||||
Checkable::OnReachabilityChanged.connect(boost::bind(&DbEvents::ReachabilityChangedHandler, _1, _2, _3));
|
||||
|
||||
/* History */
|
||||
Checkable::OnCommentAdded.connect(boost::bind(&DbEvents::AddCommentHistory, _1, _2));
|
||||
Checkable::OnDowntimeAdded.connect(boost::bind(&DbEvents::AddDowntimeHistory, _1, _2));
|
||||
@ -191,6 +193,52 @@ void DbEvents::LastNotificationChangedHandler(const Notification::Ptr& notificat
|
||||
DbObject::OnQuery(query1);
|
||||
}
|
||||
|
||||
void DbEvents::ReachabilityChangedHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, std::set<Checkable::Ptr> children)
|
||||
{
|
||||
int is_reachable = 0;
|
||||
|
||||
if (cr->GetState() == ServiceOK)
|
||||
is_reachable = 1;
|
||||
|
||||
Log(LogDebug, "DbEvents")
|
||||
<< "Updating reachability for checkable '" << checkable->GetName() << "': " << (is_reachable ? "" : "not" ) << " reachable for " << children.size() << " children.";
|
||||
|
||||
BOOST_FOREACH(const Checkable::Ptr& child, children) {
|
||||
Log(LogDebug, "DbEvents")
|
||||
<< "Updating reachability for checkable '" << child->GetName() << "': " << (is_reachable ? "" : "not" ) << " reachable.";
|
||||
|
||||
Host::Ptr host;
|
||||
Service::Ptr service;
|
||||
tie(host, service) = GetHostService(child);
|
||||
|
||||
DbQuery query1;
|
||||
if (service)
|
||||
query1.Table = "servicestatus";
|
||||
else
|
||||
query1.Table = "hoststatus";
|
||||
|
||||
query1.Type = DbQueryInsert | DbQueryUpdate;
|
||||
query1.Category = DbCatState;
|
||||
query1.StatusUpdate = true;
|
||||
query1.Object = DbObject::GetOrCreateByObject(child);
|
||||
|
||||
Dictionary::Ptr fields1 = new Dictionary();
|
||||
fields1->Set("is_reachable", is_reachable);
|
||||
|
||||
query1.Fields = fields1;
|
||||
|
||||
query1.WhereCriteria = new Dictionary();
|
||||
if (service)
|
||||
query1.WhereCriteria->Set("service_object_id", service);
|
||||
else
|
||||
query1.WhereCriteria->Set("host_object_id", host);
|
||||
|
||||
query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
|
||||
DbObject::OnQuery(query1);
|
||||
}
|
||||
}
|
||||
|
||||
/* enable changed events */
|
||||
void DbEvents::EnableActiveChecksChangedHandler(const Checkable::Ptr& checkable, bool enabled)
|
||||
{
|
||||
|
@ -102,6 +102,8 @@ public:
|
||||
static void RemoveAcknowledgement(const Checkable::Ptr& checkable);
|
||||
static void AddAcknowledgementInternal(const Checkable::Ptr& checkable, AcknowledgementType type, bool add);
|
||||
|
||||
static void ReachabilityChangedHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, std::set<Checkable::Ptr> children);
|
||||
|
||||
/* comment, downtime, acknowledgement history */
|
||||
static void AddCommentHistory(const Checkable::Ptr& checkable, const Comment::Ptr& comment);
|
||||
static void AddDowntimeHistory(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime);
|
||||
|
@ -37,6 +37,7 @@ using namespace icinga;
|
||||
|
||||
boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, const MessageOrigin&)> Checkable::OnNewCheckResult;
|
||||
boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, StateType, const MessageOrigin&)> Checkable::OnStateChange;
|
||||
boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, std::set<Checkable::Ptr>, const MessageOrigin&)> Checkable::OnReachabilityChanged;
|
||||
boost::signals2::signal<void (const Checkable::Ptr&, NotificationType, const CheckResult::Ptr&, const String&, const String&)> Checkable::OnNotificationsRequested;
|
||||
boost::signals2::signal<void (const Checkable::Ptr&, double, const MessageOrigin&)> Checkable::OnNextCheckChanged;
|
||||
boost::signals2::signal<void (const Checkable::Ptr&, bool, const MessageOrigin&)> Checkable::OnForceNextCheckChanged;
|
||||
@ -293,6 +294,8 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
|
||||
|
||||
long attempt = 1;
|
||||
|
||||
std::set<Checkable::Ptr> children = GetChildren();
|
||||
|
||||
if (!old_cr) {
|
||||
SetStateType(StateTypeHard);
|
||||
} else if (cr->GetState() == ServiceOK) {
|
||||
@ -306,6 +309,10 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
|
||||
|
||||
ResetNotificationNumbers();
|
||||
SetLastStateOK(Utility::GetTime());
|
||||
|
||||
/* update reachability for child objects in OK state */
|
||||
if (!children.empty())
|
||||
OnReachabilityChanged(this, cr, children, origin);
|
||||
} else {
|
||||
if (old_attempt >= GetMaxCheckAttempts()) {
|
||||
SetStateType(StateTypeHard);
|
||||
@ -330,6 +337,10 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
|
||||
SetLastStateUnknown(Utility::GetTime());
|
||||
break;
|
||||
}
|
||||
|
||||
/* update reachability for child objects in NOT-OK state */
|
||||
if (!children.empty())
|
||||
OnReachabilityChanged(this, cr, children, origin);
|
||||
}
|
||||
|
||||
if (!reachable)
|
||||
|
@ -168,6 +168,7 @@ public:
|
||||
|
||||
static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, const MessageOrigin&)> OnNewCheckResult;
|
||||
static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, StateType, const MessageOrigin&)> OnStateChange;
|
||||
static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, std::set<Checkable::Ptr>, const MessageOrigin&)> OnReachabilityChanged;
|
||||
static boost::signals2::signal<void (const Checkable::Ptr&, NotificationType, const CheckResult::Ptr&,
|
||||
const String&, const String&)> OnNotificationsRequested;
|
||||
static boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const std::set<User::Ptr>&,
|
||||
|
27
test/config/7683.conf
Normal file
27
test/config/7683.conf
Normal file
@ -0,0 +1,27 @@
|
||||
object Host "7683-parent" {
|
||||
check_command = "dummy"
|
||||
vars.dummy_state = 0
|
||||
}
|
||||
|
||||
|
||||
object Host "7683-child1" {
|
||||
check_command = "dummy"
|
||||
vars.dummy_state = 0
|
||||
}
|
||||
|
||||
object Host "7683-child2" {
|
||||
check_command = "dummy"
|
||||
vars.dummy_state = 0
|
||||
}
|
||||
|
||||
object Service "7683-service" {
|
||||
check_command = "dummy"
|
||||
host_name = "7683-parent"
|
||||
vars.dummy_state = 0
|
||||
}
|
||||
|
||||
apply Dependency "test-host" to Host {
|
||||
parent_host_name = "7683-parent"
|
||||
assign where match("7683-child*", host.name)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user