Add ringbuffer size to API
[demo.git] / vnfs / VES5.0 / evel / evel-library / code / evel_library / evel_event.c
1 /*************************************************************************//**
2  *
3  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
4  *
5  * Unless otherwise specified, all software contained herein is
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and 
15  * limitations under the License.
16  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
17  ****************************************************************************/
18
19 /**************************************************************************//**
20  * @file
21  * Implementation of EVEL functions relating to Event Headers - since
22  * Heartbeats only contain the Event Header, the Heartbeat factory function is
23  * here too.
24  *****************************************************************************/
25
26 #include <string.h>
27 #include <assert.h>
28 #include <stdlib.h>
29 #include <sys/time.h>
30
31 #include "evel.h"
32 #include "evel_internal.h"
33 #include "evel_throttle.h"
34 #include "metadata.h"
35
36 /**************************************************************************//**
37  * Unique sequence number for events from this VNF.
38  *****************************************************************************/
39 static int event_sequence = 1;
40
41 /**************************************************************************//**
42  * Set the next event_sequence to use.
43  *
44  * @param sequence      The next sequence number to use.
45  *****************************************************************************/
46 void evel_set_next_event_sequence(const int sequence)
47 {
48   EVEL_ENTER();
49
50   EVEL_INFO("Setting event sequence to %d, was %d ", sequence, event_sequence);
51   event_sequence = sequence;
52
53   EVEL_EXIT();
54 }
55
56
57 /**************************************************************************//**
58  * Create a new heartbeat event of given name and type.
59  *
60  * @note that the heartbeat is just a "naked" commonEventHeader!
61  *
62  * @param event_name    Unique Event Name: in format
63  * {DomainAbbreviation}_{AsdcModel or ApplicationPlatform}_{DescriptionOfInfoBeingConveyed}
64  * @param event_id     Uniquely identify event for correlation and analysis
65  *
66  * @returns pointer to the newly manufactured ::EVENT_HEADER.  If the event is
67  *          not used it must be released using ::evel_free_event
68  * @retval  NULL  Failed to create the event.
69  *****************************************************************************/
70 EVENT_HEADER * evel_new_heartbeat_nameid(const char* ev_name, const char *ev_id)
71 {
72   EVENT_HEADER * heartbeat = NULL;
73   EVEL_ENTER();
74
75   assert(ev_name != NULL);
76   assert(ev_id != NULL);
77
78   /***************************************************************************/
79   /* Allocate the header.                                                    */
80   /***************************************************************************/
81   heartbeat = malloc(sizeof(EVENT_HEADER));
82   if (heartbeat == NULL)
83   {
84     log_error_state("Out of memory");
85     goto exit_label;
86   }
87   memset(heartbeat, 0, sizeof(EVENT_HEADER));
88
89   /***************************************************************************/
90   /* Initialize the header.  Get a new event sequence number.  Note that if  */
91   /* any memory allocation fails in here we will fail gracefully because     */
92   /* everything downstream can cope with NULLs.                              */
93   /***************************************************************************/
94   evel_init_header_nameid(heartbeat,ev_name,ev_id);
95
96 exit_label:
97   EVEL_EXIT();
98   return heartbeat;
99 }
100
101 /**************************************************************************//**
102  * Create a new heartbeat event.
103  *
104  * @note that the heartbeat is just a "naked" commonEventHeader!
105  *
106  * @returns pointer to the newly manufactured ::EVENT_HEADER.  If the event is
107  *          not used it must be released using ::evel_free_event
108  * @retval  NULL  Failed to create the event.
109  *****************************************************************************/
110 EVENT_HEADER * evel_new_heartbeat()
111 {
112   EVENT_HEADER * heartbeat = NULL;
113   EVEL_ENTER();
114
115   /***************************************************************************/
116   /* Allocate the header.                                                    */
117   /***************************************************************************/
118   heartbeat = malloc(sizeof(EVENT_HEADER));
119   if (heartbeat == NULL)
120   {
121     log_error_state("Out of memory");
122     goto exit_label;
123   }
124   memset(heartbeat, 0, sizeof(EVENT_HEADER));
125
126   /***************************************************************************/
127   /* Initialize the header.  Get a new event sequence number.  Note that if  */
128   /* any memory allocation fails in here we will fail gracefully because     */
129   /* everything downstream can cope with NULLs.                              */
130   /***************************************************************************/
131   evel_init_header(heartbeat,"Heartbeat");
132   evel_force_option_string(&heartbeat->event_type, "Autonomous heartbeat");
133
134 exit_label:
135   EVEL_EXIT();
136   return heartbeat;
137 }
138
139 /**************************************************************************//**
140  * Initialize a newly created event header.
141  *
142  * @param header  Pointer to the header being initialized.
143  *****************************************************************************/
144 void evel_init_header(EVENT_HEADER * const header,const char *const eventname)
145 {
146   char scratchpad[EVEL_MAX_STRING_LEN + 1] = {0};
147   struct timeval tv;
148
149   EVEL_ENTER();
150
151   assert(header != NULL);
152
153   gettimeofday(&tv, NULL);
154
155   /***************************************************************************/
156   /* Initialize the header.  Get a new event sequence number.  Note that if  */
157   /* any memory allocation fails in here we will fail gracefully because     */
158   /* everything downstream can cope with NULLs.                              */
159   /***************************************************************************/
160   header->event_domain = EVEL_DOMAIN_HEARTBEAT;
161   snprintf(scratchpad, EVEL_MAX_STRING_LEN, "%d", event_sequence);
162   header->event_id = strdup(scratchpad);
163   if( eventname == NULL )
164      header->event_name = strdup(functional_role);
165   else
166      header->event_name = strdup(eventname);
167   header->last_epoch_microsec = tv.tv_usec + 1000000 * tv.tv_sec;
168   header->priority = EVEL_PRIORITY_NORMAL;
169   header->reporting_entity_name = strdup(openstack_vm_name());
170   header->source_name = strdup(openstack_vm_name());
171   header->sequence = event_sequence;
172   header->start_epoch_microsec = header->last_epoch_microsec;
173   header->major_version = EVEL_HEADER_MAJOR_VERSION;
174   header->minor_version = EVEL_HEADER_MINOR_VERSION;
175   event_sequence++;
176
177   /***************************************************************************/
178   /* Optional parameters.                                                    */
179   /***************************************************************************/
180   evel_init_option_string(&header->event_type);
181   evel_init_option_string(&header->nfcnaming_code);
182   evel_init_option_string(&header->nfnaming_code);
183   evel_force_option_string(&header->reporting_entity_id, openstack_vm_uuid());
184   evel_force_option_string(&header->source_id, openstack_vm_uuid());
185   evel_init_option_intheader(&header->internal_field);
186   dlist_initialize(&header->batch_events);
187
188   EVEL_EXIT();
189 }
190
191
192 /**************************************************************************//**
193  * Initialize a newly created event header.
194  *
195  * @param header  Pointer to the header being initialized.
196  * @param eventname Eventname string
197  * @param eventid   Event id : unique id for classification and analysis
198  * @param header  Pointer to the header being initialized.
199  *****************************************************************************/
200 void evel_init_header_nameid(EVENT_HEADER * const header,const char *const eventname, const char *eventid)
201 {
202   struct timeval tv;
203
204   EVEL_ENTER();
205
206   assert(header != NULL);
207   assert(eventname != NULL);
208   assert(eventid != NULL);
209
210   gettimeofday(&tv, NULL);
211
212   /***************************************************************************/
213   /* Initialize the header.  Get a new event sequence number.  Note that if  */
214   /* any memory allocation fails in here we will fail gracefully because     */
215   /* everything downstream can cope with NULLs.                              */
216   /***************************************************************************/
217   header->event_domain = EVEL_DOMAIN_HEARTBEAT;
218   header->event_id = strdup(eventid);
219   header->event_name = strdup(eventname);
220   header->last_epoch_microsec = tv.tv_usec + 1000000 * tv.tv_sec;
221   header->priority = EVEL_PRIORITY_NORMAL;
222   header->reporting_entity_name = strdup(openstack_vm_name());
223   header->source_name = strdup(openstack_vm_name());
224   header->sequence = event_sequence;
225   header->start_epoch_microsec = header->last_epoch_microsec;
226   header->major_version = EVEL_HEADER_MAJOR_VERSION;
227   header->minor_version = EVEL_HEADER_MINOR_VERSION;
228   event_sequence++;
229
230   /***************************************************************************/
231   /* Optional parameters.                                                    */
232   /***************************************************************************/
233   evel_init_option_string(&header->event_type);
234   evel_init_option_string(&header->nfcnaming_code);
235   evel_init_option_string(&header->nfnaming_code);
236   evel_force_option_string(&header->reporting_entity_id, openstack_vm_uuid());
237   evel_force_option_string(&header->source_id, openstack_vm_uuid());
238   evel_init_option_intheader(&header->internal_field);
239   dlist_initialize(&header->batch_events);
240
241   EVEL_EXIT();
242 }
243
244 /**************************************************************************//**
245  * Set the Event Type property of the event header.
246  *
247  * @note  The property is treated as immutable: it is only valid to call
248  *        the setter once.  However, we don't assert if the caller tries to
249  *        overwrite, just ignoring the update instead.
250  *
251  * @param header        Pointer to the ::EVENT_HEADER.
252  * @param type          The Event Type to be set. ASCIIZ string. The caller
253  *                      does not need to preserve the value once the function
254  *                      returns.
255  *****************************************************************************/
256 void evel_header_type_set(EVENT_HEADER * const header,
257                           const char * const type)
258 {
259   EVEL_ENTER();
260
261   /***************************************************************************/
262   /* Check preconditions.                                                    */
263   /***************************************************************************/
264   assert(header != NULL);
265   assert(type != NULL);
266
267   evel_set_option_string(&header->event_type, type, "Event Type");
268
269   EVEL_EXIT();
270 }
271
272 /**************************************************************************//**
273  * Set the Start Epoch property of the event header.
274  *
275  * @note The Start Epoch defaults to the time of event creation.
276  *
277  * @param header        Pointer to the ::EVENT_HEADER.
278  * @param start_epoch_microsec
279  *                      The start epoch to set, in microseconds.
280  *****************************************************************************/
281 void evel_start_epoch_set(EVENT_HEADER * const header,
282                           const unsigned long long start_epoch_microsec)
283 {
284   EVEL_ENTER();
285
286   /***************************************************************************/
287   /* Check preconditions and assign the new value.                           */
288   /***************************************************************************/
289   assert(header != NULL);
290   header->start_epoch_microsec = start_epoch_microsec;
291
292   EVEL_EXIT();
293 }
294
295 /**************************************************************************//**
296  * Set the Last Epoch property of the event header.
297  *
298  * @note The Last Epoch defaults to the time of event creation.
299  *
300  * @param header        Pointer to the ::EVENT_HEADER.
301  * @param last_epoch_microsec
302  *                      The last epoch to set, in microseconds.
303  *****************************************************************************/
304 void evel_last_epoch_set(EVENT_HEADER * const header,
305                          const unsigned long long last_epoch_microsec)
306 {
307   EVEL_ENTER();
308
309   /***************************************************************************/
310   /* Check preconditions and assign the new value.                           */
311   /***************************************************************************/
312   assert(header != NULL);
313   header->last_epoch_microsec = last_epoch_microsec;
314
315   EVEL_EXIT();
316 }
317
318 /**************************************************************************//**
319  * Set the NFC Naming code property of the event header.
320  *
321  * @param header        Pointer to the ::EVENT_HEADER.
322  * @param nfcnamingcode String
323  *****************************************************************************/
324 void evel_nfcnamingcode_set(EVENT_HEADER * const header,
325                          const char * const nfcnam)
326 {
327   EVEL_ENTER();
328
329   /***************************************************************************/
330   /* Check preconditions and assign the new value.                           */
331   /***************************************************************************/
332   assert(header != NULL);
333   assert(nfcnam != NULL);
334   evel_set_option_string(&header->nfcnaming_code, nfcnam, "NFC Naming Code");
335
336   EVEL_EXIT();
337 }
338
339 /**************************************************************************//**
340  * Set the NF Naming code property of the event header.
341  *
342  * @param header        Pointer to the ::EVENT_HEADER.
343  * @param nfnamingcode String
344  *****************************************************************************/
345 void evel_nfnamingcode_set(EVENT_HEADER * const header,
346                          const char * const nfnam)
347 {
348   EVEL_ENTER();
349
350   /***************************************************************************/
351   /* Check preconditions and assign the new value.                           */
352   /***************************************************************************/
353   assert(header != NULL);
354   assert(nfnam != NULL);
355   evel_set_option_string(&header->nfnaming_code, nfnam, "NF Naming Code");
356
357   EVEL_EXIT();
358 }
359
360
361 /**************************************************************************//**
362  * Set the Reporting Entity Name property of the event header.
363  *
364  * @note The Reporting Entity Name defaults to the OpenStack VM Name.
365  *
366  * @param header        Pointer to the ::EVENT_HEADER.
367  * @param entity_name   The entity name to set.
368  *****************************************************************************/
369 void evel_reporting_entity_name_set(EVENT_HEADER * const header,
370                                     const char * const entity_name)
371 {
372   EVEL_ENTER();
373
374   /***************************************************************************/
375   /* Check preconditions and assign the new value.                           */
376   /***************************************************************************/
377   assert(header != NULL);
378   assert(entity_name != NULL);
379   assert(header->reporting_entity_name != NULL);
380
381   /***************************************************************************/
382   /* Free the previously allocated memory and replace it with a copy of the  */
383   /* provided one.                                                           */
384   /***************************************************************************/
385   free(header->reporting_entity_name);
386   header->reporting_entity_name = strdup(entity_name);
387
388   EVEL_EXIT();
389 }
390
391 /**************************************************************************//**
392  * Set the Reporting Entity Id property of the event header.
393  *
394  * @note The Reporting Entity Id defaults to the OpenStack VM UUID.
395  *
396  * @param header        Pointer to the ::EVENT_HEADER.
397  * @param entity_id     The entity id to set.
398  *****************************************************************************/
399 void evel_reporting_entity_id_set(EVENT_HEADER * const header,
400                                   const char * const entity_id)
401 {
402   EVEL_ENTER();
403
404   /***************************************************************************/
405   /* Check preconditions and assign the new value.                           */
406   /***************************************************************************/
407   assert(header != NULL);
408   assert(entity_id != NULL);
409
410   /***************************************************************************/
411   /* Free the previously allocated memory and replace it with a copy of the  */
412   /* provided one.  Note that evel_force_option_string strdups entity_id.    */
413   /***************************************************************************/
414   evel_free_option_string(&header->reporting_entity_id);
415   evel_force_option_string(&header->reporting_entity_id, entity_id);
416
417   EVEL_EXIT();
418 }
419
420 /**************************************************************************//**
421  * Encode the event as a JSON event object according to AT&T's schema.
422  *
423  * @param jbuf          Pointer to the ::EVEL_JSON_BUFFER to encode into.
424  * @param event         Pointer to the ::EVENT_HEADER to encode.
425  *****************************************************************************/
426 void evel_json_encode_header(EVEL_JSON_BUFFER * jbuf,
427                              EVENT_HEADER * event)
428 {
429   char * domain;
430   char * priority;
431
432   EVEL_ENTER();
433
434   /***************************************************************************/
435   /* Check preconditions.                                                    */
436   /***************************************************************************/
437   assert(jbuf != NULL);
438   assert(jbuf->json != NULL);
439   assert(jbuf->max_size > 0);
440   assert(event != NULL);
441
442   domain = evel_event_domain(event->event_domain);
443   priority = evel_event_priority(event->priority);
444   evel_json_open_named_object(jbuf, "commonEventHeader");
445
446   /***************************************************************************/
447   /* Mandatory fields.                                                       */
448   /***************************************************************************/
449   evel_enc_kv_string(jbuf, "domain", domain);
450   evel_enc_kv_string(jbuf, "eventId", event->event_id);
451   evel_enc_kv_string(jbuf, "eventName", event->event_name);
452   evel_enc_kv_ull(jbuf, "lastEpochMicrosec", event->last_epoch_microsec);
453   evel_enc_kv_string(jbuf, "priority", priority);
454   evel_enc_kv_string(
455     jbuf, "reportingEntityName", event->reporting_entity_name);
456   evel_enc_kv_int(jbuf, "sequence", event->sequence);
457   evel_enc_kv_string(jbuf, "sourceName", event->source_name);
458   evel_enc_kv_ull(jbuf, "startEpochMicrosec", event->start_epoch_microsec);
459   evel_enc_version(
460     jbuf, "version", event->major_version, event->minor_version);
461
462   /***************************************************************************/
463   /* Optional fields.                                                        */
464   /***************************************************************************/
465   evel_enc_kv_opt_string(jbuf, "eventType", &event->event_type);
466   evel_enc_kv_opt_string(
467     jbuf, "reportingEntityId", &event->reporting_entity_id);
468   evel_enc_kv_opt_string(jbuf, "sourceId", &event->source_id);
469   evel_enc_kv_opt_string(jbuf, "nfcNamingCode", &event->nfcnaming_code);
470   evel_enc_kv_opt_string(jbuf, "nfNamingCode", &event->nfnaming_code);
471
472   evel_json_close_object(jbuf);
473
474   EVEL_EXIT();
475 }
476
477 /**************************************************************************//**
478  * Free an event header.
479  *
480  * Free off the event header supplied.  Will free all the contained allocated
481  * memory.
482  *
483  * @note It does not free the header itself, since that may be part of a
484  * larger structure.
485  *****************************************************************************/
486 void evel_free_header(EVENT_HEADER * const event)
487 {
488   EVEL_ENTER();
489
490   /***************************************************************************/
491   /* Check preconditions.  As an internal API we don't allow freeing NULL    */
492   /* events as we do on the public API.                                      */
493   /***************************************************************************/
494   assert(event != NULL);
495
496   /***************************************************************************/
497   /* Free all internal strings.                                              */
498   /***************************************************************************/
499   free(event->event_id);
500   evel_free_option_string(&event->event_type);
501   free(event->event_name);
502   evel_free_option_string(&event->reporting_entity_id);
503   free(event->reporting_entity_name);
504   evel_free_option_string(&event->source_id);
505   evel_free_option_string(&event->nfcnaming_code);
506   evel_free_option_string(&event->nfnaming_code);
507   evel_free_option_intheader(&event->internal_field);
508   free(event->source_name);
509
510   EVEL_EXIT();
511 }
512
513
514 /**************************************************************************//**
515  * Encode the event as a JSON event object according to AT&T's schema.
516  *
517  * @param json      Pointer to where to store the JSON encoded data.
518  * @param max_size  Size of storage available in json_body.
519  * @param event     Pointer to the ::EVENT_HEADER to encode.
520  * @returns Number of bytes actually written.
521  *****************************************************************************/
522 void evel_json_encode_eventtype(
523                            EVEL_JSON_BUFFER * jbuf,
524                            EVENT_HEADER * event)
525 {
526       switch (event->event_domain)
527       {
528         case EVEL_DOMAIN_HEARTBEAT:
529           evel_json_encode_header(jbuf, event);
530           break;
531
532         case EVEL_DOMAIN_FAULT:
533           evel_json_encode_fault(jbuf, (EVENT_FAULT *)event);
534           break;
535
536         case EVEL_DOMAIN_MEASUREMENT:
537           evel_json_encode_measurement(jbuf, (EVENT_MEASUREMENT *)event);
538           break;
539
540         case EVEL_DOMAIN_MOBILE_FLOW:
541           evel_json_encode_mobile_flow(jbuf, (EVENT_MOBILE_FLOW *)event);
542           break;
543
544         case EVEL_DOMAIN_REPORT:
545           evel_json_encode_report(jbuf, (EVENT_REPORT *)event);
546           break;
547
548         case EVEL_DOMAIN_HEARTBEAT_FIELD:
549           evel_json_encode_hrtbt_field(jbuf, (EVENT_HEARTBEAT_FIELD *)event);
550           break;
551
552         case EVEL_DOMAIN_SIPSIGNALING:
553           evel_json_encode_signaling(jbuf, (EVENT_SIGNALING *)event);
554           break;
555
556         case EVEL_DOMAIN_STATE_CHANGE:
557           evel_json_encode_state_change(jbuf, (EVENT_STATE_CHANGE *)event);
558           break;
559
560         case EVEL_DOMAIN_SYSLOG:
561           evel_json_encode_syslog(jbuf, (EVENT_SYSLOG *)event);
562           break;
563
564         case EVEL_DOMAIN_OTHER:
565           evel_json_encode_other(jbuf, (EVENT_OTHER *)event);
566           break;
567
568         case EVEL_DOMAIN_VOICE_QUALITY:
569           evel_json_encode_voice_quality(jbuf, (EVENT_VOICE_QUALITY *)event);
570           break;
571
572         case EVEL_DOMAIN_THRESHOLD_CROSS:
573           evel_json_encode_threshold_cross(jbuf, (EVENT_THRESHOLD_CROSS *)event);
574           break;
575
576         case EVEL_DOMAIN_INTERNAL:
577         default:
578           EVEL_ERROR("Unexpected domain %d", event->event_domain);
579           assert(0);
580       }
581 }
582
583
584
585 /**************************************************************************//**
586  * Encode the event as a JSON event object according to AT&T's schema.
587  *
588  * @param json      Pointer to where to store the JSON encoded data.
589  * @param max_size  Size of storage available in json_body.
590  * @param event     Pointer to the ::EVENT_HEADER to encode.
591  * @returns Number of bytes actually written.
592  *****************************************************************************/
593 int evel_json_encode_event(char * json,
594                            int max_size,
595                            EVENT_HEADER * event)
596 {
597   EVEL_JSON_BUFFER json_buffer;
598   EVEL_JSON_BUFFER * jbuf = &json_buffer;
599   EVEL_THROTTLE_SPEC * throttle_spec;
600
601   EVEL_ENTER();
602
603   /***************************************************************************/
604   /* Get the latest throttle specification for the domain.                   */
605   /***************************************************************************/
606   throttle_spec = evel_get_throttle_spec(event->event_domain);
607
608   /***************************************************************************/
609   /* Initialize the JSON_BUFFER and open the top-level objects.              */
610   /***************************************************************************/
611   evel_json_buffer_init(jbuf, json, max_size, throttle_spec);
612   evel_json_open_object(jbuf);
613   evel_json_open_named_object(jbuf, "event");
614
615   evel_json_encode_eventtype(jbuf, event);
616
617   evel_json_close_object(jbuf);
618   evel_json_close_object(jbuf);
619
620   /***************************************************************************/
621   /* Sanity check.                                                           */
622   /***************************************************************************/
623   assert(jbuf->depth == 0);
624   if( jbuf->offset >= max_size ){
625           EVEL_ERROR("Event exceeded size limit %d", max_size);
626           assert(0);
627   }
628
629   EVEL_EXIT();
630
631   return jbuf->offset;
632 }
633 /**************************************************************************//**
634  * Encode the event as a JSON event object according to AT&T's schema.
635  *
636  * @param json      Pointer to where to store the JSON encoded data.
637  * @param max_size  Size of storage available in json_body.
638  * @param event     Pointer to the ::EVENT_HEADER to encode.
639  * @returns Number of bytes actually written.
640  *****************************************************************************/
641 int evel_json_encode_batch_event(char * json,
642                            int max_size,
643                            EVENT_HEADER * event)
644 {
645   EVEL_JSON_BUFFER json_buffer;
646   EVEL_JSON_BUFFER *jbuf = &json_buffer;
647   EVEL_THROTTLE_SPEC * throttle_spec;
648   int tot_size = 0;
649   EVENT_HEADER * batch_field = NULL;
650   DLIST_ITEM * batch_field_item = NULL;
651
652   EVEL_ENTER();
653
654   /***************************************************************************/
655   /* Get the latest throttle specification for the domain.                   */
656   /***************************************************************************/
657   throttle_spec = evel_get_throttle_spec(event->event_domain);
658
659   /***************************************************************************/
660   /* Initialize the JSON_BUFFER and open the top-level objects.              */
661   /***************************************************************************/
662   if (event->event_domain == EVEL_DOMAIN_BATCH){
663       evel_json_buffer_init(jbuf, json, max_size, throttle_spec);
664
665   if(dlist_count(&event->batch_events) > 0)
666   {
667     evel_json_open_object(jbuf);
668     evel_json_open_named_list(jbuf, "eventList");
669     batch_field_item = dlist_get_first(&event->batch_events);
670     while (batch_field_item != NULL)
671     {
672      batch_field = (EVENT_HEADER *) batch_field_item->item;
673      if(batch_field != NULL){
674        EVEL_DEBUG("Batch Event %p %p added curr fsize %d offset %d depth %d check %d", batch_field_item->item, batch_field, tot_size,jbuf->offset,jbuf->depth,jbuf->checkpoint);
675        evel_json_open_object(jbuf);
676        evel_json_encode_eventtype(jbuf, batch_field);
677        evel_json_close_object(jbuf);
678
679        tot_size += jbuf->offset;
680        EVEL_DEBUG("Batch Event result size %d offset %d depth %d check %d", tot_size,jbuf->offset,jbuf->depth,jbuf->checkpoint);
681        if( tot_size >= max_size ){
682           EVEL_ERROR("Batch Event exceeded size limit %d", tot_size);
683           assert(0);
684        }
685        batch_field_item = dlist_get_next(batch_field_item);
686      }
687     }
688     evel_json_close_list(jbuf);
689     evel_json_close_object(jbuf);
690   }
691
692   }
693   /***************************************************************************/
694   /* Sanity check.                                                           */
695   /***************************************************************************/
696   //assert(jbuf->depth == 0);
697
698   EVEL_EXIT();
699
700   return jbuf->offset;
701 }
702
703
704 /**************************************************************************//**
705  * Initialize an event instance id.
706  *
707  * @param vfield        Pointer to the event vnfname field being initialized.
708  * @param vendor_id     The vendor id to encode in the event instance id.
709  * @param event_id      The event id to encode in the event instance id.
710  *****************************************************************************/
711 void evel_init_vendor_field(VENDOR_VNFNAME_FIELD * const vfield,
712                                  const char * const vendor_name)
713 {
714   EVEL_ENTER();
715
716   /***************************************************************************/
717   /* Check preconditions.                                                    */
718   /***************************************************************************/
719   assert(vfield != NULL);
720   assert(vendor_name != NULL);
721
722   /***************************************************************************/
723   /* Store the mandatory parts.                                              */
724   /***************************************************************************/
725   vfield->vendorname = strdup(vendor_name);
726   evel_init_option_string(&vfield->vfmodule);
727   evel_init_option_string(&vfield->vnfname);
728
729   /***************************************************************************/
730   /* Initialize the optional parts.                                          */
731   /***************************************************************************/
732
733   EVEL_EXIT();
734 }
735
736 /**************************************************************************//**
737  * Set the Vendor module property of the Vendor.
738  *
739  * @note  The property is treated as immutable: it is only valid to call
740  *        the setter once.  However, we don't assert if the caller tries to
741  *        overwrite, just ignoring the update instead.
742  *
743  * @param vfield        Pointer to the Vendor field.
744  * @param module_name   The module name to be set. ASCIIZ string. The caller
745  *                      does not need to preserve the value once the function
746  *                      returns.
747  *****************************************************************************/
748 void evel_vendor_field_module_set(VENDOR_VNFNAME_FIELD * const vfield,
749                                     const char * const module_name)
750 {
751   EVEL_ENTER();
752
753   /***************************************************************************/
754   /* Check preconditions.                                                    */
755   /***************************************************************************/
756   assert(vfield != NULL);
757   assert(module_name != NULL);
758
759   evel_set_option_string(&vfield->vfmodule, module_name, "Module name set");
760
761   EVEL_EXIT();
762 }
763
764 /**************************************************************************//**
765  * Set the Vendor module property of the Vendor.
766  *
767  * @note  The property is treated as immutable: it is only valid to call
768  *        the setter once.  However, we don't assert if the caller tries to
769  *        overwrite, just ignoring the update instead.
770  *
771  * @param vfield        Pointer to the Vendor field.
772  * @param module_name   The module name to be set. ASCIIZ string. The caller
773  *                      does not need to preserve the value once the function
774  *                      returns.
775  *****************************************************************************/
776 void evel_vendor_field_vnfname_set(VENDOR_VNFNAME_FIELD * const vfield,
777                                     const char * const vnfname)
778 {
779   EVEL_ENTER();
780
781   /***************************************************************************/
782   /* Check preconditions.                                                    */
783   /***************************************************************************/
784   assert(vfield != NULL);
785   assert(vnfname != NULL);
786
787   evel_set_option_string(&vfield->vnfname, vnfname, "Virtual Network Function name set");
788
789   EVEL_EXIT();
790 }
791
792 /**************************************************************************//**
793  * Free an event instance id.
794  *
795  * @param vfield   Pointer to the event vnfname_field being freed.
796  *****************************************************************************/
797 void evel_free_event_vendor_field(VENDOR_VNFNAME_FIELD * const vfield)
798 {
799   EVEL_ENTER();
800
801   /***************************************************************************/
802   /* Check preconditions.                                                    */
803   /***************************************************************************/
804   assert(vfield->vendorname != NULL);
805
806   /***************************************************************************/
807   /* Free everything.                                                        */
808   /***************************************************************************/
809   evel_free_option_string(&vfield->vfmodule);
810   evel_free_option_string(&vfield->vnfname);
811   free(vfield->vendorname);
812
813   EVEL_EXIT();
814 }
815
816 /**************************************************************************//**
817  * Encode the instance id as a JSON object according to AT&T's schema.
818  *
819  * @param jbuf          Pointer to the ::EVEL_JSON_BUFFER to encode into.
820  * @param vfield        Pointer to the ::VENDOR_VNFNAME_FIELD to encode.
821  *****************************************************************************/
822 void evel_json_encode_vendor_field(EVEL_JSON_BUFFER * jbuf,
823                                   VENDOR_VNFNAME_FIELD * vfield)
824 {
825   EVEL_ENTER();
826
827   /***************************************************************************/
828   /* Check preconditions.                                                    */
829   /***************************************************************************/
830   assert(jbuf != NULL);
831   assert(jbuf->json != NULL);
832   assert(jbuf->max_size > 0);
833   assert(vfield != NULL);
834   assert(vfield->vendorname != NULL);
835
836   evel_json_open_named_object(jbuf, "vendorVnfNameFields");
837
838   /***************************************************************************/
839   /* Mandatory fields.                                                       */
840   /***************************************************************************/
841   evel_enc_kv_string(jbuf, "vendorName", vfield->vendorname);
842   evel_enc_kv_opt_string(jbuf, "vfModuleName", &vfield->vfmodule);
843   evel_enc_kv_opt_string(jbuf, "vnfName", &vfield->vnfname);
844
845   /***************************************************************************/
846   /* Optional fields.                                                        */
847   /***************************************************************************/
848
849   evel_json_close_object(jbuf);
850
851   EVEL_EXIT();
852 }