f6616a5b32745ce65f87f55c789de8f7dae5a8cf
[ric-plt/xapp-frame.git] / pkg / xapp / alarm.go
1 /*
2 ==================================================================================
3   Copyright (c) 2020 AT&T Intellectual Property.
4   Copyright (c) 2020 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 */
19
20 package xapp
21
22 import (
23         "os"
24
25         "gerrit.o-ran-sc.org/r/ric-plt/alarm-go.git/alarm"
26 )
27
28 type AlarmClient struct {
29         alarmer *alarm.RICAlarm
30 }
31
32 // NewAlarmClient returns a new AlarmClient.
33 func NewAlarmClient(moId, appId string) *AlarmClient {
34         if moId == "" {
35                 moId = "RIC"
36                 if hostname, err := os.Hostname(); err == nil {
37                         moId = hostname
38                 }
39         }
40
41         if appId == "" {
42                 appId = os.Args[0]
43         }
44
45         alarmInstance, err := alarm.InitAlarm(moId, appId)
46         if err == nil {
47                 return &AlarmClient{
48                         alarmer: alarmInstance,
49                 }
50         }
51         return nil
52 }
53
54 func (c *AlarmClient) Raise(sp int, severity alarm.Severity, identifyingInfo, additionalInfo string) error {
55         alarmData := c.alarmer.NewAlarm(sp, severity, identifyingInfo, additionalInfo)
56         return c.alarmer.Raise(alarmData)
57 }
58
59 func (c *AlarmClient) Clear(sp int, severity alarm.Severity, identifyingInfo, additionalInfo string) error {
60         alarmData := c.alarmer.NewAlarm(sp, severity, identifyingInfo, additionalInfo)
61         return c.alarmer.Clear(alarmData)
62 }
63
64 func (c *AlarmClient) Reraise(sp int, severity alarm.Severity, identifyingInfo, additionalInfo string) error {
65         alarmData := c.alarmer.NewAlarm(sp, severity, identifyingInfo, additionalInfo)
66         return c.alarmer.Reraise(alarmData)
67 }
68
69 func (c *AlarmClient) ClearAll() error {
70         return c.alarmer.ClearAll()
71 }