MCPcopy Create free account
hub / github.com/Icinga/icinga2 / GetState

Method GetState

lib/icinga/dependency-state.cpp:85–126  ·  view source on GitHub ↗

* Retrieve the state of the given dependency group. * * The state of the dependency group is determined based on the state of the parent Checkables and dependency objects * of the group. A dependency group is considered unreachable when none of the parent Checkables is reachable. However, * a dependency group may still be marked as failed even when it has reachable parent Checkables, but an un

Source from the content-addressed store, hash-verified

83 * @return - Returns the state of the current dependency group.
84 */
85DependencyGroup::State DependencyStateChecker::GetState(const DependencyGroup::ConstPtr& group, const Checkable* child, int rstack)
86{
87 using State = DependencyGroup::State;
88
89 auto dependencies(group->GetDependenciesForChild(child));
90 size_t reachable = 0, available = 0;
91
92 for (const auto& dependency : dependencies) {
93 if (IsReachable(dependency->GetParent(), rstack)) {
94 reachable++;
95
96 // Only reachable parents are considered for availability. If they are unreachable and checks are
97 // disabled, they could be incorrectly treated as available otherwise.
98 if (dependency->IsAvailable(m_DependencyType)) {
99 available++;
100 }
101 }
102 }
103
104 if (group->IsRedundancyGroup()) {
105 // The state of a redundancy group is determined by the best state of any parent. If any parent ist reachable,
106 // the redundancy group is reachable, analogously for availability.
107 if (reachable == 0) {
108 return State::Unreachable;
109 } else if (available == 0) {
110 return State::Failed;
111 } else {
112 return State::Ok;
113 }
114 } else {
115 // For dependencies without a redundancy group, dependencies.size() will be 1 in almost all cases. It will only
116 // contain more elements if there are duplicate dependency config objects between two checkables. In this case,
117 // all of them have to be reachable/available as they don't provide redundancy.
118 if (reachable < dependencies.size()) {
119 return State::Unreachable;
120 } else if (available < dependencies.size()) {
121 return State::Failed;
122 } else {
123 return State::Ok;
124 }
125 }
126}

Callers 1

IsReachableMethod · 0.45

Calls 5

IsAvailableMethod · 0.80
IsRedundancyGroupMethod · 0.80
GetParentMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected