Mohamed Abukar | 3e03815 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 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 | */ |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 20 | |
Mohamed Abukar | 3e03815 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 21 | package main |
| 22 | |
| 23 | import ( |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 24 | "encoding/json" |
| 25 | "fmt" |
Mohamed Abukar | b2f29a8 | 2020-03-17 09:31:55 +0200 | [diff] [blame] | 26 | "time" |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 27 | |
| 28 | clientruntime "github.com/go-openapi/runtime/client" |
| 29 | "github.com/go-openapi/strfmt" |
| 30 | "github.com/prometheus/alertmanager/api/v2/client" |
| 31 | "github.com/prometheus/alertmanager/api/v2/client/alert" |
| 32 | "github.com/prometheus/alertmanager/api/v2/models" |
| 33 | "github.com/spf13/viper" |
| 34 | |
| 35 | "gerrit.o-ran-sc.org/r/ric-plt/alarm-go/alarm" |
| 36 | app "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
Mohamed Abukar | 3e03815 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 37 | ) |
| 38 | |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 39 | func (a *AlarmManager) StartAlertTimer() { |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 40 | tick := time.Tick(time.Duration(a.alertInterval) * time.Millisecond) |
| 41 | for range tick { |
Mohamed Abukar | af0c570 | 2020-03-11 10:29:40 +0200 | [diff] [blame] | 42 | a.mutex.Lock() |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 43 | for _, m := range a.activeAlarms { |
| 44 | app.Logger.Info("Re-raising alarm: %v", m) |
Anssi Mannila | 2be5ac5 | 2020-09-22 12:17:05 +0300 | [diff] [blame] | 45 | a.PostAlert(a.GenerateAlertLabels(m.Alarm, AlertStatusActive, m.AlarmTime)) |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 46 | } |
Mohamed Abukar | af0c570 | 2020-03-11 10:29:40 +0200 | [diff] [blame] | 47 | a.mutex.Unlock() |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 51 | func (a *AlarmManager) Consume(rp *app.RMRParams) (err error) { |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 52 | app.Logger.Info("Message received!") |
| 53 | |
| 54 | defer app.Rmr.Free(rp.Mbuf) |
| 55 | switch rp.Mtype { |
| 56 | case alarm.RIC_ALARM_UPDATE: |
| 57 | a.HandleAlarms(rp) |
| 58 | default: |
| 59 | app.Logger.Info("Unknown Message Type '%d', discarding", rp.Mtype) |
| 60 | } |
| 61 | |
| 62 | return nil |
| 63 | } |
| 64 | |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 65 | func (a *AlarmManager) HandleAlarms(rp *app.RMRParams) (*alert.PostAlertsOK, error) { |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 66 | var m alarm.AlarmMessage |
Lott, Christopher (cl778h) | 3e8e2aa | 2020-06-03 08:52:14 -0400 | [diff] [blame] | 67 | app.Logger.Info("Received JSON: %s", rp.Payload) |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 68 | if err := json.Unmarshal(rp.Payload, &m); err != nil { |
| 69 | app.Logger.Error("json.Unmarshal failed: %v", err) |
| 70 | return nil, err |
| 71 | } |
| 72 | app.Logger.Info("newAlarm: %v", m) |
| 73 | |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 74 | return a.ProcessAlarm(&m) |
| 75 | } |
| 76 | |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 77 | func (a *AlarmManager) ProcessAlarm(m *alarm.AlarmMessage) (*alert.PostAlertsOK, error) { |
Mohamed Abukar | af0c570 | 2020-03-11 10:29:40 +0200 | [diff] [blame] | 78 | if _, ok := alarm.RICAlarmDefinitions[m.Alarm.SpecificProblem]; !ok { |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 79 | app.Logger.Warn("Alarm (SP='%d') not recognized, suppressing ...", m.Alarm.SpecificProblem) |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 80 | return nil, nil |
| 81 | } |
| 82 | |
| 83 | // Suppress duplicate alarms |
| 84 | idx, found := a.IsMatchFound(m.Alarm) |
Anssi Mannila | fe07bd1 | 2020-09-24 14:02:57 +0300 | [diff] [blame] | 85 | if found && m.AlarmAction == alarm.AlarmActionRaise { |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 86 | app.Logger.Info("Duplicate alarm found, suppressing ...") |
Anssi Mannila | fe07bd1 | 2020-09-24 14:02:57 +0300 | [diff] [blame] | 87 | if m.PerceivedSeverity == a.activeAlarms[idx].PerceivedSeverity { |
| 88 | // Duplicate with same severity found |
| 89 | return nil, nil |
| 90 | } else { |
| 91 | // Remove duplicate with different severity |
| 92 | a.activeAlarms = a.RemoveAlarm(a.activeAlarms, idx, "active") |
| 93 | } |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Anssi Mannila | fe07bd1 | 2020-09-24 14:02:57 +0300 | [diff] [blame] | 96 | |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 97 | // Clear alarm if found from active alarm list |
| 98 | if m.AlarmAction == alarm.AlarmActionClear { |
| 99 | if found { |
Mohamed Abukar | 3873c22 | 2020-09-21 09:54:57 +0300 | [diff] [blame] | 100 | a.alarmHistory = append(a.alarmHistory, *m) |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 101 | a.activeAlarms = a.RemoveAlarm(a.activeAlarms, idx, "active") |
Mohamed Abukar | b2f29a8 | 2020-03-17 09:31:55 +0200 | [diff] [blame] | 102 | |
| 103 | if a.postClear { |
Anssi Mannila | 2be5ac5 | 2020-09-22 12:17:05 +0300 | [diff] [blame] | 104 | return a.PostAlert(a.GenerateAlertLabels(m.Alarm, AlertStatusResolved, m.AlarmTime)) |
Mohamed Abukar | b2f29a8 | 2020-03-17 09:31:55 +0200 | [diff] [blame] | 105 | } |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 106 | } |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 107 | app.Logger.Info("No matching active alarm found, suppressing ...") |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 108 | return nil, nil |
| 109 | } |
| 110 | |
| 111 | // New alarm -> update active alarms and post to Alert Manager |
| 112 | if m.AlarmAction == alarm.AlarmActionRaise { |
Mohamed Abukar | 0c38973 | 2020-09-17 14:47:50 +0300 | [diff] [blame] | 113 | a.UpdateAlarmLists(m) |
Anssi Mannila | 2be5ac5 | 2020-09-22 12:17:05 +0300 | [diff] [blame] | 114 | return a.PostAlert(a.GenerateAlertLabels(m.Alarm, AlertStatusActive, m.AlarmTime)) |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | return nil, nil |
| 118 | } |
| 119 | |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 120 | func (a *AlarmManager) IsMatchFound(newAlarm alarm.Alarm) (int, bool) { |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 121 | for i, m := range a.activeAlarms { |
| 122 | if m.ManagedObjectId == newAlarm.ManagedObjectId && m.ApplicationId == newAlarm.ApplicationId && |
Mohamed Abukar | 0c38973 | 2020-09-17 14:47:50 +0300 | [diff] [blame] | 123 | m.SpecificProblem == newAlarm.SpecificProblem && m.IdentifyingInfo == newAlarm.IdentifyingInfo { |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 124 | return i, true |
| 125 | } |
| 126 | } |
| 127 | return -1, false |
| 128 | } |
| 129 | |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 130 | func (a *AlarmManager) RemoveAlarm(alarms []alarm.AlarmMessage, i int, listName string) []alarm.AlarmMessage { |
Mohamed Abukar | af0c570 | 2020-03-11 10:29:40 +0200 | [diff] [blame] | 131 | a.mutex.Lock() |
| 132 | defer a.mutex.Unlock() |
| 133 | |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 134 | app.Logger.Info("Alarm '%+v' deleted from the '%s' list", alarms[i], listName) |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 135 | copy(alarms[i:], alarms[i+1:]) |
| 136 | return alarms[:len(alarms)-1] |
| 137 | } |
| 138 | |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 139 | func (a *AlarmManager) UpdateAlarmLists(newAlarm *alarm.AlarmMessage) { |
Mohamed Abukar | af0c570 | 2020-03-11 10:29:40 +0200 | [diff] [blame] | 140 | a.mutex.Lock() |
| 141 | defer a.mutex.Unlock() |
| 142 | |
vipin | 541eb50 | 2020-09-22 12:04:59 +0000 | [diff] [blame] | 143 | /* If maximum number of active alarms is reached, an error log writing is made, and new alarm indicating the problem is raised. |
| 144 | The attempt to raise the alarm next time will be supressed when found as duplicate. */ |
| 145 | if len(a.activeAlarms) >= a.maxActiveAlarms { |
| 146 | app.Logger.Error("active alarm count exceeded maxActiveAlarms threshold") |
| 147 | actAlarm := a.alarmClient.NewAlarm(alarm.ACTIVE_ALARM_EXCEED_MAX_THRESHOLD, alarm.SeverityWarning, "clear alarms or raise threshold", "active alarms full") |
| 148 | actAlarmMessage := alarm.AlarmMessage{Alarm: actAlarm, AlarmAction: alarm.AlarmActionRaise, AlarmTime: (time.Now().UnixNano())} |
| 149 | a.activeAlarms = append(a.activeAlarms, actAlarmMessage) |
| 150 | a.alarmHistory = append(a.alarmHistory, actAlarmMessage) |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 151 | } |
| 152 | |
vipin | 541eb50 | 2020-09-22 12:04:59 +0000 | [diff] [blame] | 153 | if len(a.alarmHistory) >= a.maxAlarmHistory { |
| 154 | app.Logger.Error("alarm history count exceeded maxAlarmHistory threshold") |
| 155 | histAlarm := a.alarmClient.NewAlarm(alarm.ALARM_HISTORY_EXCEED_MAX_THRESHOLD, alarm.SeverityWarning, "clear alarms or raise threshold", "alarm history full") |
| 156 | histAlarmMessage := alarm.AlarmMessage{Alarm: histAlarm, AlarmAction: alarm.AlarmActionRaise, AlarmTime: (time.Now().UnixNano())} |
| 157 | a.activeAlarms = append(a.activeAlarms, histAlarmMessage) |
| 158 | a.alarmHistory = append(a.alarmHistory, histAlarmMessage) |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | // @todo: For now just keep the alarms (both active and history) in-memory. Use SDL later for persistence |
Mohamed Abukar | 0c38973 | 2020-09-17 14:47:50 +0300 | [diff] [blame] | 162 | a.activeAlarms = append(a.activeAlarms, *newAlarm) |
| 163 | a.alarmHistory = append(a.alarmHistory, *newAlarm) |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 164 | } |
| 165 | |
Anssi Mannila | 2be5ac5 | 2020-09-22 12:17:05 +0300 | [diff] [blame] | 166 | func (a *AlarmManager) GenerateAlertLabels(newAlarm alarm.Alarm, status AlertStatus, alarmTime int64) (models.LabelSet, models.LabelSet) { |
Mohamed Abukar | af0c570 | 2020-03-11 10:29:40 +0200 | [diff] [blame] | 167 | alarmDef := alarm.RICAlarmDefinitions[newAlarm.SpecificProblem] |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 168 | amLabels := models.LabelSet{ |
Mohamed Abukar | b2f29a8 | 2020-03-17 09:31:55 +0200 | [diff] [blame] | 169 | "status": string(status), |
Mohamed Abukar | af0c570 | 2020-03-11 10:29:40 +0200 | [diff] [blame] | 170 | "alertname": alarmDef.AlarmText, |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 171 | "severity": string(newAlarm.PerceivedSeverity), |
| 172 | "service": fmt.Sprintf("%s:%s", newAlarm.ManagedObjectId, newAlarm.ApplicationId), |
Mohamed Abukar | 643241f | 2020-06-09 15:26:00 +0300 | [diff] [blame] | 173 | "system_name": fmt.Sprintf("RIC:%s:%s", newAlarm.ManagedObjectId, newAlarm.ApplicationId), |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 174 | } |
| 175 | amAnnotations := models.LabelSet{ |
Mohamed Abukar | 643241f | 2020-06-09 15:26:00 +0300 | [diff] [blame] | 176 | "alarm_id": fmt.Sprintf("%d", alarmDef.AlarmId), |
| 177 | "description": fmt.Sprintf("%d:%s:%s", newAlarm.SpecificProblem, newAlarm.IdentifyingInfo, newAlarm.AdditionalInfo), |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 178 | "additional_info": newAlarm.AdditionalInfo, |
Mohamed Abukar | af0c570 | 2020-03-11 10:29:40 +0200 | [diff] [blame] | 179 | "summary": alarmDef.EventType, |
| 180 | "instructions": alarmDef.OperationInstructions, |
Anssi Mannila | 2be5ac5 | 2020-09-22 12:17:05 +0300 | [diff] [blame] | 181 | "timestamp": fmt.Sprintf("%s", time.Unix(0, alarmTime).Format("02/01/2006, 15:04:05")), |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | return amLabels, amAnnotations |
| 185 | } |
| 186 | |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 187 | func (a *AlarmManager) NewAlertmanagerClient() *client.Alertmanager { |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 188 | cr := clientruntime.New(a.amHost, a.amBaseUrl, a.amSchemes) |
| 189 | return client.New(cr, strfmt.Default) |
| 190 | } |
| 191 | |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 192 | func (a *AlarmManager) PostAlert(amLabels, amAnnotations models.LabelSet) (*alert.PostAlertsOK, error) { |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 193 | pa := &models.PostableAlert{ |
| 194 | Alert: models.Alert{ |
| 195 | GeneratorURL: strfmt.URI(""), |
| 196 | Labels: amLabels, |
| 197 | }, |
| 198 | Annotations: amAnnotations, |
| 199 | } |
| 200 | alertParams := alert.NewPostAlertsParams().WithAlerts(models.PostableAlerts{pa}) |
| 201 | |
Mohamed Abukar | 643241f | 2020-06-09 15:26:00 +0300 | [diff] [blame] | 202 | app.Logger.Info("Posting alerts: labels: %+v, annotations: %+v", amLabels, amAnnotations) |
Mohamed Abukar | af0c570 | 2020-03-11 10:29:40 +0200 | [diff] [blame] | 203 | ok, err := a.NewAlertmanagerClient().Alert.PostAlerts(alertParams) |
| 204 | if err != nil { |
| 205 | app.Logger.Error("Posting alerts to '%s/%s' failed with error: %v", a.amHost, a.amBaseUrl, err) |
| 206 | } |
| 207 | return ok, err |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 210 | func (a *AlarmManager) StatusCB() bool { |
Mohamed Abukar | 4e7e712 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 211 | if !a.rmrReady { |
| 212 | app.Logger.Info("RMR not ready yet!") |
| 213 | } |
| 214 | |
| 215 | return a.rmrReady |
Mohamed Abukar | 3e03815 | 2020-03-04 10:01:45 +0200 | [diff] [blame] | 216 | } |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 217 | |
vipin | 541eb50 | 2020-09-22 12:04:59 +0000 | [diff] [blame] | 218 | func (a *AlarmManager) ConfigChangeCB(configparam string) { |
| 219 | |
| 220 | a.maxActiveAlarms = app.Config.GetInt("controls.maxActiveAlarms") |
| 221 | a.maxAlarmHistory = app.Config.GetInt("controls.maxAlarmHistory") |
| 222 | |
| 223 | app.Logger.Debug("ConfigChangeCB: maxActiveAlarms %v", a.maxActiveAlarms) |
| 224 | app.Logger.Debug("ConfigChangeCB: maxAlarmHistory = %v", a.maxAlarmHistory) |
| 225 | |
| 226 | return |
| 227 | } |
| 228 | |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 229 | func (a *AlarmManager) Run(sdlcheck bool) { |
| 230 | app.Logger.SetMdc("alarmManager", fmt.Sprintf("%s:%s", Version, Hash)) |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 231 | app.SetReadyCB(func(d interface{}) { a.rmrReady = true }, true) |
| 232 | app.Resource.InjectStatusCb(a.StatusCB) |
vipin | 541eb50 | 2020-09-22 12:04:59 +0000 | [diff] [blame] | 233 | app.AddConfigChangeListener(a.ConfigChangeCB) |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 234 | |
vipin | 54a3a4f | 2020-09-23 12:19:58 +0000 | [diff] [blame] | 235 | alarm.RICAlarmDefinitions = make(map[int]*alarm.AlarmDefinition) |
| 236 | |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 237 | app.Resource.InjectRoute("/ric/v1/alarms", a.RaiseAlarm, "POST") |
| 238 | app.Resource.InjectRoute("/ric/v1/alarms", a.ClearAlarm, "DELETE") |
| 239 | app.Resource.InjectRoute("/ric/v1/alarms/active", a.GetActiveAlarms, "GET") |
| 240 | app.Resource.InjectRoute("/ric/v1/alarms/history", a.GetAlarmHistory, "GET") |
vipin | 541eb50 | 2020-09-22 12:04:59 +0000 | [diff] [blame] | 241 | app.Resource.InjectRoute("/ric/v1/alarms/config", a.SetAlarmConfig, "POST") |
| 242 | app.Resource.InjectRoute("/ric/v1/alarms/config", a.GetAlarmConfig, "GET") |
vipin | 54a3a4f | 2020-09-23 12:19:58 +0000 | [diff] [blame] | 243 | app.Resource.InjectRoute("/ric/v1/alarms/define", a.SetAlarmDefinition, "POST") |
| 244 | app.Resource.InjectRoute("/ric/v1/alarms/define/{alarmId}", a.DeleteAlarmDefinition, "DELETE") |
| 245 | app.Resource.InjectRoute("/ric/v1/alarms/define", a.GetAlarmDefinition, "GET") |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 246 | |
| 247 | // Start background timer for re-raising alerts |
| 248 | a.postClear = sdlcheck |
| 249 | go a.StartAlertTimer() |
vipin | 541eb50 | 2020-09-22 12:04:59 +0000 | [diff] [blame] | 250 | a.alarmClient, _ = alarm.InitAlarm("SEP", "ALARMMANAGER") |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 251 | |
| 252 | app.RunWithParams(a, sdlcheck) |
| 253 | } |
| 254 | |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 255 | func NewAlarmManager(amHost string, alertInterval int) *AlarmManager { |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 256 | if alertInterval == 0 { |
| 257 | alertInterval = viper.GetInt("controls.promAlertManager.alertInterval") |
| 258 | } |
| 259 | |
| 260 | if amHost == "" { |
| 261 | amHost = viper.GetString("controls.promAlertManager.address") |
| 262 | } |
| 263 | |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 264 | return &AlarmManager{ |
vipin | 541eb50 | 2020-09-22 12:04:59 +0000 | [diff] [blame] | 265 | rmrReady: false, |
| 266 | amHost: amHost, |
| 267 | amBaseUrl: viper.GetString("controls.promAlertManager.baseUrl"), |
| 268 | amSchemes: []string{viper.GetString("controls.promAlertManager.schemes")}, |
| 269 | alertInterval: alertInterval, |
| 270 | activeAlarms: make([]alarm.AlarmMessage, 0), |
| 271 | alarmHistory: make([]alarm.AlarmMessage, 0), |
| 272 | maxActiveAlarms: app.Config.GetInt("controls.maxActiveAlarms"), |
| 273 | maxAlarmHistory: app.Config.GetInt("controls.maxAlarmHistory"), |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
| 277 | // Main function |
| 278 | func main() { |
Abukar Mohamed | 121e8b6 | 2020-09-18 11:41:33 +0000 | [diff] [blame] | 279 | NewAlarmManager("", 0).Run(true) |
Mohamed Abukar | 540ceee | 2020-09-09 08:07:40 +0300 | [diff] [blame] | 280 | } |