Merge "Use env varialbes to replace image urls & tags"
[nonrtric.git] / test / usecases / oruclosedlooprecovery / goversion / stub / producer / producerstub.go
1 // -
2 //   ========================LICENSE_START=================================
3 //   O-RAN-SC
4 //   %%
5 //   Copyright (C) 2021: Nordix Foundation
6 //   %%
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
10 //
11 //        http://www.apache.org/licenses/LICENSE-2.0
12 //
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===================================
19 //
20
21 package main
22
23 import (
24         "bytes"
25         "encoding/json"
26         "net/http"
27         "time"
28
29         "oransc.org/usecase/oruclosedloop/internal/ves"
30 )
31
32 func main() {
33         message := ves.FaultMessage{
34                 Event: ves.Event{
35                         CommonEventHeader: ves.CommonEventHeader{
36                                 Domain:     "fault",
37                                 SourceName: "ERICSSON-O-RU-11220",
38                         },
39                         FaultFields: ves.FaultFields{
40                                 AlarmCondition: "28",
41                         },
42                 },
43         }
44         client := &http.Client{
45                 Timeout: 5 * time.Second,
46         }
47
48         critical := true
49         for range time.Tick(2 * time.Second) {
50                 if critical {
51                         message.Event.FaultFields.EventSeverity = "CRITICAL"
52                         critical = false
53                 } else {
54                         critical = true
55                         message.Event.FaultFields.EventSeverity = "NORMAL"
56                 }
57                 m, _ := json.Marshal(message)
58                 msgToSend, _ := json.Marshal([]string{string(m)})
59
60                 req, _ := http.NewRequest(http.MethodPost, "http://localhost:40935", bytes.NewBuffer(msgToSend))
61                 req.Header.Set("Content-Type", "application/json; charset=utf-8")
62
63                 client.Do(req)
64         }
65
66 }