matrix-alertmanager
matrix-alertmanager copied to clipboard
Improve usage with Prometheus-Operator
Prometheus-Operator prepends the following the all receiver names: <namespace>/<alertmanager-instance-name>/
Since MATRIX_ROOMS currently uses / as a separator for <RECEIVER>/<MATRIX_ROOM_ID> matrix-alertmanager can currently not be used with Prometheus-Operator.
I suggest replacing '/' with ';' in MATRIX_ROOMS env var.
Addresses existing issue: https://github.com/jaywink/matrix-alertmanager/issues/23
Here is an alternative implementation that keeps the / as separator:
master ec5d8a5321256fc537959f08d6b407d70e2f6284
Author: Reinhard Tartler <[email protected]>
AuthorDate: Thu Feb 1 06:35:08 2024 -0500
Commit: Reinhard Tartler <[email protected]>
CommitDate: Fri Feb 2 06:07:08 2024 -0500
Parent: 1b1d470 Release v0.7.2
Merged: master
Contained: master
Follows: v0.7.2 (1)
handle receivers that contain '/'
2 files changed, 7 insertions(+), 6 deletions(-)
src/client.js | 7 ++++---
src/utils.js | 6 +++---
modified src/client.js
@@ -30,9 +30,10 @@ const client = {
const joinedRooms = rooms.joined_rooms
const roomConfigs = process.env.MATRIX_ROOMS.split('|')
roomConfigs.forEach(async roomConfig => {
- const room = roomConfig.split('/')
- if (joinedRooms.indexOf(room[1]) === -1) {
- await this.ensureInRoom(room[1])
+ const i = roomConfig.lastIndexOf('/')
+ const room = roomConfig.slice(i+1)
+ if (joinedRooms.indexOf(room) === -1) {
+ await this.ensureInRoom(room)
}
})
},
modified src/utils.js
@@ -14,9 +14,9 @@ const utils = {
const roomConfigs = process.env.MATRIX_ROOMS.split('|')
let roomId = false
for (let config of roomConfigs) {
- const roomConfig = config.split('/')
- if (roomConfig[0] === receiver) {
- roomId = roomConfig[1]
+ const i = config.lastIndexOf('/')
+ if (config.slice(0, i) === receiver) {
+ roomId = config.slice(i+1)
break
}
}
@Timoses your PR misses to update the .env.default file, which continues to suggest the old / syntax as example.
Here is an alternative implementation that keeps the
/as separator:master ec5d8a5321256fc537959f08d6b407d70e2f6284 Author: Reinhard Tartler <[email protected]> AuthorDate: Thu Feb 1 06:35:08 2024 -0500 Commit: Reinhard Tartler <[email protected]> CommitDate: Fri Feb 2 06:07:08 2024 -0500 Parent: 1b1d470 Release v0.7.2 Merged: master Contained: master Follows: v0.7.2 (1) handle receivers that contain '/' 2 files changed, 7 insertions(+), 6 deletions(-) src/client.js | 7 ++++--- src/utils.js | 6 +++--- modified src/client.js @@ -30,9 +30,10 @@ const client = { const joinedRooms = rooms.joined_rooms const roomConfigs = process.env.MATRIX_ROOMS.split('|') roomConfigs.forEach(async roomConfig => { - const room = roomConfig.split('/') - if (joinedRooms.indexOf(room[1]) === -1) { - await this.ensureInRoom(room[1]) + const i = roomConfig.lastIndexOf('/') + const room = roomConfig.slice(i+1) + if (joinedRooms.indexOf(room) === -1) { + await this.ensureInRoom(room) } }) }, modified src/utils.js @@ -14,9 +14,9 @@ const utils = { const roomConfigs = process.env.MATRIX_ROOMS.split('|') let roomId = false for (let config of roomConfigs) { - const roomConfig = config.split('/') - if (roomConfig[0] === receiver) { - roomId = roomConfig[1] + const i = config.lastIndexOf('/') + if (config.slice(0, i) === receiver) { + roomId = config.slice(i+1) break } }
Thanks siretart. Since above implementation does not require existing configurations to change, it seems preferable over my suggestion. @siretart Do you mind if I use your suggestion for the PR?
If yes, I'd also
- [ ] add a fitting / adjust example in the
.env.defaultfile.
i took the liberty of creating another PR https://github.com/jaywink/matrix-alertmanager/pull/44
Closing as #44 implemented this in a backwards compatible way.