738dd90177bff0a3f9507bd6f5e34c9ab82a0891
[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 = -1;
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  = -1;               // problem ID (specific problem)
54                 std::string     severity = "";                  // set_sev() xlates from SEV_* consts to collector's string values
55                 std::string info = "";                          // info string supplied by user
56                 std::string add_info = "";                      // additional information supplied by user
57
58                 int build_alarm( int action_id, xapp::Msg_component payload, int payload_len );
59
60         public:
61                 static const int        SEV_CRIT = 1;                   // allow translation to string on send/gen
62                 static const int        SEV_MAJOR = 2;
63                 static const int        SEV_MINOR = 3;
64                 static const int        SEV_WARN = 4;
65                 static const int        SEV_CLEAR = 5;
66                 static const int        SEV_DEFAULT = 6;
67
68                 static const int        ACT_RAISE = 1;                  // action const map to alarm manager strings
69                 static const int        ACT_CLEAR = 2;
70                 static const int        ACT_CLEAR_ALL = 3;
71
72                 explicit Alarm( std::shared_ptr<Message> msg );         // builders
73                 Alarm( std::shared_ptr<Message> msg, const std::string& meid  );
74                 Alarm( std::shared_ptr<Message> msg, int prob_id, const std::string& meid  );
75
76                 Alarm( const Alarm& soi );                                      // copy to newly created instance
77                 Alarm& operator=( const Alarm& soi );           // copy operator
78                 Alarm( Alarm&& soi );                                           // mover
79                 Alarm& operator=( Alarm&& soi ) noexcept;                       // move operator
80                 ~Alarm();                                                                       // destroyer
81
82
83                 std::string Get_endpoint( ) const;
84
85                 void Set_additional( const std::string& new_info );
86                 void Set_appid( const std::string& new_id );
87                 void Set_info( const std::string& new_info );
88                 void Set_meid( const std::string& new_meid );
89                 void Set_problem( int new_id );
90                 void Set_severity( int new_sev );
91                 void Set_whid( int whid );
92
93
94                 bool Raise( );
95                 bool Raise( int severity, int problem, const std::string& info );
96                 bool Raise( int severity, int problem, const std::string& info, const std::string& additional_info );
97                 bool Raise_again( );
98
99                 bool Clear( );
100                 bool Clear( int severity, int problem, const std::string& info );
101                 bool Clear( int severity, int problem, const std::string& info, const std::string& additional_info );
102                 bool Clear_all( );
103
104
105                 void Dump() const;
106 };
107
108 } // namespace
109
110 #endif