X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ntsimulator%2Fsrc%2Fo-ran-notifications%2Fo-ran-notifications.c;h=3699e282b39e9d934ec55bf87223ed2cdbf60cfb;hb=f2d8f1002fa93848c80a88e5658db4816cba3020;hp=230fad26bdc949da572725faedfbd94d1ecc56e9;hpb=a19f893a70c03dee9312e1208301d079409d84ac;p=sim%2Fo1-interface.git diff --git a/ntsimulator/src/o-ran-notifications/o-ran-notifications.c b/ntsimulator/src/o-ran-notifications/o-ran-notifications.c index 230fad2..3699e28 100644 --- a/ntsimulator/src/o-ran-notifications/o-ran-notifications.c +++ b/ntsimulator/src/o-ran-notifications/o-ran-notifications.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "sysrepo.h" #include "sysrepo/values.h" @@ -99,7 +100,6 @@ static int cleanup_curl() static int send_fault_ves_message(char *alarm_condition, char *alarm_object, char *severity, char *date_time, char *specific_problem, int port) { - int rc = SR_ERR_OK; CURLcode res; static int sequence_id = 0; int netconf_port_base = 0; @@ -112,23 +112,14 @@ static int send_fault_ves_message(char *alarm_condition, char *alarm_object, cha if (event == NULL) { printf("Could not create JSON object: event\n"); - return 1; + return SR_ERR_OPERATION_FAILED; } cJSON_AddItemToObject(postDataJson, "event", event); char *hostname = getenv("HOSTNAME"); - char *netconf_base_string = getenv("NETCONF_BASE"); - if (netconf_base_string != NULL) - { - rc = sscanf(netconf_base_string, "%d", &netconf_port_base); - if (rc != 1) - { - printf("Could not find the NETCONF base port, aborting the PNF registration...\n"); - return 1; - } - netconf_port_base += port; - } + netconf_port_base = getIntFromString(getenv("NETCONF_BASE"), 1); + netconf_port_base += port; char source_name[100]; sprintf(source_name, "%s_%d", hostname, netconf_port_base); @@ -137,7 +128,7 @@ static int send_fault_ves_message(char *alarm_condition, char *alarm_object, cha if (commonEventHeader == NULL) { printf("Could not create JSON object: commonEventHeader\n"); - return 1; + return SR_ERR_OPERATION_FAILED; } cJSON_AddItemToObject(event, "commonEventHeader", commonEventHeader); @@ -149,7 +140,7 @@ static int send_fault_ves_message(char *alarm_condition, char *alarm_object, cha { cJSON_Delete(postDataJson); } - return 1; + return SR_ERR_OPERATION_FAILED; } cJSON_AddItemToObject(event, "faultFields", faultFields); @@ -360,7 +351,6 @@ main(int argc, char **argv) sr_session_ctx_t *session = NULL; sr_subscription_ctx_t *subscription = NULL; int rc = SR_ERR_OK; - int notification_delay_period = 0; //seconds setbuf(stdout, NULL); @@ -389,27 +379,44 @@ main(int argc, char **argv) signal(SIGINT, sigint_handler); signal(SIGPIPE, SIG_IGN); - while (!exit_application) { - notification_delay_period = getFaultNotificationDelayPeriodFromConfigJson(); + int notif_delay[100], count = 0; - if (notification_delay_period > 0) + rc = getFaultNotificationDelayPeriodFromConfigJson(notif_delay, &count); + if (rc != SR_ERR_OK) { - send_dummy_notif(session); + printf("Could not get fault notification delay period."); + sleep(1); + continue; + } - sleep(notification_delay_period); + if (count > 1) + { + for (int i = 0; i < count; ++i) + { + sleep(notif_delay[i]); + send_dummy_notif(session); + } } - else + else if (count == 1) { - sleep(1); - // reset the counters when the notifciation delay period is switched back to 0 - netconf_alarm_counter.normal = netconf_alarm_counter.warning = \ - netconf_alarm_counter.minor = netconf_alarm_counter.major = \ - netconf_alarm_counter.critical = 0; - - ves_alarm_counter.normal = ves_alarm_counter.warning = \ - ves_alarm_counter.minor = ves_alarm_counter.major = \ - ves_alarm_counter.critical = 0; + if (notif_delay[0] > 0) + { + sleep(notif_delay[0]); + send_dummy_notif(session); + } + else + { + sleep(1); + // reset the counters when the notifciation delay period is switched back to 0 + netconf_alarm_counter.normal = netconf_alarm_counter.warning = \ + netconf_alarm_counter.minor = netconf_alarm_counter.major = \ + netconf_alarm_counter.critical = 0; + + ves_alarm_counter.normal = ves_alarm_counter.warning = \ + ves_alarm_counter.minor = ves_alarm_counter.major = \ + ves_alarm_counter.critical = 0; + } } }