pacemaker 2.1.8-2.1.8
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
alerts.c
Go to the documentation of this file.
1/*
2 * Copyright 2015-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>
11#include <crm/crm.h>
12#include <crm/lrmd.h>
13#include <crm/common/xml.h>
17
18/*
19 * to allow script compatibility we can have more than one
20 * set of environment variables
21 */
23{
25 "CRM_notify_recipient", "CRM_alert_recipient", NULL
26 },
28 "CRM_notify_node", "CRM_alert_node", NULL
29 },
31 "CRM_notify_nodeid", "CRM_alert_nodeid", NULL
32 },
34 "CRM_notify_rsc", "CRM_alert_rsc", NULL
35 },
37 "CRM_notify_task", "CRM_alert_task", NULL
38 },
40 "CRM_notify_interval", "CRM_alert_interval", NULL
41 },
43 "CRM_notify_desc", "CRM_alert_desc", NULL
44 },
46 "CRM_notify_status", "CRM_alert_status", NULL
47 },
49 "CRM_notify_target_rc", "CRM_alert_target_rc", NULL
50 },
52 "CRM_notify_rc", "CRM_alert_rc", NULL
53 },
55 "CRM_notify_kind", "CRM_alert_kind", NULL
56 },
58 "CRM_notify_version", "CRM_alert_version", NULL
59 },
61 "CRM_notify_node_sequence", PCMK__ALERT_NODE_SEQUENCE, NULL
62 },
64 "CRM_notify_timestamp", "CRM_alert_timestamp", NULL
65 },
67 "CRM_notify_attribute_name", "CRM_alert_attribute_name", NULL
68 },
70 "CRM_notify_attribute_value", "CRM_alert_attribute_value", NULL
71 },
73 "CRM_notify_timestamp_epoch", "CRM_alert_timestamp_epoch", NULL
74 },
76 "CRM_notify_timestamp_usec", "CRM_alert_timestamp_usec", NULL
77 },
79 "CRM_notify_exec_time", "CRM_alert_exec_time", NULL
80 }
81};
82
95pcmk__alert_new(const char *id, const char *path)
96{
98
99 CRM_ASSERT((id != NULL) && (path != NULL));
100 entry->id = pcmk__str_copy(id);
101 entry->path = pcmk__str_copy(path);
103 entry->flags = pcmk__alert_default;
104 return entry;
105}
106
107void
109{
110 if (entry) {
111 free(entry->id);
112 free(entry->path);
113 free(entry->tstamp_format);
114 free(entry->recipient);
115
116 g_strfreev(entry->select_attribute_name);
117 if (entry->envvars) {
118 g_hash_table_destroy(entry->envvars);
119 }
120 free(entry);
121 }
122}
123
134{
135 pcmk__alert_t *new_entry = pcmk__alert_new(entry->id, entry->path);
136
137 new_entry->timeout = entry->timeout;
138 new_entry->flags = entry->flags;
139 new_entry->envvars = pcmk__str_table_dup(entry->envvars);
140 new_entry->tstamp_format = pcmk__str_copy(entry->tstamp_format);
141 new_entry->recipient = pcmk__str_copy(entry->recipient);
142 if (entry->select_attribute_name) {
143 new_entry->select_attribute_name = g_strdupv(entry->select_attribute_name);
144 }
145 return new_entry;
146}
147
148void
150 const char *value)
151{
152 for (const char **key = pcmk__alert_keys[name]; *key; key++) {
153 if (value) {
154 crm_trace("Inserting alert key %s = '%s'", *key, value);
155 pcmk__insert_dup(table, *key, value);
156 } else {
157 crm_trace("Removing alert key %s (no value given)", *key);
158 g_hash_table_remove(table, *key);
159 }
160 }
161}
162
163void
165 int value)
166{
167 for (const char **key = pcmk__alert_keys[name]; *key; key++) {
168 crm_trace("Inserting alert key %s = %d", *key, value);
169 g_hash_table_insert(table, pcmk__str_copy(*key), pcmk__itoa(value));
170 }
171}
void pcmk__free_alert(pcmk__alert_t *entry)
Definition alerts.c:108
const char * pcmk__alert_keys[PCMK__ALERT_INTERNAL_KEY_MAX][3]
Definition alerts.c:22
pcmk__alert_t * pcmk__alert_new(const char *id, const char *path)
Create a new alert entry structure.
Definition alerts.c:95
pcmk__alert_t * pcmk__dup_alert(const pcmk__alert_t *entry)
Definition alerts.c:133
void pcmk__add_alert_key_int(GHashTable *table, enum pcmk__alert_keys_e name, int value)
Definition alerts.c:164
void pcmk__add_alert_key(GHashTable *table, enum pcmk__alert_keys_e name, const char *value)
Definition alerts.c:149
#define PCMK__ALERT_NODE_SEQUENCE
pcmk__alert_keys_e
@ PCMK__alert_key_node
@ PCMK__alert_key_task
@ PCMK__alert_key_timestamp_epoch
@ PCMK__alert_key_rc
@ PCMK__alert_key_status
@ PCMK__alert_key_nodeid
@ PCMK__alert_key_interval
@ PCMK__alert_key_timestamp
@ PCMK__alert_key_attribute_name
@ PCMK__alert_key_target_rc
@ PCMK__alert_key_timestamp_usec
@ PCMK__alert_key_kind
@ PCMK__alert_key_node_sequence
@ PCMK__alert_key_rsc
@ PCMK__alert_key_recipient
@ PCMK__alert_key_exec_time
@ PCMK__alert_key_version
@ PCMK__alert_key_desc
@ PCMK__alert_key_attribute_value
#define PCMK__ALERT_DEFAULT_TIMEOUT_MS
@ pcmk__alert_default
#define PCMK__ALERT_INTERNAL_KEY_MAX
const char * path
Definition cib.c:28
const char * name
Definition cib.c:26
#define pcmk__assert_alloc(nmemb, size)
Definition internal.h:297
A dumping ground.
#define crm_trace(fmt, args...)
Definition logging.h:402
Resource agent executor.
#define CRM_ASSERT(expr)
Definition results.h:42
GHashTable * pcmk__str_table_dup(GHashTable *old_table)
Definition strings.c:766
void pcmk__insert_dup(GHashTable *table, const char *name, const char *value)
Definition strings.c:701
#define pcmk__str_copy(str)
char ** select_attribute_name
GHashTable * envvars
Wrappers for and extensions to libxml2.