Add counters for generated notifications.
[sim/o1-interface.git] / ntsimulator / inc / utils / utils.h
1 /*************************************************************************
2 *
3 * Copyright 2019 highstreet technologies GmbH and others
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
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 ***************************************************************************/
17
18 #ifndef EXAMPLES_NTSIMULATOR_UTILS_H_
19 #define EXAMPLES_NTSIMULATOR_UTILS_H_
20
21 #include "sysrepo.h"
22 #include "sysrepo/values.h"
23 #include "sysrepo/xpath.h"
24
25 #include <curl/curl.h>
26 #include <stdlib.h>
27 #include <stdbool.h>
28 #include <stdio.h>
29 #include <cjson/cJSON.h>
30
31 #define TRUE 1
32 #define FALSE 0
33
34 #define NETCONF_CONNECTIONS_PER_DEVICE 10
35
36 #define PREPARE_ADD_NEW_VALUE(v, num)   {\
37                                                                                 num++;\
38                                                                                 }
39
40 #define CREATE_NEW_VALUE(rc, v, num)    {\
41                                                                                 rc = sr_realloc_values(num, num+1, &v);\
42                                                                                 if (SR_ERR_OK != rc) {\
43                                                                                         return rc;\
44                                                                                 }\
45                                                                                 num++;\
46                                                                                 }
47
48 typedef struct
49 {
50         int normal;
51         int warning;
52         int minor;
53         int major;
54         int critical;
55 } counterAlarms;
56
57 void            set_curl_common_info_ves(CURL *curl);
58
59 long            random_at_most(long max);
60 void            getCurrentDateAndTime(char *date_and_time);
61 int             getSecondsFromLastQuarterInterval(void);
62 int             getSecondsFromLastDayInterval(void);
63 void            getPreviousQuarterInterval(int number_of_intervals, char *date_and_time);
64 void            getPreviousDayPmTimestamp(int number_of_intervals, char *date_and_time);
65 long int        getMicrosecondsSinceEpoch(void);
66 void            prepare_ves_message_curl(CURL *curl);
67
68 cJSON*  vesCreateCommonEventHeader(char *domain, char *event_type, char *source_name, int seq_id);
69 cJSON*  vesCreateHeartbeatFields(int heartbeat_interval);
70 cJSON*  vesCreatePnfRegistrationFields(int port, bool is_tls);
71 cJSON*  vesCreateFaultFields(char *alarm_condition, char *alarm_object, char *severity, char *date_time, char *specific_problem);
72
73 char*   readConfigFileInString(void);
74 void    writeConfigFile(char *config);
75
76 int     getFaultNotificationDelayPeriodFromConfigJson(void);
77 int     getVesHeartbeatPeriodFromConfigJson(void);
78 char*   getVesAuthMethodFromConfigJson(void);
79 char*   getVesIpFromConfigJson(void);
80 int     getVesPortFromConfigJson(void);
81 int     getVesRegistrationFromConfigJson(void);
82 int     getNetconfAvailableFromConfigJson(void);
83 int     getVesAvailableFromConfigJson(void);
84
85 void    generateRandomMacAddress(char *mac_address);
86
87 int     writeSkeletonStatusFile(void);
88 char*   readStatusFileInString(void);
89
90 int     writeStatusNotificationCounters(counterAlarms ves_counter, counterAlarms netconf_counter);
91 void    writeStatusFile(char *status);
92 int     removeDeviceEntryFromStatusFile(char *deviceName);
93
94 cJSON*  getDeviceListFromStatusFile(void);
95 int     compute_notifications_count(counterAlarms *ves_counter, counterAlarms *netconf_counter);
96 int     getDeviceCounters(char *containerId, counterAlarms *ves_counter, counterAlarms *netconf_counter);
97
98 #endif /* EXAMPLES_NTSIMULATOR_UTILS_H_ */