94d572c86a851ac9f88d1244bf65da6d284d63bc
[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 prepare CellStateChange Fields
66  *
67  * @details
68  *
69  *    Function : prepareCellStateChangeEventFields
70  *
71  *    Functionality:
72  *      - prepare CellStateChange Fields in json format
73  *
74  * @params[in] IN   - pointer to pnfFields
75  * @return true     - success
76  *         false    - failure
77  *
78  * ****************************************************************/
79
80 bool CellStateChange::prepareEventFields(const Message* msg) {
81    const Alarm* alrm = dynamic_cast<const Alarm*> (msg);
82    if(!alrm) {
83       O1_LOG("\nO1 CellStateChange : Casting failed in prepareEventFields");
84       return false;
85    }
86    bool ret = true;
87
88
89    cJSON* faultFields = this->mVesEventFields;
90
91    if(JsonHelper::addNodeToObject(faultFields, "faultFieldsVersion", FAULT_FIELDS_VERSION) == 0) {
92       ret = false;
93    }
94    if(JsonHelper::addNodeToObject(faultFields, "alarmCondition", ALARM_CONDITION) == 0) {
95       ret = false;
96    }
97    if(JsonHelper::addNodeToObject(faultFields, "alarmInterfaceA", ALARM_INTERFACE_A) == 0) {
98       ret = false;
99    }
100    if(JsonHelper::addNodeToObject(faultFields, "eventSourceType", EVENT_SOURCE_TYPE) == 0) {
101       ret = false;
102    }
103    if(JsonHelper::addNodeToObject(faultFields, "specificProblem", SPECIFIC_PROBLEM) == 0) {
104       ret = false;
105    }
106    if(JsonHelper::addNodeToObject(faultFields, "eventSeverity", EVENT_SEVERITY) == 0) {
107       ret = false;
108    }   
109    if(JsonHelper::addNodeToObject(faultFields, "vfStatus", VF_STATUS) == 0) {
110       ret = false;
111    }
112    
113    cJSON* alarmAdditionalInformation = JsonHelper::createNode();
114    if(alarmAdditionalInformation == 0) {
115       O1_LOG("\nO1 CellStateChange : could not create alarmAdditionalInformation JSON object");
116       return false;
117    }
118    else if(JsonHelper::addJsonNodeToObject(faultFields, "alarmAdditionalInformation", \
119                                       alarmAdditionalInformation ) == 0) {
120       ret = false;
121    }
122    else if(JsonHelper::addNodeToObject(alarmAdditionalInformation, "eventTime", getISOEventTime().c_str()) == 0) {
123       ret = false;
124    }
125    else if(JsonHelper::addNodeToObject(alarmAdditionalInformation, "equipType", EQUIP_TYPE) == 0) {
126       ret = false;
127    }
128    else if(JsonHelper::addNodeToObject(alarmAdditionalInformation, "vendor", VENDOR) == 0) {
129       ret = false;
130    }
131    else if(JsonHelper::addNodeToObject(alarmAdditionalInformation, "model", MODEL) == 0) {
132       ret = false;
133    }
134    
135    
136    return ret;
137 }
138
139
140 /**********************************************************************
141   End of file
142  **********************************************************************/