1 /*
2 * Copyright 2004-2024 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10 #include <crm_internal.h> // pcmk__str_eq(), etc.
11
12 #include <stdio.h> // NULL
13 #include <stdbool.h> // bool, true, false
14 #include <glib.h> // guint
15 #include <libxml/tree.h> // xmlNode
16
17 #include <crm/common/options.h> // PCMK_META_INTERVAL
18 #include <crm/common/probes.h>
19 #include <crm/common/xml.h> // PCMK_XA_OPERATION
20
21 /*!
22 * \brief Check whether an action name and interval represent a probe
23 *
24 * \param[in] task Action name
25 * \param[in] interval_ms Action interval in milliseconds
26 *
27 * \return true if \p task is \c PCMK_ACTION_MONITOR and \p interval_ms is 0,
28 * otherwise false
29 */
30 bool
31 pcmk_is_probe(const char *task, guint interval_ms)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
32 {
33 // @COMPAT This should be made inline at an API compatibility break
34 return (interval_ms == 0)
35 && pcmk__str_eq(task, PCMK_ACTION_MONITOR, pcmk__str_none);
36 }
37
38 /*!
39 * \brief Check whether an action history entry represents a probe
40 *
41 * \param[in] xml XML of action history entry
42 *
43 * \return true if \p xml is for a probe action, otherwise false
44 */
45 bool
46 pcmk_xe_is_probe(const xmlNode *xml)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
47 {
48 int interval_ms = 0;
49
50 if (xml == NULL) {
51 return false;
52 }
53
54 pcmk__scan_min_int(crm_element_value(xml, PCMK_META_INTERVAL),
55 &interval_ms, 0);
56
57 return pcmk_is_probe(crm_element_value(xml, PCMK_XA_OPERATION),
58 interval_ms);
59 }
60
61 /*!
62 * \brief Check whether an action history entry represents a maskable probe
63 *
64 * \param[in] xml XML of action history entry
65 *
66 * \return true if \p xml is for a failed probe action that should be treated as
67 * successful, otherwise false
68 */
69 bool
70 pcmk_xe_mask_probe_failure(const xmlNode *xml)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
71 {
72 int exec_status = PCMK_EXEC_UNKNOWN;
73 int exit_status = PCMK_OCF_OK;
74
75 if (!pcmk_xe_is_probe(xml)) {
76 return false;
77 }
78
79 crm_element_value_int(xml, PCMK__XA_OP_STATUS, &exec_status);
80 crm_element_value_int(xml, PCMK__XA_RC_CODE, &exit_status);
81
82 return (exit_status == PCMK_OCF_NOT_INSTALLED)
83 || (exit_status == PCMK_OCF_INVALID_PARAM)
84 || (exec_status == PCMK_EXEC_NOT_INSTALLED);
85 }