|
7 | 7 | from dataclasses import dataclass, field
|
8 | 8 | from typing import Any, TypedDict
|
9 | 9 |
|
10 |
| -from cmk.checkengine.checkresults import state_markers # pylint: disable=cmk-module-layer-violation |
11 |
| - |
12 | 10 | from cmk.agent_based.v2 import (
|
13 | 11 | AgentSection,
|
14 | 12 | CheckPlugin,
|
@@ -50,7 +48,9 @@ class Aggregation:
|
50 | 48 |
|
51 | 49 | @dataclass
|
52 | 50 | class AggregationError:
|
53 |
| - output: str |
| 51 | + state: State |
| 52 | + notice: str |
| 53 | + details: str |
54 | 54 | affects_state: bool
|
55 | 55 |
|
56 | 56 |
|
@@ -90,22 +90,35 @@ def get_aggregation_errors(
|
90 | 90 |
|
91 | 91 | if aggr.error_state is not None:
|
92 | 92 | yield AggregationError(
|
93 |
| - output=f"{state_markers[aggr.error_state]} {aggr.error_output}", |
| 93 | + state=State(aggr.error_state), |
| 94 | + notice=aggr.error_output or "", |
| 95 | + details=aggr.error_output or "", |
94 | 96 | affects_state=affects_state,
|
95 | 97 | )
|
96 | 98 |
|
97 | 99 | if aggr.custom_output is not None:
|
98 |
| - yield AggregationError(output=aggr.custom_output, affects_state=affects_state) |
| 100 | + yield AggregationError( |
| 101 | + state=State.OK, |
| 102 | + notice=aggr.custom_output, |
| 103 | + details=aggr.custom_output, |
| 104 | + affects_state=affects_state, |
| 105 | + ) |
99 | 106 |
|
100 | 107 | for child in aggr.children:
|
101 | 108 | if errors := list(get_aggregation_errors(child, affects_state)):
|
102 | 109 | yield AggregationError(
|
103 |
| - output=f"+-- {errors[0].output}", affects_state=errors[0].affects_state |
| 110 | + state=errors[0].state, |
| 111 | + notice=errors[0].notice, |
| 112 | + details=f"+-- {errors[0].details}", |
| 113 | + affects_state=errors[0].affects_state, |
104 | 114 | )
|
105 | 115 |
|
106 | 116 | for error in errors[1:]:
|
107 | 117 | yield AggregationError(
|
108 |
| - output=f"| {error.output}", affects_state=error.affects_state |
| 118 | + state=error.state, |
| 119 | + notice=error.notice, |
| 120 | + details=f"| {error.details}", |
| 121 | + affects_state=error.affects_state, |
109 | 122 | )
|
110 | 123 |
|
111 | 124 |
|
@@ -136,23 +149,22 @@ def check_bi_aggregation(item: str, section: Section) -> CheckResult:
|
136 | 149 | summary="Acknowledged: %s" % ("yes" if bi_data["acknowledged"] else "no"),
|
137 | 150 | )
|
138 | 151 |
|
139 |
| - if bi_data["infos"]: |
140 |
| - aggregations = get_aggregations(bi_data["infos"]) |
141 |
| - errors = list(get_aggregation_errors(aggregations, bool(overall_state))) |
142 |
| - |
143 |
| - errors_affecting_state = [error.output for error in errors if error.affects_state] |
144 |
| - other_errors = [error.output for error in errors if not error.affects_state] |
| 152 | + if not bi_data["infos"]: |
| 153 | + return |
145 | 154 |
|
146 |
| - infos = [] |
147 |
| - if errors_affecting_state: |
148 |
| - infos.extend(["", "Aggregation problems affecting the state:"]) |
149 |
| - infos.extend(errors_affecting_state) |
| 155 | + aggregations = get_aggregations(bi_data["infos"]) |
| 156 | + errors = list(get_aggregation_errors(aggregations, bool(overall_state))) |
150 | 157 |
|
151 |
| - if other_errors: |
152 |
| - infos.extend(["", "Aggregation problems not affecting the state:"]) |
153 |
| - infos.extend(other_errors) |
| 158 | + if errors_affecting_state := [e for e in errors if e.affects_state]: |
| 159 | + yield Result(state=State.OK, notice="Aggregation problems affecting the state:") |
| 160 | + yield from ( |
| 161 | + Result(state=e.state, notice=e.notice, details=e.details) |
| 162 | + for e in errors_affecting_state |
| 163 | + ) |
154 | 164 |
|
155 |
| - yield Result(state=State.OK, notice="\n".join(infos)) |
| 165 | + if other_errors := [e for e in errors if not e.affects_state]: |
| 166 | + yield Result(state=State.OK, notice="Aggregation problems not affecting the state:") |
| 167 | + yield from (Result(state=e.state, notice=e.notice, details=e.details) for e in other_errors) |
156 | 168 |
|
157 | 169 |
|
158 | 170 | check_plugin_bi_aggregation = CheckPlugin(
|
|
0 commit comments