Add API allowing xAPPs to send alarm messages
[ric-plt/xapp-frame-cpp.git] / src / alarm / alarm.hpp
1 // vi: ts=4 sw=4 noet:
2 /*
3 ==================================================================================
4         Copyright (c) 2020 Nokia
5         Copyright (c) 2020 AT&T Intellectual Property.
6
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11        http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18 ==================================================================================
19 */
20
21 /*
22         Mnemonic:       alarm.hpp
23         Abstract:       Headers for the alarm class.
24                                 This class provides for an alarm API.
25
26         Date:           15 July 2020
27         Author:         E. Scott Daniels
28 */
29
30 #ifndef _XAPP_ALARM_HPP
31 #define _XAPP_ALARM_HPP
32
33
34 #include <iostream>
35 #include <string>
36
37 #include "msg_component.hpp"
38
39 namespace xapp {
40
41 // ------------------------------------------------------------------------
42
43 class Alarm {
44         private:
45                 std::shared_ptr<Message> msg;           // message to send
46                 std::shared_ptr<char> psp;                      // shared pointer to the payload to give out
47                 std::string endpoint;                           // the ip:port addr:port of the alarm collector
48                 int                     whid;
49
50                                                                                         // data for the payload
51                 std::string     me_id;                                  // managed element ID
52                 std::string app_id;                                     // application ID
53                 int                     problem_id;                             // problem ID (specific problem)
54                 std::string     severity;                               // SEV_* constants
55                 std::string     action;                                 // ACT_* constants
56                 std::string info;                                       // info string supplied by user
57                 std::string add_info;                           // additional information supplied by user
58
59                 int build_alarm( int action_id, xapp::Msg_component payload, int payload_len );
60
61         public:
62                 static const int        SEV_CRIT = 1;                   // allow translation to string on send/gen
63                 static const int        SEV_MAJOR = 2;
64                 static const int        SEV_MINOR = 3;
65                 static const int        SEV_WARN = 4;
66                 static const int        SEV_CLEAR = 5;
67                 static const int        SEV_DEFAULT = 6;
68
69                 static const int        ACT_RAISE = 1;                  // action const map to alarm manager strings
70                 static const int        ACT_CLEAR = 2;
71                 static const int        ACT_CLEAR_ALL = 3;
72
73                 Alarm( std::shared_ptr<Message> msg );          // builders
74                 Alarm( std::shared_ptr<Message> msg, std::string meid  );
75                 Alarm( std::shared_ptr<Message> msg, int prob_id, std::string meid  );
76
77                 Alarm( const Alarm& soi );                                      // copy to newly created instance
78                 Alarm& operator=( const Alarm& soi );           // copy operator
79                 Alarm( Alarm&& soi );                                           // mover
80                 Alarm& operator=( Alarm&& soi );                        // move operator
81                 ~Alarm();                                                                       // destroyer
82
83
84                 std::string Get_endpoint( );
85
86                 void Set_additional( std::string new_info );
87                 void Set_appid( std::string new_id );
88                 void Set_info( std::string new_info );
89                 void Set_meid( std::string new_meid );
90                 void Set_problem( int new_id );
91                 void Set_severity( int new_sev );
92                 void Set_whid( int whid );
93
94
95                 bool Raise( );
96                 bool Raise( int severity, int problem, std::string info );
97                 bool Raise( int severity, int problem, std::string info, std::string addional_info );
98                 bool Raise_again( );
99
100                 bool Clear( );
101                 bool Clear( int severity, int problem, std::string info );
102                 bool Clear( int severity, int problem, std::string info, std::string addional_info );
103                 bool Clear_all( );
104
105
106                 void Dump();
107 };
108
109 } // namespace
110
111 #endif