Skip to content

Commit 8a80ed9

Browse files
committed
Update IGL for Notifications Changes
Synchronize codebase against latest version of Icinga/icinga-go-library#145, containing package changes.
1 parent 03bc099 commit 8a80ed9

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6
88
github.com/emersion/go-smtp v0.24.0
99
github.com/google/uuid v1.6.0
10-
github.com/icinga/icinga-go-library v0.7.3-0.20250807134650-55c038b220d8
10+
github.com/icinga/icinga-go-library v0.7.3-0.20250904130608-5032573a325e
1111
github.com/jhillyerd/enmime v1.3.0
1212
github.com/jmoiron/sqlx v1.4.0
1313
github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
3535
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
3636
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
3737
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
38-
github.com/icinga/icinga-go-library v0.7.2 h1:6ilUeE9F9OqxxJXNR9URWDf6zOqsdhjjR9w1MUXY9Kg=
39-
github.com/icinga/icinga-go-library v0.7.2/go.mod h1:HZTiYD+N+9FZIVpPdUEJWJnc6sLvrIRO03jvkdkmUEU=
40-
github.com/icinga/icinga-go-library v0.7.3-0.20250807134650-55c038b220d8 h1:YStwl7OlLUN87ROcZ8LQRTDKBhEx0V7EX5+5OMRwEnM=
41-
github.com/icinga/icinga-go-library v0.7.3-0.20250807134650-55c038b220d8/go.mod h1:6xgV9o7JcGVg2I6CzPfefQZF4Ev8QeZnysiu82YaRY4=
38+
github.com/icinga/icinga-go-library v0.7.3-0.20250904130608-5032573a325e h1:yZPWPPCHKozWRm9VedDHd8igJh9uI4U2CJdgl1On+/4=
39+
github.com/icinga/icinga-go-library v0.7.3-0.20250904130608-5032573a325e/go.mod h1:exEJdfik2GPYrvZM6Gn4BXIBLIGg6OrCCMnILT+mTUs=
4240
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056 h1:iCHtR9CQyktQ5+f3dMVZfwD2KWJUgm7M0gdL9NGr8KA=
4341
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056/go.mod h1:CVKlgaMiht+LXvHG173ujK6JUhZXKb2u/BQtjPDIvyk=
4442
github.com/jessevdk/go-flags v1.6.1 h1:Cvu5U8UGrLay1rZfv/zP7iLpSHGUZ/Ou68T0iX1bBK4=

