b61f436ac675c3e075e1d30887ae238d0b598121
[ric-plt/alarm-go.git] / alarm / types.go
1 /*
2  *  Copyright (c) 2020 AT&T Intellectual Property.
3  *  Copyright (c) 2020 Nokia.
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  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
18  * platform project (RICP).
19  */
20
21 package alarm
22
23 import (
24         "sync"
25         "unsafe"
26         "os"
27         "fmt"
28 )
29
30 import "C"
31
32 // Severity for alarms
33 type Severity string
34
35 // Possible values for Severity
36 const (
37         SeverityUnspecified Severity = "UNSPECIFIED"
38         SeverityCritical    Severity = "CRITICAL"
39         SeverityMajor       Severity = "MAJOR"
40         SeverityMinor       Severity = "MINOR"
41         SeverityWarning     Severity = "WARNING"
42         SeverityCleared     Severity = "CLEARED"
43         SeverityDefault     Severity = "DEFAULT"
44 )
45
46 // Alarm object - see README for more information
47 type Alarm struct {
48         ManagedObjectId   string   `json:"managedObjectId"`
49         ApplicationId     string   `json:"applicationId"`
50         SpecificProblem   int      `json:"specificProblem"`
51         PerceivedSeverity Severity `json:"perceivedSeverity"`
52         AdditionalInfo    string   `json:"additionalInfo"`
53         IdentifyingInfo   string   `json:"identifyingInfo"`
54 }
55
56 // Alarm actions
57 type AlarmAction string
58
59 // Possible values for alarm actions
60 const (
61         AlarmActionRaise    AlarmAction = "RAISE"
62         AlarmActionClear    AlarmAction = "CLEAR"
63         AlarmActionClearAll AlarmAction = "CLEARALL"
64 )
65
66 type AlarmMessage struct {
67         Alarm
68         AlarmAction
69         AlarmTime int64
70 }
71
72 type AlarmConfigParams struct {
73         MaxActiveAlarms int `json:"maxactivealarms"`
74         MaxAlarmHistory int `json:"maxalarmhistory"`
75 }
76
77 // RICAlarm is an alarm instance
78 type RICAlarm struct {
79         moId       string
80         appId      string
81         managerUrl string
82         rmrCtx     unsafe.Pointer
83         rmrReady   bool
84         mutex      sync.Mutex
85 }
86
87 const (
88         RIC_ALARM_UPDATE = 13111
89         RIC_ALARM_QUERY  = 13112
90 )
91
92 // Temp alarm constants & definitions
93 const (
94         E2_CONNECTION_PROBLEM     int = 72004
95         ACTIVE_ALARM_EXCEED_MAX_THRESHOLD  int = 72007
96         ALARM_HISTORY_EXCEED_MAX_THRESHOLD int = 72008
97 )
98
99 type AlarmDefinition struct {
100         AlarmId               int    `json:"alarmId"`
101         AlarmText             string `json:"alarmText"`
102         EventType             string `json:"eventType"`
103         OperationInstructions string `json:"operationInstructions"`
104         RaiseDelay            int    `json:"raiseDelay"`
105         ClearDelay            int    `json:"clearDelay"`
106         TimeToLive            int    `json:"timeToLive"`
107 }
108
109 var RICAlarmDefinitions map[int]*AlarmDefinition
110 var RICPerfAlarmObjects map[int]*Alarm
111
112 var (
113         namespace = os.Getenv("PLT_NAMESPACE")
114         ALARM_MANAGER_HTTP_URL string = fmt.Sprintf("http://service-%s-alarmmanager-http.%s:8080", namespace, namespace) 
115         ALARM_MANAGER_RMR_URL  string = fmt.Sprintf("service-%s-alarmmanager-rmr.%s:4560", namespace, namespace)
116 )