2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import com.fasterxml.jackson.databind.JsonNode;
25 import com.fasterxml.jackson.databind.ObjectMapper;
27 import java.io.IOException;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType;
31 public class DMaaPFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
33 private static final Logger LOG = LoggerFactory.getLogger(DMaaPFaultVESMsgConsumer.class);
35 //private static int faultCounter = 0;
36 private static final String DEFAULT_SDNRUSER = "admin";
37 private static final String DEFAULT_SDNRPASSWD = "admin";
40 public void processMsg(String msg) throws Exception {
42 String faultOccurrenceTime;
47 ObjectMapper oMapper = new ObjectMapper();
48 JsonNode dmaapMessageRootNode;
50 LOG.info("Fault VES Message is - {}", msg);
52 dmaapMessageRootNode = oMapper.readTree(msg);
53 faultNodeId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue();
55 dmaapMessageRootNode.at("/event/faultFields/alarmAdditionalInformation/eventTime").textValue();
56 faultObjectId = dmaapMessageRootNode.at("/event/faultFields/alarmInterfaceA").textValue();
57 faultReason = dmaapMessageRootNode.at("/event/faultFields/specificProblem").textValue();
58 faultSeverity = dmaapMessageRootNode.at("/event/faultFields/eventSeverity").textValue();
59 faultSequence = dmaapMessageRootNode.at("/event/commonEventHeader/sequence").intValue();
62 if (faultSeverity.equalsIgnoreCase("critical")) {
63 faultSeverity = SeverityType.Critical.toString();
64 } else if (faultSeverity.equalsIgnoreCase("major")) {
65 faultSeverity = SeverityType.Major.toString();
66 } else if (faultSeverity.equalsIgnoreCase("minor")) {
67 faultSeverity = SeverityType.Minor.toString();
68 } else if (faultSeverity.equalsIgnoreCase("warning")) {
69 faultSeverity = SeverityType.Warning.toString();
70 } else if (faultSeverity.equalsIgnoreCase("nonalarmed")) {
71 faultSeverity = SeverityType.NonAlarmed.toString();
73 faultSeverity = SeverityType.NonAlarmed.toString();
76 String baseUrl = getBaseUrl();
77 String sdnrUser = getSDNRUser();
78 String sdnrPasswd = getSDNRPasswd();
80 FaultNotificationClient faultClient = getFaultNotificationClient(baseUrl);
81 faultClient.setAuthorization(sdnrUser, sdnrPasswd);
82 faultClient.sendFaultNotification(faultNodeId, Integer.toString(faultSequence), faultOccurrenceTime,
83 faultObjectId, faultReason, faultSeverity);
85 } catch (IOException e) {
86 LOG.info("Cannot parse json object ");
87 throw new Exception("Cannot parse json object", e);
91 public String getBaseUrl() {
92 return GeneralConfig.getBaseUrl();
95 public String getSDNRUser() {
96 return GeneralConfig.getSDNRUser() != null ? GeneralConfig.getSDNRUser() : DEFAULT_SDNRUSER;
99 public String getSDNRPasswd() {
100 return GeneralConfig.getSDNRPasswd() != null ? GeneralConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD;
103 public FaultNotificationClient getFaultNotificationClient(String baseUrl) {
104 return new FaultNotificationClient(baseUrl);