internal/config/runtime.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"fmt"
88
"github.com/icinga/icinga-go-library/database"
99
"github.com/icinga/icinga-go-library/logging"
10-
"github.com/icinga/icinga-go-library/notifications"
10+
"github.com/icinga/icinga-go-library/notifications/source"
1111
"github.com/icinga/icinga-go-library/types"
1212
"github.com/icinga/icinga-notifications/internal/channel"
1313
"github.com/icinga/icinga-notifications/internal/recipient"
@@ -171,17 +171,17 @@ func (r *RuntimeConfig) GetRuleEscalation(escalationID int64) *rule.Escalation {
171171
// If the source does not have any rules associated with it, the version will be set to notifications.EmptyRulesVersion.
172172
//
173173
// May not be called while holding the write lock on the RuntimeConfig.
174-
func (r *RuntimeConfig) GetRulesVersionFor(source int64) string {
174+
func (r *RuntimeConfig) GetRulesVersionFor(srcId int64) string {
175175
r.RLock()
176176
defer r.RUnlock()
177177

178178
if r.RulesBySource != nil {
179-
if sourceInfo, ok := r.RulesBySource[source]; ok && sourceInfo.Version > 0 {
179+
if sourceInfo, ok := r.RulesBySource[srcId]; ok && sourceInfo.Version > 0 {
180180
return fmt.Sprintf("%x", sourceInfo.Version)
181181
}
182182
}
183183

184-
return notifications.EmptyRulesVersion
184+
return source.EmptyRulesVersion
185185
}
186186

187187
// GetContact returns *recipient.Contact by the given username (case-insensitive).
@@ -215,20 +215,20 @@ func (r *RuntimeConfig) GetSourceFromCredentials(user, pass string, logger *logg
215215
return nil
216216
}
217217

218-
source, ok := r.Sources[sourceId]
218+
src, ok := r.Sources[sourceId]
219219
if !ok {
220220
logger.Debugw("Cannot check credentials for unknown source ID", zap.Int64("id", sourceId))
221221
return nil
222222
}
223223

224-
if !source.ListenerPasswordHash.Valid {
224+
if !src.ListenerPasswordHash.Valid {
225225
logger.Debugw("Cannot check credentials for source without a listener_password_hash", zap.Int64("id", sourceId))
226226
return nil
227227
}
228228

229229
// If either PHP's PASSWORD_DEFAULT changes or Icinga Web 2 starts using something else, e.g., Argon2id, this will
230230
// return a descriptive error as the identifier does no longer match the bcrypt "$2y$".
231-
err = bcrypt.CompareHashAndPassword([]byte(source.ListenerPasswordHash.String), []byte(pass))
231+
err = bcrypt.CompareHashAndPassword([]byte(src.ListenerPasswordHash.String), []byte(pass))
232232
if errors.Is(err, bcrypt.ErrMismatchedHashAndPassword) {
233233
logger.Debugw("Invalid password for this source", zap.Int64("id", sourceId))
234234
return nil
@@ -237,7 +237,7 @@ func (r *RuntimeConfig) GetSourceFromCredentials(user, pass string, logger *logg
237237
return nil
238238
}
239239

240-
return source
240+
return src
241241
}
242242

243243
func (r *RuntimeConfig) fetchFromDatabase(ctx context.Context) error {

internal/listener/listener.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"fmt"
99
"github.com/icinga/icinga-go-library/database"
1010
"github.com/icinga/icinga-go-library/logging"
11-
"github.com/icinga/icinga-go-library/notifications"
1211
baseEv "github.com/icinga/icinga-go-library/notifications/event"
12+
"github.com/icinga/icinga-go-library/notifications/source"
1313
"github.com/icinga/icinga-notifications/internal"
1414
"github.com/icinga/icinga-notifications/internal/config"
1515
"github.com/icinga/icinga-notifications/internal/daemon"
@@ -124,30 +124,30 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, r *http.Request) {
124124
return
125125
}
126126

127-
source, validAuth := l.sourceFromAuthOrAbort(w, r)
127+
src, validAuth := l.sourceFromAuthOrAbort(w, r)
128128
if !validAuth {
129129
return
130130
}
131131

132-
ruleIdsStr := r.Header.Get(notifications.XIcingaRulesId)
133-
ruleVersion := r.Header.Get(notifications.XIcingaRulesVersion)
132+
ruleIdsStr := r.Header.Get(source.XIcingaRulesId)
133+
ruleVersion := r.Header.Get(source.XIcingaRulesVersion)
134134

135135
// If the client uses an outdated rules version, reject the request but send also the current rules version
136136
// and rules for this source back to the client, so it can retry the request with the updated rules.
137-
if latestRuleVersion := l.runtimeConfig.GetRulesVersionFor(source.ID); ruleVersion != latestRuleVersion {
137+
if latestRuleVersion := l.runtimeConfig.GetRulesVersionFor(src.ID); ruleVersion != latestRuleVersion {
138138
w.WriteHeader(http.StatusPreconditionFailed)
139-
l.writeSourceRulesInfo(w, source)
139+
l.writeSourceRulesInfo(w, src)
140140

141141
l.logger.Debugw("Abort event processing due to outdated rules version",
142142
zap.String("current_version", latestRuleVersion),
143143
zap.String("provided_version", ruleVersion),
144-
zap.String("source", source.Name))
144+
zap.String("source", src.Name))
145145
return
146146
}
147147

148148
var ev event.Event
149149
if err := ev.LoadMatchedRulesFromString(ruleIdsStr); err != nil {
150-
abort(http.StatusBadRequest, nil, "cannot parse %s header: %v", notifications.XIcingaRulesId, err)
150+
abort(http.StatusBadRequest, nil, "cannot parse %s header: %v", source.XIcingaRulesId, err)
151151
return
152152
}
153153

@@ -157,7 +157,7 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, r *http.Request) {
157157
}
158158

159159
ev.Time = time.Now()
160-
ev.SourceId = source.ID
160+
ev.SourceId = src.ID
161161
if ev.Type == baseEv.TypeUnknown {
162162
ev.Type = baseEv.TypeState
163163
} else if !ev.Mute.Valid && ev.Type == baseEv.TypeMute {

0 commit comments

Comments
 (0)