This source file includes following definitions.
- print_status
- print_xml_status
- print_html_status
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <glib.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <time.h>
16
17 #ifndef PCMK__CONFIG_H
18 # define PCMK__CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <crm/cib/util.h>
23 #include <crm/common/curses_internal.h>
24 #include <crm/common/iso8601_internal.h>
25 #include <crm/common/xml.h>
26 #include <crm/msg_xml.h>
27 #include <crm/pengine/internal.h>
28 #include <crm/pengine/pe_types.h>
29 #include <crm/stonith-ng.h>
30 #include <crm/common/internal.h>
31 #include <crm/common/xml_internal.h>
32 #include <crm/common/util.h>
33 #include <crm/fencing/internal.h>
34
35 #include "crm_mon.h"
36
37 #define CHECK_RC(retcode, retval) \
38 if (retval == pcmk_rc_ok) { \
39 retcode = pcmk_rc_ok; \
40 }
41
42
43
44
45
46
47
48
49
50
51
52
53 void
54 print_status(pe_working_set_t *data_set, crm_exit_t history_rc,
55 stonith_history_t *stonith_history, unsigned int mon_ops,
56 unsigned int print_opts,
57 unsigned int show, const char *prefix, GList *unames, GList *resources)
58 {
59 pcmk__output_t *out = data_set->priv;
60
61 int rc = pcmk_rc_no_output;
62 bool already_printed_failure = false;
63
64 CHECK_RC(rc, out->message(out, "cluster-summary", data_set,
65 pcmk_is_set(mon_ops, mon_op_print_clone_detail),
66 pcmk_is_set(show, mon_show_stack),
67 pcmk_is_set(show, mon_show_dc),
68 pcmk_is_set(show, mon_show_times),
69 pcmk_is_set(show, mon_show_counts),
70 pcmk_is_set(show, mon_show_options)));
71
72 if (pcmk_is_set(show, mon_show_nodes) && unames) {
73 PCMK__OUTPUT_SPACER_IF(out, rc == pcmk_rc_ok);
74 CHECK_RC(rc, out->message(out, "node-list", data_set->nodes, unames,
75 resources, print_opts,
76 pcmk_is_set(mon_ops, mon_op_print_clone_detail),
77 pcmk_is_set(mon_ops, mon_op_print_brief),
78 pcmk_is_set(mon_ops, mon_op_group_by_node)));
79 }
80
81
82 if (pcmk_is_set(show, mon_show_resources)) {
83 CHECK_RC(rc, out->message(out, "resource-list", data_set, print_opts,
84 pcmk_is_set(mon_ops, mon_op_group_by_node),
85 pcmk_is_set(mon_ops, mon_op_inactive_resources),
86 pcmk_is_set(mon_ops, mon_op_print_brief), TRUE, unames,
87 resources, rc == pcmk_rc_ok));
88 }
89
90
91 if (pcmk_is_set(show, mon_show_attributes)) {
92 CHECK_RC(rc, out->message(out, "node-attribute-list", data_set,
93 print_opts, rc == pcmk_rc_ok,
94 pcmk_is_set(mon_ops, mon_op_print_clone_detail),
95 pcmk_is_set(mon_ops, mon_op_print_brief),
96 pcmk_is_set(mon_ops, mon_op_group_by_node),
97 unames, resources));
98 }
99
100
101
102
103 if (pcmk_is_set(show, mon_show_operations)
104 || pcmk_is_set(show, mon_show_failcounts)) {
105
106 CHECK_RC(rc, out->message(out, "node-summary", data_set, unames,
107 resources, pcmk_is_set(show, mon_show_operations),
108 print_opts,
109 pcmk_is_set(mon_ops, mon_op_print_clone_detail),
110 pcmk_is_set(mon_ops, mon_op_print_brief),
111 pcmk_is_set(mon_ops, mon_op_group_by_node),
112 pcmk_is_set(mon_ops, mon_op_print_timing),
113 rc == pcmk_rc_ok));
114 }
115
116
117 if (pcmk_is_set(show, mon_show_failures)
118 && xml_has_children(data_set->failed)) {
119
120 CHECK_RC(rc, out->message(out, "failed-action-list", data_set, unames,
121 resources, rc == pcmk_rc_ok));
122 }
123
124
125 if (pcmk_is_set(show, mon_show_fence_failed)
126 && pcmk_is_set(mon_ops, mon_op_fence_history)) {
127
128 if (history_rc == 0) {
129 stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_eq,
130 GINT_TO_POINTER(st_failed));
131
132 if (hp) {
133 CHECK_RC(rc, out->message(out, "failed-fencing-list", stonith_history, unames,
134 pcmk_is_set(mon_ops, mon_op_fence_full_history),
135 rc == pcmk_rc_ok));
136 }
137 } else {
138 PCMK__OUTPUT_SPACER_IF(out, rc == pcmk_rc_ok);
139 out->begin_list(out, NULL, NULL, "Failed Fencing Actions");
140 out->list_item(out, NULL, "Failed to get fencing history: %s",
141 crm_exit_str(history_rc));
142 out->end_list(out);
143
144 already_printed_failure = true;
145 }
146 }
147
148
149 if (pcmk_is_set(show, mon_show_tickets)) {
150 CHECK_RC(rc, out->message(out, "ticket-list", data_set, rc == pcmk_rc_ok));
151 }
152
153
154 if (pcmk_is_set(show, mon_show_bans)) {
155 CHECK_RC(rc, out->message(out, "ban-list", data_set, prefix, resources,
156 pcmk_is_set(mon_ops, mon_op_print_clone_detail),
157 rc == pcmk_rc_ok));
158 }
159
160
161 if (pcmk_is_set(mon_ops, mon_op_fence_history)) {
162 if (history_rc != 0) {
163 if (!already_printed_failure) {
164 PCMK__OUTPUT_SPACER_IF(out, rc == pcmk_rc_ok);
165 out->begin_list(out, NULL, NULL, "Failed Fencing Actions");
166 out->list_item(out, NULL, "Failed to get fencing history: %s",
167 crm_exit_str(history_rc));
168 out->end_list(out);
169 }
170 } else if (pcmk_is_set(show, mon_show_fence_worked)) {
171 stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_neq,
172 GINT_TO_POINTER(st_failed));
173
174 if (hp) {
175 CHECK_RC(rc, out->message(out, "fencing-list", hp, unames,
176 pcmk_is_set(mon_ops, mon_op_fence_full_history),
177 rc == pcmk_rc_ok));
178 }
179 } else if (pcmk_is_set(show, mon_show_fence_pending)) {
180 stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_pending, NULL);
181
182 if (hp) {
183 CHECK_RC(rc, out->message(out, "pending-fencing-list", hp, unames,
184 pcmk_is_set(mon_ops, mon_op_fence_full_history),
185 rc == pcmk_rc_ok));
186 }
187 }
188 }
189 }
190
191
192
193
194
195
196
197
198
199
200
201
202 void
203 print_xml_status(pe_working_set_t *data_set, crm_exit_t history_rc,
204 stonith_history_t *stonith_history, unsigned int mon_ops,
205 unsigned int print_opts,
206 unsigned int show, const char *prefix, GList *unames, GList *resources)
207 {
208 pcmk__output_t *out = data_set->priv;
209
210 out->message(out, "cluster-summary", data_set,
211 pcmk_is_set(mon_ops, mon_op_print_clone_detail),
212 pcmk_is_set(show, mon_show_stack),
213 pcmk_is_set(show, mon_show_dc),
214 pcmk_is_set(show, mon_show_times),
215 pcmk_is_set(show, mon_show_counts),
216 pcmk_is_set(show, mon_show_options));
217
218
219 if (pcmk_is_set(show, mon_show_nodes)) {
220 out->message(out, "node-list", data_set->nodes, unames,
221 resources, print_opts,
222 pcmk_is_set(mon_ops, mon_op_print_clone_detail),
223 pcmk_is_set(mon_ops, mon_op_print_brief),
224 pcmk_is_set(mon_ops, mon_op_group_by_node));
225 }
226
227
228 if (pcmk_is_set(show, mon_show_resources)) {
229 out->message(out, "resource-list", data_set, print_opts,
230 pcmk_is_set(mon_ops, mon_op_group_by_node),
231 pcmk_is_set(mon_ops, mon_op_inactive_resources),
232 FALSE, FALSE, unames, resources, FALSE);
233 }
234
235
236 if (pcmk_is_set(show, mon_show_attributes)) {
237 out->message(out, "node-attribute-list", data_set,
238 print_opts, FALSE,
239 pcmk_is_set(mon_ops, mon_op_print_clone_detail),
240 pcmk_is_set(mon_ops, mon_op_print_brief),
241 pcmk_is_set(mon_ops, mon_op_group_by_node),
242 unames, resources);
243 }
244
245
246
247
248 if (pcmk_is_set(show, mon_show_operations)
249 || pcmk_is_set(show, mon_show_failcounts)) {
250
251 out->message(out, "node-summary", data_set, unames,
252 resources, pcmk_is_set(show, mon_show_operations),
253 print_opts,
254 pcmk_is_set(mon_ops, mon_op_print_clone_detail),
255 pcmk_is_set(mon_ops, mon_op_print_brief),
256 pcmk_is_set(mon_ops, mon_op_group_by_node),
257 pcmk_is_set(mon_ops, mon_op_print_timing),
258 FALSE);
259 }
260
261
262 if (pcmk_is_set(show, mon_show_failures)
263 && xml_has_children(data_set->failed)) {
264
265 out->message(out, "failed-action-list", data_set, unames, resources,
266 FALSE);
267 }
268
269
270 if (pcmk_is_set(show, mon_show_fencing_all)
271 && pcmk_is_set(mon_ops, mon_op_fence_history)) {
272
273 out->message(out, "full-fencing-list", history_rc, stonith_history,
274 unames, pcmk_is_set(mon_ops, mon_op_fence_full_history),
275 FALSE);
276 }
277
278
279 if (pcmk_is_set(show, mon_show_tickets)) {
280 out->message(out, "ticket-list", data_set, FALSE);
281 }
282
283
284 if (pcmk_is_set(show, mon_show_bans)) {
285 out->message(out, "ban-list", data_set, prefix, resources,
286 pcmk_is_set(mon_ops, mon_op_print_clone_detail), FALSE);
287 }
288 }
289
290
291
292
293
294
295
296
297
298
299
300
301 int
302 print_html_status(pe_working_set_t *data_set, crm_exit_t history_rc,
303 stonith_history_t *stonith_history, unsigned int mon_ops,
304 unsigned int print_opts,
305 unsigned int show, const char *prefix, GList *unames, GList *resources)
306 {
307 pcmk__output_t *out = data_set->priv;
308
309 bool already_printed_failure = false;
310
311 out->message(out, "cluster-summary", data_set,
312 pcmk_is_set(mon_ops, mon_op_print_clone_detail),
313 pcmk_is_set(show, mon_show_stack),
314 pcmk_is_set(show, mon_show_dc),
315 pcmk_is_set(show, mon_show_times),
316 pcmk_is_set(show, mon_show_counts),
317 pcmk_is_set(show, mon_show_options));
318
319
320 if (pcmk_is_set(show, mon_show_nodes) && unames) {
321 out->message(out, "node-list", data_set->nodes, unames,
322 resources, print_opts,
323 pcmk_is_set(mon_ops, mon_op_print_clone_detail),
324 pcmk_is_set(mon_ops, mon_op_print_brief),
325 pcmk_is_set(mon_ops, mon_op_group_by_node));
326 }
327
328
329 if (pcmk_is_set(show, mon_show_resources)) {
330 out->message(out, "resource-list", data_set, print_opts,
331 pcmk_is_set(mon_ops, mon_op_group_by_node),
332 pcmk_is_set(mon_ops, mon_op_inactive_resources),
333 pcmk_is_set(mon_ops, mon_op_print_brief), TRUE, unames,
334 resources, FALSE);
335 }
336
337
338 if (pcmk_is_set(show, mon_show_attributes)) {
339 out->message(out, "node-attribute-list", data_set,
340 print_opts, FALSE,
341 pcmk_is_set(mon_ops, mon_op_print_clone_detail),
342 pcmk_is_set(mon_ops, mon_op_print_brief),
343 pcmk_is_set(mon_ops, mon_op_group_by_node),
344 unames, resources);
345 }
346
347
348
349
350 if (pcmk_is_set(show, mon_show_operations)
351 || pcmk_is_set(show, mon_show_failcounts)) {
352
353 out->message(out, "node-summary", data_set, unames,
354 resources, pcmk_is_set(show, mon_show_operations),
355 print_opts,
356 pcmk_is_set(mon_ops, mon_op_print_clone_detail),
357 pcmk_is_set(mon_ops, mon_op_print_brief),
358 pcmk_is_set(mon_ops, mon_op_group_by_node),
359 pcmk_is_set(mon_ops, mon_op_print_timing),
360 FALSE);
361 }
362
363
364 if (pcmk_is_set(show, mon_show_failures)
365 && xml_has_children(data_set->failed)) {
366
367 out->message(out, "failed-action-list", data_set, unames, resources,
368 FALSE);
369 }
370
371
372 if (pcmk_is_set(show, mon_show_fence_failed)
373 && pcmk_is_set(mon_ops, mon_op_fence_history)) {
374
375 if (history_rc == 0) {
376 stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_eq,
377 GINT_TO_POINTER(st_failed));
378
379 if (hp) {
380 out->message(out, "failed-fencing-list", stonith_history, unames,
381 pcmk_is_set(mon_ops, mon_op_fence_full_history), FALSE);
382 }
383 } else {
384 out->begin_list(out, NULL, NULL, "Failed Fencing Actions");
385 out->list_item(out, NULL, "Failed to get fencing history: %s",
386 crm_exit_str(history_rc));
387 out->end_list(out);
388 }
389 }
390
391
392 if (pcmk_is_set(mon_ops, mon_op_fence_history)) {
393 if (history_rc != 0) {
394 if (!already_printed_failure) {
395 out->begin_list(out, NULL, NULL, "Failed Fencing Actions");
396 out->list_item(out, NULL, "Failed to get fencing history: %s",
397 crm_exit_str(history_rc));
398 out->end_list(out);
399 }
400 } else if (pcmk_is_set(show, mon_show_fence_worked)) {
401 stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_neq,
402 GINT_TO_POINTER(st_failed));
403
404 if (hp) {
405 out->message(out, "fencing-list", hp, unames,
406 pcmk_is_set(mon_ops, mon_op_fence_full_history),
407 FALSE);
408 }
409 } else if (pcmk_is_set(show, mon_show_fence_pending)) {
410 stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_pending, NULL);
411
412 if (hp) {
413 out->message(out, "pending-fencing-list", hp, unames,
414 pcmk_is_set(mon_ops, mon_op_fence_full_history),
415 FALSE);
416 }
417 }
418 }
419
420
421 if (pcmk_is_set(show, mon_show_tickets)) {
422 out->message(out, "ticket-list", data_set, FALSE);
423 }
424
425
426 if (pcmk_is_set(show, mon_show_bans)) {
427 out->message(out, "ban-list", data_set, prefix, resources,
428 pcmk_is_set(mon_ops, mon_op_print_clone_detail), FALSE);
429 }
430
431 return 0;
432 }