2 // ========================LICENSE_START=================================
5 // Copyright (C) 2021: Nordix Foundation
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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 // ========================LICENSE_END===================================
32 var r = rand.New(rand.NewSource(time.Now().UnixNano()))
34 type FaultMessage struct {
35 Event Event `json:"event"`
39 CommonEventHeader CommonEventHeader `json:"commonEventHeader"`
40 FaultFields FaultFields `json:"faultFields"`
43 type CommonEventHeader struct {
44 Domain string `json:"domain"`
45 SourceName string `json:"sourceName"`
48 type FaultFields struct {
49 AlarmCondition string `json:"alarmCondition"`
50 EventSeverity string `json:"eventSeverity"`
54 port := flag.Int("port", 3905, "The port this message router will listen on")
57 http.HandleFunc("/events/unauthenticated.SEC_FAULT_OUTPUT/dmaapmediatorproducer/STD_Fault_Messages", handleData)
59 fmt.Print("Starting mr on port: ", *port)
60 fmt.Println(http.ListenAndServeTLS(fmt.Sprintf(":%v", *port), "../../security/producer.crt", "../../security/producer.key", nil))
66 func handleData(w http.ResponseWriter, req *http.Request) {
67 time.Sleep(time.Duration(r.Intn(3)) * time.Second)
69 w.Header().Set("Content-Type", "application/json")
71 var responseBody []byte
73 responseBody = getFaultMessage("CRITICAL")
74 fmt.Println("Sending CRITICAL")
77 responseBody = getFaultMessage("NORMAL")
78 fmt.Println("Sending NORMAL")
81 fmt.Fprint(w, string(responseBody))
84 func getFaultMessage(eventSeverity string) []byte {
85 linkFailureMessage := FaultMessage{
87 CommonEventHeader: CommonEventHeader{
89 SourceName: "ERICSSON-O-RU-11220",
91 FaultFields: FaultFields{
93 EventSeverity: eventSeverity,
97 fmt.Printf("Sending message: %v\n", linkFailureMessage)
99 messageAsByteArray, _ := json.Marshal(linkFailureMessage)
100 response := [1]string{string(messageAsByteArray)}
101 responseAsByteArray, _ := json.Marshal(response)
102 return responseAsByteArray