Fix of VES alarm issue
[o-du/l2.git] / src / o1 / ves / CellStateChange.cpp
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2020-2022] [HCL Technologies Ltd.]                          #
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
19 #include <iostream>
20 #include <chrono>
21 #include <iomanip>
22 #include <sstream>
23 #include "CellStateChange.hpp"
24 #include "JsonHelper.hpp"
25
26 /* Default constructor*/
27 CellStateChange::CellStateChange() : Notification(VesEventType::FAULT_NOTIFICATION)
28 {
29    
30 }
31
32 /* Default Destructor*/
33 CellStateChange::~CellStateChange()
34 {
35
36 }
37
38 /*******************************************************************
39  *
40  * @brief Returns ISO time String 
41  *
42  * @details
43  *
44  *    Function :getISOEventTime
45  *
46  *    Functionality:
47  *      - Returns ISO time String
48  *
49  * @params[in] IN - void
50  * @return value of string     - success
51  *         empty string        - failure
52  *
53  * ****************************************************************/
54
55 std::string CellStateChange::getISOEventTime() {
56    auto now = std::chrono::system_clock::now();
57    auto itt = std::chrono::system_clock::to_time_t(now);
58    std::ostringstream os;
59    os << std::put_time(gmtime(&itt), "%FT%TZ");
60    return os.str();
61 }
62
63 /*******************************************************************
64  *
65  * @brief Returns Event Severity String
66  *
67  * @details
68  *
69  *    Function :getEventSeverity
70  *
71  *    Functionality:
72  *      - Returns Event Severity String
73  *
74  * @params[in] IN - int severity 
75  * @return value of string     - success
76  *         empty string        - failure
77  *
78  * ****************************************************************/
79
80 std::string CellStateChange::getEventSeverity(int severity) {
81    string str;
82    switch(severity)
83    {
84       case 3:
85          str = "CRITICAL";
86          break;
87       case 4:
88          str = "MAJOR";
89          break;
90       case 5:
91          str = "MINOR";
92          break;
93       case 6:
94          str = "WARNING";
95          break;
96       default:
97          str = "MAJOR";
98          break;
99    }
100    return str;
101
102
103 }
104
105 /*******************************************************************
106  *
107  * @brief prepare CellStateChange Fields
108  *
109  * @details
110  *
111  *    Function : prepareCellStateChangeEventFields
112  *
113  *    Functionality:
114  *      - prepare CellStateChange Fields in json format
115  *
116  * @params[in] IN   - pointer to pnfFields
117  * @return true     - success
118  *         false    - failure
119  *
120  * ****************************************************************/
121
122 bool CellStateChange::prepareEventFields(const Message* msg) {
123    const Alarm* alarm = dynamic_cast<const Alarm*> (msg);
124    if(!alarm) {
125       O1_LOG("\nO1 CellStateChange : Casting failed in prepareEventFields");
126       return false;
127    }
128    bool ret = true;
129
130
131    cJSON* faultFields = this->mVesEventFields;
132
133    if(JsonHelper::addNodeToObject(faultFields, "faultFieldsVersion", FAULT_FIELDS_VERSION) == 0) {
134       ret = false;
135    }
136    if(JsonHelper::addNodeToObject(faultFields, "alarmCondition", alarm->getAdditionalInfo().c_str()) == 0) {
137       ret = false;
138    }
139    if(JsonHelper::addNodeToObject(faultFields, "alarmInterfaceA", ALARM_INTERFACE_A) == 0) {
140       ret = false;
141    }
142    if(JsonHelper::addNodeToObject(faultFields, "eventSourceType", ODU_HIGH) == 0) {
143       ret = false;
144    }
145    if(JsonHelper::addNodeToObject(faultFields, "specificProblem", alarm->getAdditionalText().c_str()) == 0) {
146       ret = false;
147    }
148    if(JsonHelper::addNodeToObject(faultFields, "eventSeverity", getEventSeverity(alarm->getPerceivedSeverity()).c_str()) == 0) {
149       ret = false;
150    }   
151    if(JsonHelper::addNodeToObject(faultFields, "vfStatus", alarm->getSpecificProblem().c_str()) == 0) {
152       ret = false;
153    }
154    
155    cJSON* alarmAdditionalInformation = JsonHelper::createNode();
156    if(alarmAdditionalInformation == 0) {
157       O1_LOG("\nO1 CellStateChange : could not create alarmAdditionalInformation JSON object");
158       return false;
159    }
160    else if(JsonHelper::addJsonNodeToObject(faultFields, "alarmAdditionalInformation", \
161                                       alarmAdditionalInformation ) == 0) {
162       ret = false;
163    }
164    else if(JsonHelper::addNodeToObject(alarmAdditionalInformation, "eventTime", getISOEventTime().c_str()) == 0) {
165       ret = false;
166    }
167    else if(JsonHelper::addNodeToObject(alarmAdditionalInformation, "equipType", EQUIP_TYPE) == 0) {
168       ret = false;
169    }
170    else if(JsonHelper::addNodeToObject(alarmAdditionalInformation, "vendor", VENDOR) == 0) {
171       ret = false;
172    }
173    else if(JsonHelper::addNodeToObject(alarmAdditionalInformation, "model", MODEL) == 0) {
174       ret = false;
175    }
176    
177    
178    return ret;
179 }
180
181
182 /**********************************************************************
183   End of file
184  **********************************************************************/