Rewrite NTS Framework.
[sim/o1-interface.git] / ntsimulator / ntsim-ng / core / faults / faults.h
1 /*************************************************************************
2 *
3 * Copyright 2020 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 #pragma once
19
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <sysrepo.h>
23
24 typedef struct {
25     //list of all fields, including ves mandatory
26     char **field_name;
27     char **field_value;
28     int field_count;
29
30     //mandatory ves fields
31     char *condition;
32     char *object;
33     char *severity;
34     char *date_time;
35     char *specific_problem;
36
37     //output data
38     char *yang_notif_processed;
39 } fault_details_t;
40
41 typedef struct {
42     char *yang_notif_template;
43     char *choosing_method;
44
45     fault_details_t *fault;
46     int fault_count;
47 } fault_settings_t;
48
49 typedef struct {
50     uint32_t normal;
51     uint32_t warning;
52     uint32_t minor;
53     uint32_t major;
54     uint32_t critical;
55 } fault_counters_t;
56
57 int faults_init(void);
58 void faults_free(void);
59
60 int faults_change_settings(const char *json);
61 bool faults_get_present(void);                      //returns wheter faults are present or not in current config
62
63 fault_details_t *faults_generate_fault(void);       //does not require freeing, does not update counters
64
65 //faults_processing.c
66 fault_settings_t *faults_settings_read(const char *json_plain);
67 void faults_settings_free(fault_settings_t *faults);
68 int faults_settings_process(fault_settings_t *faults, int fault_no);
69
70 //faults_counters.c
71 fault_counters_t faults_counters_get(void);             //assumes faults_lock is acquired
72 void faults_counters_clear(void);                       //assumes faults_lock is acquired
73 int faults_counters_increase(const char *severity);     //assumes faults_lock is acquired
74
75 //faults_logic.c
76 void faults_fault_list_clear(void);         //assumes faults_lock is acquired
77 int faults_fault_list_add(uint16_t delay);  //assumes faults_lock is acquired
78 bool faults_fault_list_not_empty(void);     //assumes faults_lock is acquired
79 uint16_t faults_fault_list_get_next(void);  //assumes faults_lock is acquired
80
81 //faults_ves.c
82 int faults_ves_init(void);
83 void faults_ves_free(void);
84
85 int faults_ves_message_send(sr_session_ctx_t *session, const char *condition, const char *object, const char *severity, const char *date_time, const char *specific_problem);