summaryrefslogtreecommitdiffstats
path: root/vnfs/VES5.0/evel/evel-library/code/evel_library
diff options
context:
space:
mode:
authorPrakashH <pbhandar@techmahindra.com>2019-01-28 17:14:52 +0000
committerPrakashH <pbhandar@techmahindra.com>2019-01-28 17:45:15 +0000
commitaf7aa682517d3ccaace9a089194e6a4333f4cdaa (patch)
treef9da027c69fff993b907ca93130aa47fe9c9786d /vnfs/VES5.0/evel/evel-library/code/evel_library
parent3bf047e64a1121208719e7603bf91c69d532ecf8 (diff)
VES EVEL Library VES 5.4.1 enhancements
HB-Fault-Measurement-Syslog-2Collector enhancement. Issue-ID: CERT-17 Change-Id: Ieff01ee5461e50c7e7d07d10ec66c1c97cf8c5b1 Signed-off-by: PrakashH <pbhandar@techmahindra.com>
Diffstat (limited to 'vnfs/VES5.0/evel/evel-library/code/evel_library')
-rw-r--r--vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h38
-rw-r--r--vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event.c58
-rw-r--r--vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event_mgr.c325
-rw-r--r--vnfs/VES5.0/evel/evel-library/code/evel_library/evel_heartbeat_fields.c7
4 files changed, 263 insertions, 165 deletions
diff --git a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h
index d62911de..8cdc4b57 100644
--- a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h
+++ b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h
@@ -1622,6 +1622,22 @@ EVENT_HEADER * evel_new_heartbeat(void);
*****************************************************************************/
EVENT_HEADER * evel_new_heartbeat_nameid(const char* ev_name, const char *ev_id);
+/**************************************************************************//**
+ * Create a new Heartbeat fields event.
+ *
+ * @note The mandatory fields on the Heartbeat fields must be supplied to
+ * this factory function and are immutable once set. Optional fields
+ * have explicit setter functions, but again values may only be set
+ * once so that the event has immutable properties.
+ * @param ev_name Unique Event Name confirming Domain AsdcModel Description
+ * @param ev_id A universal identifier of the event for: troubleshooting correlation, analysis, etc
+ * @param interval heartbeat interval
+ * @returns pointer to the newly manufactured ::EVENT_HEARTBEAT_FIELD. If the event
+ * is not used (i.e. posted) it must be released using
+ * ::evel_free_hrtbt_field.
+ * @retval NULL Failed to create the event.
+ *****************************************************************************/
+EVENT_HEARTBEAT_FIELD * evel_new_heartbeat_field(int interval,const char* ev_name, const char *ev_id);
/**************************************************************************//**
* Free an event header.
@@ -1706,6 +1722,17 @@ void evel_reporting_entity_name_set(EVENT_HEADER * const header,
const char * const entity_name);
/**************************************************************************//**
+ * Set the Source Name property of the event header.
+ *
+ * @note The Source Name defaults to the OpenStack VM Name.
+ *
+ * @param header Pointer to the ::EVENT_HEADER.
+ * @param entity_name The source name to set.
+ *****************************************************************************/
+void evel_source_name_set(EVENT_HEADER * const header,
+ const char * const source_name);
+
+/**************************************************************************//**
* Set the Reporting Entity Id property of the event header.
*
* @note The Reporting Entity Id defaults to the OpenStack VM UUID.
@@ -1717,6 +1744,17 @@ void evel_reporting_entity_id_set(EVENT_HEADER * const header,
const char * const entity_id);
/**************************************************************************//**
+ * Set the Source Id property of the event header.
+ *
+ * @note The Source Id defaults to the OpenStack VM UUID.
+ *
+ * @param header Pointer to the ::EVENT_HEADER.
+ * @param entity_id The Source id to set.
+ *****************************************************************************/
+void evel_source_id_set(EVENT_HEADER * const header,
+ const char * const source_id);
+
+/**************************************************************************//**
* Set the NFC Naming code property of the event header.
*
* @param header Pointer to the ::EVENT_HEADER.
diff --git a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event.c b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event.c
index 1656fa75..89c5c15e 100644
--- a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event.c
+++ b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event.c
@@ -411,6 +411,35 @@ void evel_reporting_entity_name_set(EVENT_HEADER * const header,
}
/**************************************************************************//**
+ * Set the Source Name property of the event header.
+ *
+ * @note The Source Name defaults to the OpenStack VM Name.
+ *
+ * @param header Pointer to the ::EVENT_HEADER.
+ * @param entity_name The source name to set.
+ *****************************************************************************/
+void evel_source_name_set(EVENT_HEADER * const header,
+ const char * const source_name)
+{
+ EVEL_ENTER();
+
+ /***************************************************************************/
+ /* Check preconditions and assign the new value. */
+ /***************************************************************************/
+ assert(header != NULL);
+ assert(source_name != NULL);
+
+ /***************************************************************************/
+ /* Free the previously allocated memory and replace it with a copy of the */
+ /* provided one. */
+ /***************************************************************************/
+ free(header->source_name);
+ header->source_name = strdup(source_name);
+
+ EVEL_EXIT();
+}
+
+/**************************************************************************//**
* Set the Reporting Entity Id property of the event header.
*
* @note The Reporting Entity Id defaults to the OpenStack VM UUID.
@@ -440,6 +469,35 @@ void evel_reporting_entity_id_set(EVENT_HEADER * const header,
}
/**************************************************************************//**
+ * Set the Source Id property of the event header.
+ *
+ * @note The Source Id defaults to the OpenStack VM UUID.
+ *
+ * @param header Pointer to the ::EVENT_HEADER.
+ * @param entity_id The Source id to set.
+ *****************************************************************************/
+void evel_source_id_set(EVENT_HEADER * const header,
+ const char * const source_id)
+{
+ EVEL_ENTER();
+
+ /***************************************************************************/
+ /* Check preconditions and assign the new value. */
+ /***************************************************************************/
+ assert(header != NULL);
+ assert(source_id != NULL);
+
+ /***************************************************************************/
+ /* Free the previously allocated memory and replace it with a copy of the */
+ /* provided one. Note that evel_force_option_string strdups entity_id. */
+ /***************************************************************************/
+ evel_free_option_string(&header->source_id);
+ evel_force_option_string(&header->source_id, source_id);
+
+ EVEL_EXIT();
+}
+
+/**************************************************************************//**
* Encode the event as a JSON event object according to AT&T's schema.
*
* @param jbuf Pointer to the ::EVEL_JSON_BUFFER to encode into.
diff --git a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event_mgr.c b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event_mgr.c
index 347f0284..cc676a6f 100644
--- a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event_mgr.c
+++ b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event_mgr.c
@@ -64,6 +64,7 @@ static bool evel_token_equals_string(const MEMORY_CHUNK * const chunk,
const jsmntok_t * const json_token,
const char * check_string);
static EVEL_ERR_CODES evel_setup_curl();
+static EVEL_ERR_CODES evel_send_to_another_collector(const EVEL_EVENT_DOMAINS evel_domain, char * json_body, size_t json_size);
/**************************************************************************//**
* Buffers for error strings from libcurl.
@@ -135,8 +136,8 @@ static char * evel_password = NULL;
static char * evel_username2 = NULL;
static char * evel_password2 = NULL;
-static int http_response_code = 0;
-static int evel_collector_id = 0;
+static long http_response_code = 0;
+static int evel_collector_id = 1;
/**************************************************************************//**
* Initialize the event handler.
*
@@ -224,7 +225,7 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url,
}
/***************************************************************************/
- /* Store other parameters
+ /* Store other parameters */
/***************************************************************************/
evel_secure = secure;
evel_verbosity = verbosity;
@@ -349,10 +350,10 @@ static EVEL_ERR_CODES evel_setup_curl()
EVEL_ENTER();
- if (evel_collector_id > 4)
+ if (evel_collector_id > 2)
{
rc = EVEL_CURL_LIBRARY_FAIL;
- log_error_state("Wrong evel_collector- value > 4");
+ log_error_state("Wrong evel_collector- value > 2");
goto exit_label;
}
@@ -374,21 +375,6 @@ static EVEL_ERR_CODES evel_setup_curl()
username = evel_username2;
password = evel_password2;
}
- else if (evel_collector_id == 3)
- {
- api_url = evel_batch_api_url;
- source_ip = evel_source_ip;
- username = evel_username;
- password = evel_password;
- }
- else if (evel_collector_id == 4)
- {
- api_url = evel_bbatch_api_url;
- source_ip = evel_source_ip_bakup;
- username = evel_username2;
- password = evel_password2;
- }
-
/***************************************************************************/
/* Clean-up the cURL library. */
/***************************************************************************/
@@ -1021,6 +1007,57 @@ exit_label:
}
/**************************************************************************//**
+ * Send event to another collector
+ *
+ * Identify the next collector and try sending the event to that collector
+ ****************************************************************************/
+static EVEL_ERR_CODES evel_send_to_another_collector(
+ const EVEL_EVENT_DOMAINS evel_domain,
+ char * json_body,
+ size_t json_size)
+{
+ int rc = EVEL_SUCCESS;
+ CURLcode curl_rc;
+
+ EVEL_ENTER();
+
+ if ((evel_collector_id == 1) && (curr_global_handles == 2))
+ {
+ evel_collector_id =2;
+ }
+ else if (evel_collector_id == 2)
+ {
+ evel_collector_id =1;
+ }
+
+ rc = evel_setup_curl();
+
+ if ( rc == EVEL_SUCCESS)
+ {
+ if (evel_collector_id == 1)
+ {
+ if (evel_domain == EVEL_DOMAIN_BATCH)
+ curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_batch_api_url);
+ else
+ curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_event_api_url);
+ }
+ else if (evel_collector_id == 2)
+ {
+ if (evel_domain == EVEL_DOMAIN_BATCH)
+ curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bbatch_api_url);
+ else
+ curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bevent_api_url);
+ }
+
+ rc = evel_post_api(json_body, json_size);
+ }
+
+ EVEL_EXIT();
+
+ return rc;
+}
+
+/**************************************************************************//**
* Callback function to provide data to send.
*
* Copy data into the supplied buffer, read_callback::ptr, checking size
@@ -1135,6 +1172,50 @@ static void * event_handler(void * arg __attribute__ ((unused)))
EVEL_ERROR("Event Handler State was not INACTIVE at start-up - "
"Handler will exit immediately!");
}
+ /***************************************************************************/
+ /* Set the connection to collector */
+ /***************************************************************************/
+ while (true)
+ {
+ evel_collector_id = 1;
+ rc = evel_setup_curl();
+
+ if ( rc != EVEL_SUCCESS)
+ {
+ EVEL_ERROR("Failed to setup the first collector. Error code=%d", rc);
+ if (curr_global_handles == 2)
+ {
+ EVEL_DEBUG("Switching to other collector");
+
+ evel_collector_id = 2;
+
+ rc = evel_setup_curl();
+ if ( rc != EVEL_SUCCESS)
+ {
+ EVEL_ERROR("Failed to setup the connection to second collector also, Error code%d", rc);
+ sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
+ collector_down_count = collector_down_count + 1;
+ EVEL_ERROR("Collectors setup issue- retry count=%d", collector_down_count);
+ }
+ else
+ {
+ collector_down_count = 0;
+ break;
+ }
+ }
+ else
+ {
+ sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
+ collector_down_count = collector_down_count + 1;
+ EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count);
+ }
+ }
+ else
+ {
+ collector_down_count = 0;
+ break;
+ }
+ }
while (evt_handler_state == EVT_HANDLER_ACTIVE)
{
@@ -1158,54 +1239,9 @@ static void * event_handler(void * arg __attribute__ ((unused)))
json_size = evel_json_encode_batch_event(json_body, EVEL_MAX_JSON_BODY, msg);
/***************************************************************************/
- /* Set the connection to collector */
- /***************************************************************************/
- while (true)
- {
- evel_collector_id =3;
- rc = evel_setup_curl();
-
- if ( rc != EVEL_SUCCESS)
- {
- EVEL_ERROR("Failed to setup the first collector. Error code=%d", rc);
- if (curr_global_handles == 2)
- {
- EVEL_DEBUG("Switching to other collector");
-
- evel_collector_id = 4;
-
- rc = evel_setup_curl();
- if ( rc != EVEL_SUCCESS)
- {
- EVEL_ERROR("Failed to setup the connection to second collector also, Error code%d", rc);
- sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
- collector_down_count = collector_down_count + 1;
- EVEL_ERROR("Collectors setup issue- retry count=%d", collector_down_count);
- }
- else
- {
- break;
- collector_down_count = 0;
- }
- }
- else
- {
- sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
- collector_down_count = collector_down_count + 1;
- EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count);
- }
- }
- else
- {
- break;
- collector_down_count = 0;
- }
- }
-
- /***************************************************************************/
/* Set the URL for the API. */
/***************************************************************************/
- if (evel_collector_id == 3)
+ if (evel_collector_id == 1)
{
curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_batch_api_url);
}
@@ -1242,45 +1278,51 @@ static void * event_handler(void * arg __attribute__ ((unused)))
while (true)
{
- if ((evel_collector_id == 3) && (curr_global_handles == 2))
+ if (curr_global_handles == 2)
{
- evel_collector_id =4;
+ rc = evel_send_to_another_collector(msg->event_domain, json_body, json_size);
+
+ switch_coll = 0;
+ if ((rc == EVEL_SUCCESS) && ((http_response_code / 100) != 2))
+ {
+ switch_coll = 1;
+ if (http_response_code == 400) // 400 - Bad JSON related return code
+ switch_coll = 0;
+ }
+ if ((rc != EVEL_SUCCESS) || (switch_coll == 1))
+ {
+ sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
+ collector_down_count = collector_down_count + 1;
+ EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count);
+ }
+ else
+ {
+ break;
+ }
}
- else if (evel_collector_id == 4)
+ else
{
- evel_collector_id =3;
+ sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
+ collector_down_count = collector_down_count + 1;
+ EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count);
}
- rc = evel_setup_curl();
-
- if ( rc != EVEL_SUCCESS)
- {
- sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
- collector_down_count = collector_down_count + 1;
- EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count);
- continue;
- }
+ rc = evel_send_to_another_collector(msg->event_domain, json_body, json_size);
- if (evel_collector_id == 3)
- {
- curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_batch_api_url);
- }
- else if (evel_collector_id == 4)
+ switch_coll = 0;
+ if ((rc == EVEL_SUCCESS) && ((http_response_code / 100) != 2))
{
- curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bbatch_api_url);
+ switch_coll = 1;
+ if (http_response_code == 400) // 400 - Bad JSON related return code
+ switch_coll = 0;
}
-
- rc = evel_post_api(json_body, json_size);
- if ( rc != EVEL_SUCCESS)
+ if ((rc != EVEL_SUCCESS) || (switch_coll == 1))
{
- sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
collector_down_count = collector_down_count + 1;
EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count);
- continue;
}
else
{
- EVEL_DEBUG("Successfully sent msg after retry=%d", collector_down_count);
break;
}
}
@@ -1296,57 +1338,12 @@ static void * event_handler(void * arg __attribute__ ((unused)))
json_size = evel_json_encode_event(json_body, EVEL_MAX_JSON_BODY, msg);
/***************************************************************************/
- /* Set the connection to collector */
- /***************************************************************************/
- while (true)
- {
- evel_collector_id = 1;
- rc = evel_setup_curl();
-
- if ( rc != EVEL_SUCCESS)
- {
- EVEL_ERROR("Failed to setup the first collector. Error code=%d", rc);
- if (curr_global_handles == 2)
- {
- EVEL_DEBUG("Switching to other collector");
-
- evel_collector_id = 2;
-
- rc = evel_setup_curl();
- if ( rc != EVEL_SUCCESS)
- {
- EVEL_ERROR("Failed to setup the connection to second collector also, Error code%d", rc);
- sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
- collector_down_count = collector_down_count + 1;
- EVEL_ERROR("Collectors setup issue- retry count=%d", collector_down_count);
- }
- else
- {
- break;
- collector_down_count = 0;
- }
- }
- else
- {
- sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
- collector_down_count = collector_down_count + 1;
- EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count);
- }
- }
- else
- {
- break;
- collector_down_count = 0;
- }
- }
- /***************************************************************************/
/* Set the URL for the API. */
/***************************************************************************/
if (evel_collector_id == 1)
curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_event_api_url);
else
curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bevent_api_url);
-
if (curl_rc != CURLE_OK)
{
rc = EVEL_CURL_LIBRARY_FAIL;
@@ -1375,45 +1372,51 @@ static void * event_handler(void * arg __attribute__ ((unused)))
while (true)
{
- if ((evel_collector_id == 1) && (curr_global_handles == 2))
+ if (curr_global_handles == 2)
{
- evel_collector_id =2;
+ rc = evel_send_to_another_collector(msg->event_domain, json_body, json_size);
+
+ switch_coll = 0;
+ if ((rc == EVEL_SUCCESS) && ((http_response_code / 100) != 2))
+ {
+ switch_coll = 1;
+ if (http_response_code == 400) // 400 - Bad JSON related return code
+ switch_coll = 0;
+ }
+ if ((rc != EVEL_SUCCESS) || (switch_coll == 1))
+ {
+ sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
+ collector_down_count = collector_down_count + 1;
+ EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count);
+ }
+ else
+ {
+ break;
+ }
}
- else if (evel_collector_id == 2)
+ else
{
- evel_collector_id =1;
+ sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
+ collector_down_count = collector_down_count + 1;
+ EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count);
}
- rc = evel_setup_curl();
-
- if ( rc != EVEL_SUCCESS)
- {
- sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
- collector_down_count = collector_down_count + 1;
- EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count);
- continue;
- }
+ rc = evel_send_to_another_collector(msg->event_domain, json_body, json_size);
- if (evel_collector_id == 1)
- {
- curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_event_api_url);
- }
- else if (evel_collector_id == 2)
+ switch_coll = 0;
+ if ((rc == EVEL_SUCCESS) && ((http_response_code / 100) != 2))
{
- curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bevent_api_url);
+ switch_coll = 1;
+ if (http_response_code == 400) // 400 - Bad JSON related return code
+ switch_coll = 0;
}
-
- rc = evel_post_api(json_body, json_size);
- if ( rc != EVEL_SUCCESS)
+ if ((rc != EVEL_SUCCESS) || (switch_coll == 1))
{
- sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME);
collector_down_count = collector_down_count + 1;
EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count);
- continue;
}
else
{
- EVEL_DEBUG("Successfully sent msg after retry=%d", collector_down_count);
break;
}
}
diff --git a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_heartbeat_fields.c b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_heartbeat_fields.c
index 031632a3..be8527c4 100644
--- a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_heartbeat_fields.c
+++ b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_heartbeat_fields.c
@@ -36,10 +36,9 @@
* this factory function and are immutable once set. Optional fields
* have explicit setter functions, but again values may only be set
* once so that the event has immutable properties.
- * @param event_name Unique Event Name confirming Domain AsdcModel Description
- * @param event_id A universal identifier of the event for: troubleshooting correlation, analysis, etc
- * @param vendor_id The vendor id to encode in the event instance id.
- * @param event_id The vendor event id to encode in the event instance id.
+ * @param ev_name Unique Event Name confirming Domain AsdcModel Description
+ * @param ev_id A universal identifier of the event for: troubleshooting correlation, analysis, etc
+ * @param interval heartbeat interval
* @returns pointer to the newly manufactured ::EVENT_HEARTBEAT_FIELD. If the event
* is not used (i.e. posted) it must be released using
* ::evel_free_hrtbt_field.