AT&T ECOMP Vendor Event Listener library  0.1
evel_fault.c
Go to the documentation of this file.
1 /**************************************************************************/
37 #include <string.h>
38 #include <assert.h>
39 #include <stdlib.h>
40 
41 #include "evel.h"
42 #include "evel_internal.h"
43 #include "evel_throttle.h"
44 
45 /**************************************************************************/
60 EVENT_FAULT * evel_new_fault(const char * const condition,
61  const char * const specific_problem,
62  EVEL_EVENT_PRIORITIES priority,
63  EVEL_SEVERITIES severity)
64 {
65  EVENT_FAULT * fault = NULL;
66  EVEL_ENTER();
67 
68  /***************************************************************************/
69  /* Check preconditions. */
70  /***************************************************************************/
71  assert(condition != NULL);
72  assert(specific_problem != NULL);
73  assert(priority < EVEL_MAX_PRIORITIES);
74  assert(severity < EVEL_MAX_SEVERITIES);
75 
76  /***************************************************************************/
77  /* Allocate the fault. */
78  /***************************************************************************/
79  fault = malloc(sizeof(EVENT_FAULT));
80  if (fault == NULL)
81  {
82  log_error_state("Out of memory");
83  goto exit_label;
84  }
85  memset(fault, 0, sizeof(EVENT_FAULT));
86  EVEL_DEBUG("New fault is at %lp", fault);
87 
88  /***************************************************************************/
89  /* Initialize the header & the fault fields. Optional string values are */
90  /* uninitialized (NULL). */
91  /***************************************************************************/
92  evel_init_header(&fault->header);
94  fault->header.priority = priority;
97  fault->event_severity = severity;
100  fault->alarm_condition = strdup(condition);
101  fault->specific_problem = strdup(specific_problem);
104 
105 exit_label:
106  EVEL_EXIT();
107  return fault;
108 }
109 
110 /**************************************************************************/
125 void evel_fault_addl_info_add(EVENT_FAULT * fault, char * name, char * value)
126 {
127  FAULT_ADDL_INFO * addl_info = NULL;
128  EVEL_ENTER();
129 
130  /***************************************************************************/
131  /* Check preconditions. */
132  /***************************************************************************/
133  assert(fault != NULL);
134  assert(fault->header.event_domain == EVEL_DOMAIN_FAULT);
135  assert(name != NULL);
136  assert(value != NULL);
137 
138  EVEL_DEBUG("Adding name=%s value=%s", name, value);
139  addl_info = malloc(sizeof(FAULT_ADDL_INFO));
140  assert(addl_info != NULL);
141  memset(addl_info, 0, sizeof(FAULT_ADDL_INFO));
142  addl_info->name = strdup(name);
143  addl_info->value = strdup(value);
144  assert(addl_info->name != NULL);
145  assert(addl_info->value != NULL);
146 
147  dlist_push_last(&fault->additional_info, addl_info);
148 
149  EVEL_EXIT();
150 }
151 
152 /**************************************************************************/
165  const char * const interface)
166 {
167  EVEL_ENTER();
168 
169  /***************************************************************************/
170  /* Check preconditions. */
171  /***************************************************************************/
172  assert(fault != NULL);
173  assert(fault->header.event_domain == EVEL_DOMAIN_FAULT);
174  assert(interface != NULL);
175 
177  interface,
178  "Alarm Interface A");
179  EVEL_EXIT();
180 }
181 
182 /**************************************************************************/
194 void evel_fault_type_set(EVENT_FAULT * fault, const char * const type)
195 {
196  EVEL_ENTER();
197 
198  /***************************************************************************/
199  /* Check preconditions and call evel_header_type_set. */
200  /***************************************************************************/
201  assert(fault != NULL);
202  assert(fault->header.event_domain == EVEL_DOMAIN_FAULT);
203  evel_header_type_set(&fault->header, type);
204 
205  EVEL_EXIT();
206 }
207 
208 /**************************************************************************/
215  EVENT_FAULT * event)
216 {
217  FAULT_ADDL_INFO * addl_info = NULL;
218  DLIST_ITEM * addl_info_item = NULL;
219  char * fault_severity;
220  char * fault_source_type;
221  char * fault_vf_status;
222 
223  EVEL_ENTER();
224 
225  /***************************************************************************/
226  /* Check preconditions. */
227  /***************************************************************************/
228  assert(event != NULL);
229  assert(event->header.event_domain == EVEL_DOMAIN_FAULT);
230 
231  fault_severity = evel_severity(event->event_severity);
232  fault_source_type = evel_source_type(event->event_source_type);
233  fault_vf_status = evel_vf_status(event->vf_status);
234 
235  evel_json_encode_header(jbuf, &event->header);
236  evel_json_open_named_object(jbuf, "faultFields");
237 
238  /***************************************************************************/
239  /* Mandatory fields. */
240  /***************************************************************************/
241  evel_enc_kv_string(jbuf, "alarmCondition", event->alarm_condition);
242  evel_enc_kv_string(jbuf, "eventSeverity", fault_severity);
243  evel_enc_kv_string(jbuf, "eventSourceType", fault_source_type);
244  evel_enc_kv_string(jbuf, "specificProblem", event->specific_problem);
245  evel_enc_kv_string(jbuf, "vfStatus", fault_vf_status);
247  jbuf, "faultFieldsVersion", event->major_version, event->minor_version);
248 
249  /***************************************************************************/
250  /* Optional fields. */
251  /***************************************************************************/
252 
253  /***************************************************************************/
254  /* Checkpoint, so that we can wind back if all fields are suppressed. */
255  /***************************************************************************/
256  evel_json_checkpoint(jbuf);
257  if (evel_json_open_opt_named_list(jbuf, "alarmAdditionalInformation"))
258  {
259  bool item_added = false;
260 
261  addl_info_item = dlist_get_first(&event->additional_info);
262  while (addl_info_item != NULL)
263  {
264  addl_info = (FAULT_ADDL_INFO*) addl_info_item->item;
265  assert(addl_info != NULL);
266 
268  "alarmAdditionalInformation",
269  addl_info->name))
270  {
271  evel_json_open_object(jbuf);
272  evel_enc_kv_string(jbuf, "name", addl_info->name);
273  evel_enc_kv_string(jbuf, "value", addl_info->value);
275  item_added = true;
276  }
277  addl_info_item = dlist_get_next(addl_info_item);
278  }
279  evel_json_close_list(jbuf);
280 
281  /*************************************************************************/
282  /* If we've not written anything, rewind to before we opened the list. */
283  /*************************************************************************/
284  if (!item_added)
285  {
286  evel_json_rewind(jbuf);
287  }
288  }
289  evel_enc_kv_opt_string(jbuf, "alarmInterfaceA", &event->alarm_interface_a);
290 
292 
293  EVEL_EXIT();
294 }
295 
296 /**************************************************************************/
305 {
306  FAULT_ADDL_INFO * addl_info = NULL;
307 
308  EVEL_ENTER();
309 
310  /***************************************************************************/
311  /* Check preconditions. As an internal API we don't allow freeing NULL */
312  /* events as we do on the public API. */
313  /***************************************************************************/
314  assert(event != NULL);
315  assert(event->header.event_domain == EVEL_DOMAIN_FAULT);
316 
317  /***************************************************************************/
318  /* Free all internal strings then the header itself. */
319  /***************************************************************************/
320  addl_info = dlist_pop_last(&event->additional_info);
321  while (addl_info != NULL)
322  {
323  EVEL_DEBUG("Freeing Additional Info (%s, %s)",
324  addl_info->name,
325  addl_info->value);
326  free(addl_info->name);
327  free(addl_info->value);
328  free(addl_info);
329  addl_info = dlist_pop_last(&event->additional_info);
330  }
331  free(event->alarm_condition);
333  free(event->specific_problem);
334  evel_free_header(&event->header);
335 
336  EVEL_EXIT();
337 }
EVEL_SOURCE_TYPES event_source_type
Definition: evel.h:461
void evel_set_option_string(EVEL_OPTION_STRING *const option, const char *const value, const char *const description)
Set the value of an EVEL_OPTION_STRING.
Definition: evel_option.c:94
#define EVEL_DEBUG(FMT,...)
Definition: evel.h:3621
#define EVEL_FAULT_MAJOR_VERSION
Definition: evel.h:442
char * alarm_condition
Definition: evel.h:462
DLIST_ITEM * dlist_get_first(DLIST *list)
Definition: double_list.c:162
EVEL_SOURCE_TYPES event_source_type
The type of equipment represented by this VNF.
Definition: evel.c:58
void dlist_initialize(DLIST *list)
List initialization.
Definition: double_list.c:55
void evel_fault_interface_set(EVENT_FAULT *fault, const char *const interface)
Set the Alarm Interface A property of the Fault.
Definition: evel_fault.c:164
char * specific_problem
Definition: evel.h:463
void * item
Definition: double_list.h:47
EVEL_THROTTLE_SPEC * throttle_spec
void evel_free_fault(EVENT_FAULT *event)
Free a Fault.
Definition: evel_fault.c:304
#define EVEL_EXIT()
Definition: evel.h:3631
void evel_json_encode_fault(EVEL_JSON_BUFFER *jbuf, EVENT_FAULT *event)
Encode the fault in JSON according to AT&T&#39;s schema for the fault type.
Definition: evel_fault.c:214
void evel_json_close_list(EVEL_JSON_BUFFER *jbuf)
Add the closing bracket of a list to a JSON buffer.
void evel_init_option_string(EVEL_OPTION_STRING *const option)
Initialize an EVEL_OPTION_STRING to a not-set state.
Definition: evel_option.c:72
#define EVEL_ENTER()
Definition: evel.h:3626
Header for EVEL library.
char * evel_source_type(const EVEL_SOURCE_TYPES source_type)
Map an EVEL_SOURCE_TYPES enum value to the equivalent string.
Definition: evel_strings.c:305
void evel_enc_kv_string(EVEL_JSON_BUFFER *jbuf, const char *const key, const char *const value)
Encode a string key and string value to a EVEL_JSON_BUFFER.
char * evel_vf_status(const EVEL_VF_STATUSES vf_status)
Map an EVEL_VF_STATUSES enum value to the equivalent string.
Definition: evel_strings.c:370
void evel_json_close_object(EVEL_JSON_BUFFER *jbuf)
Add the closing bracket of an object to a JSON buffer.
#define EVEL_FAULT_MINOR_VERSION
Definition: evel.h:443
int minor_version
Definition: evel.h:455
int major_version
Definition: evel.h:454
void evel_fault_addl_info_add(EVENT_FAULT *fault, char *name, char *value)
Add an additional value name/value pair to the Fault.
Definition: evel_fault.c:125
void evel_json_open_named_object(EVEL_JSON_BUFFER *jbuf, const char *const key)
Add the opening bracket of an object to a JSON buffer.
void evel_json_open_object(EVEL_JSON_BUFFER *jbuf)
Add the opening bracket of an object to a JSON buffer.
void evel_json_checkpoint(EVEL_JSON_BUFFER *jbuf)
Add a checkpoint - a stake in the ground to which we can rewind.
EVEL_EVENT_DOMAINS event_domain
Definition: evel.h:420
void evel_json_encode_header(EVEL_JSON_BUFFER *jbuf, EVENT_HEADER *event)
Encode the event as a JSON event object according to AT&T&#39;s schema.
Definition: evel_event.c:291
EVENT_HEADER header
Definition: evel.h:453
EVEL_SEVERITIES
Fault / Threshold severities.
Definition: evel.h:161
void evel_free_header(EVENT_HEADER *const event)
Free an event header.
Definition: evel_event.c:349
void * dlist_pop_last(DLIST *list)
Definition: double_list.c:73
void dlist_push_last(DLIST *list, void *item)
Definition: double_list.c:132
A Heartbeat event (event header only).
Definition: evel.h:133
bool evel_json_open_opt_named_list(EVEL_JSON_BUFFER *jbuf, const char *const key)
Add the key and opening bracket of an optional named list to a JSON buffer.
void log_error_state(char *format,...)
Definition: evel_logging.c:98
void evel_free_option_string(EVEL_OPTION_STRING *const option)
Free the underlying resources of an EVEL_OPTION_STRING.
Definition: evel_option.c:48
bool evel_enc_kv_opt_string(EVEL_JSON_BUFFER *jbuf, const char *const key, const EVEL_OPTION_STRING *const option)
Encode a string key and string value to a EVEL_JSON_BUFFER.
DLIST_ITEM * dlist_get_next(DLIST_ITEM *item)
Definition: double_list.c:172
void evel_fault_type_set(EVENT_FAULT *fault, const char *const type)
Set the Event Type property of the Fault.
Definition: evel_fault.c:194
EVEL_EVENT_PRIORITIES priority
Definition: evel.h:425
void evel_json_rewind(EVEL_JSON_BUFFER *jbuf)
Rewind to the latest checkoint.
void evel_header_type_set(EVENT_HEADER *const header, const char *const type)
Set the Event Type property of the event header.
Definition: evel_event.c:164
EVEL throttle definitions.
Fault Additional Info.
Definition: evel.h:478
EVEL_EVENT_PRIORITIES
Event priorities.
Definition: evel.h:149
EVEL internal definitions.
void evel_enc_version(EVEL_JSON_BUFFER *jbuf, const char *const key, const int major_version, const int minor_version)
Encode a key and version.
void evel_init_header(EVENT_HEADER *const header)
Initialize a newly created event header.
Definition: evel_event.c:112
EVENT_FAULT * evel_new_fault(const char *const condition, const char *const specific_problem, EVEL_EVENT_PRIORITIES priority, EVEL_SEVERITIES severity)
Create a new fault event.
Definition: evel_fault.c:60
bool evel_throttle_suppress_nv_pair(EVEL_THROTTLE_SPEC *throttle_spec, const char *const field_name, const char *const name)
Determine whether a name-value pair should be allowed (not suppressed).
EVEL_OPTION_STRING alarm_interface_a
Definition: evel.h:469
char * evel_severity(const EVEL_SEVERITIES severity)
Map an EVEL_SEVERITIES enum value to the equivalent string.
Definition: evel_strings.c:79
EVEL_SEVERITIES event_severity
Definition: evel.h:460
DLIST additional_info
Definition: evel.h:470
Fault.
Definition: evel.h:449
EVEL_VF_STATUSES vf_status
Definition: evel.h:464