matrix-alertmanager icon indicating copy to clipboard operation
matrix-alertmanager copied to clipboard

Improve usage with Prometheus-Operator

Open Timoses opened this issue 2 years ago • 6 comments

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.

Timoses avatar Oct 31 '23 16:10 Timoses

Addresses existing issue: https://github.com/jaywink/matrix-alertmanager/issues/23

Timoses avatar Nov 02 '23 07:11 Timoses

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
             }
         }

siretart avatar Feb 02 '24 11:02 siretart

@Timoses your PR misses to update the .env.default file, which continues to suggest the old / syntax as example.

siretart avatar Feb 02 '24 11:02 siretart

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?

Timoses avatar Feb 04 '24 11:02 Timoses

If yes, I'd also

  • [ ] add a fitting / adjust example in the .env.default file.

Timoses avatar Feb 04 '24 11:02 Timoses

i took the liberty of creating another PR https://github.com/jaywink/matrix-alertmanager/pull/44

siretart avatar Feb 05 '24 11:02 siretart

Closing as #44 implemented this in a backwards compatible way.

jaywink avatar Sep 14 '24 22:09 jaywink