Cell down alarm notification [Issue-Id: ODUHIGH-430]
[o-du/l2.git] / src / o1 / ves / CellStateChangeStdDef.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 "CellStateChangeStdDef.hpp"
24 #include "JsonHelper.hpp"
25 /* Default constructor*/
26 CellStateChangeStdDef::CellStateChangeStdDef() : Notification(VesEventType::FAULT_NOTIFICATION)
27 {
28
29 }
30
31 /* Default Destructor*/
32 CellStateChangeStdDef::~CellStateChangeStdDef()
33 {
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 CellStateChangeStdDef::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 prepare CellStateChangeStdDef Fields
66  *
67  * @details
68  *
69  *    Function : prepareCellStateChangeStdDefEventFields
70  *
71  *    Functionality:
72  *      - prepare CellStateChangeStdDef Fields in json format
73  *
74  * @params[in] IN   - pointer to pnfFields
75  * @return true     - success
76  *         false    - failure
77  *
78  * ****************************************************************/
79
80 bool CellStateChangeStdDef::prepareEventFields(const Message* msg) {
81    const Alarm* alrm = dynamic_cast<const Alarm*> (msg);
82    if(!alrm) {
83       O1_LOG("\nO1 CellStateChangeStdDef : Casting failed in prepareEventFields");
84       return false;
85    }
86    bool ret = true;
87
88
89    cJSON* stndDefinedFields = this->mVesEventFields;
90
91    if(JsonHelper::addNodeToObject(stndDefinedFields, "schemaReference", FAULT_SCHEMA) == 0) {
92       ret = false;
93    }
94
95    cJSON* data = JsonHelper::createNode();
96    if(data == 0) {
97       O1_LOG("\nO1 CellStateChangeStdDef : could not create data JSON object");
98       return false;
99    }
100    else if(JsonHelper::addJsonNodeToObject(stndDefinedFields, "data", \
101                                        data) == 0) {
102       ret = false;
103    }
104    else if(JsonHelper::addNodeToObject(data, "href", HREF) == 0) {
105       ret = false;
106    }
107    else if(JsonHelper::addNodeToObject(data, "uri", URI) == 0) {
108       ret = false;
109    }
110    else if(JsonHelper::addNodeToObject(data, "notificationId", NOTIFICATION_ID) == 0) {
111       ret = false;
112    }
113    else if(JsonHelper::addNodeToObject(data, "notificationType", NOTIFICATION_TYPE) == 0) {
114       ret = false;
115    }
116    else if(JsonHelper::addNodeToObject(data, "eventTime", getISOEventTime().c_str()) == 0) {
117       ret = false;
118    }
119    else if(JsonHelper::addNodeToObject(data, "systemDN", "") == 0) {
120       ret = false;
121    }
122    else if(JsonHelper::addNodeToObject(data, "probableCause", PROBABLE_CAUSE) == 0) {
123       ret = false;
124    }
125    else if(JsonHelper::addNodeToObject(data, "perceivedSeverity",PERCEIVED_SEVERITY) == 0) {
126       ret = false;
127    }
128    else if(JsonHelper::addNodeToObject(data, "rootCauseIndicator", (bool)false ) == 0) {
129       ret = false;
130    }
131    else if(JsonHelper::addNodeToObject(data, "specificProblem", "") == 0) {
132       ret = false;
133    }
134
135    cJSON*  correlatedNotificationsArr= cJSON_CreateArray();
136    if (correlatedNotificationsArr == NULL)
137    {
138       ret = false;
139    }
140    cJSON_AddItemToObject(data, "correlatedNotifications", correlatedNotificationsArr);
141
142    if(JsonHelper::addNodeToObject(data, "backedUpStatus", (bool)true) == 0) {
143       ret = false;
144    }
145    else if(JsonHelper::addNodeToObject(data, "backUpObject", "") == 0) {
146       ret = false;
147    }
148    else if(JsonHelper::addNodeToObject(data, "trendIndication", TRND_INDICATION) == 0) {
149       ret = false;
150    }
151
152    cJSON* thresholdInfo = JsonHelper::createNode();
153    if(thresholdInfo == 0) {
154       O1_LOG("\nO1 CellStateChange : could not create thresholdInfo JSON object");
155       return false;
156    }
157    else if(JsonHelper::addJsonNodeToObject(data, "thresholdInfo", \
158                                       thresholdInfo ) == 0) {
159       ret = false;
160    }
161    else if(JsonHelper::addNodeToObject(thresholdInfo, "observedMeasurement", OBSRVED_MEASUREMENT) == 0) {
162       ret = false;
163    }
164    else if(JsonHelper::addNodeToObject(thresholdInfo, "observedValue", OBSERVED_VALUE) == 0) {
165       ret = false;
166    }
167
168    cJSON*  stateChangeDefinitionArr= cJSON_CreateArray();
169    if (stateChangeDefinitionArr == NULL)
170    {
171       ret = false;
172    }
173    cJSON_AddItemToObject(data, "stateChangeDefinition", stateChangeDefinitionArr);
174
175    cJSON* monitoredAttributes = JsonHelper::createNode();
176    if( monitoredAttributes == 0) {
177       O1_LOG("\nO1 CellStateChange : could not create monitoredAttributes JSON object");
178       return false;
179    }
180    else if(JsonHelper::addJsonNodeToObject(data , "monitoredAttributes", \
181                                        monitoredAttributes ) == 0) {
182       ret = false;
183    }
184    else if(JsonHelper::addNodeToObject(monitoredAttributes, "newAtt", NEW_ATT) == 0) {
185       ret = false;
186    }
187    else if(JsonHelper::addNodeToObject(data, "proposedRepairActions", PROPOSED_REPAIR_ACTION) == 0) {
188       ret = false;
189    }
190    else if(JsonHelper::addNodeToObject(data, "additionalText", ADDITIONAL_TEXT) == 0) {
191       ret = false;
192    }
193
194    cJSON* additionalInformation = JsonHelper::createNode();
195    if(additionalInformation == 0) {
196       O1_LOG("\nO1 CellStateChangeStdDef : could not create additionalInformation JSON object");
197       return false;
198    }
199    else if(JsonHelper::addJsonNodeToObject(data , "additionalInformation", \
200                                        additionalInformation ) == 0) {
201       ret = false;
202    }
203    else if(JsonHelper::addNodeToObject( additionalInformation, "addInfo", ADD_INFO) == 0) {
204       ret = false;
205    }
206    else if(JsonHelper::addNodeToObject(data , "alarmId", ALARM_ID) == 0) {
207       ret = false;
208    }
209    else if(JsonHelper::addNodeToObject(data , "alarmType",ALRAM_TYPE ) == 0) {
210       ret = false;
211    }
212
213    else if(JsonHelper::addNodeToObject(stndDefinedFields, "stndDefinedFieldsVersion", STND_DEFINED_FEILD_VERSION) == 0) {
214       ret = false;
215    }
216
217
218
219    return ret;
220 }
221
222
223 /**********************************************************************
224   End of file
225  **********************************************************************/