Go client for parsing Alertmanager config file?

49 views
Skip to first unread message

jthunder

unread,
Nov 22, 2021, 8:41:53 PM11/22/21
to Prometheus Users
Hi guys,

I'd like to modify Alertmanager config programmatically - add/remove receivers - but didn't find any reliable libraries after googling in hours.

Does anyone know some useful libraries for this? 

Thanks


Brian Candler

unread,
Nov 23, 2021, 3:02:52 AM11/23/21
to Prometheus Users
It's just YAML, so any library which parses and/or generates YAML should do.

In fact, some people just generate YAML with a plain text templating language (this is what Helm charts do).  It's a bit ugly and brittle, but if all you're doing is appending some receivers to an alertmanager config, it would work fine.

If you're worried that you may accidentally generate an invalid alertmanager config, you can run "amtool check-config" on your generated output to validate it.

Matthias Rampke

unread,
Nov 23, 2021, 3:09:33 AM11/23/21
to Brian Candler, Prometheus Users
The alertmanager's own structs are here: https://pkg.go.dev/github.com/prometheus/alertmanager/config but keep in mind that this isn't primarily intended as a library, so you may or may not be better off vendoring them.

/MR

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/839d3e00-83b6-47b3-a032-3754ff69718dn%40googlegroups.com.

Julien Pivotto

unread,
Nov 23, 2021, 4:25:51 AM11/23/21
to Matthias Rampke, Brian Candler, Prometheus Users
On 23 Nov 08:09, Matthias Rampke wrote:
> The alertmanager's own structs are here:
> https://pkg.go.dev/github.com/prometheus/alertmanager/config but keep in
> mind that this isn't primarily intended as a library, so you may or may not
> be better off vendoring them.


Alertmanager structs can't really be used easily since for security
reasons they do not unmarshal secrets.


>
> /MR
>
> On Tue, Nov 23, 2021 at 8:02 AM Brian Candler <b.ca...@pobox.com> wrote:
>
> > It's just YAML, so any library which parses and/or generates YAML should
> > do.
> >
> > In fact, some people just generate YAML with a plain text templating
> > language (this is what Helm charts do). It's a bit ugly and brittle, but
> > if all you're doing is appending some receivers to an alertmanager config,
> > it would work fine.
> >
> > If you're worried that you may accidentally generate an invalid
> > alertmanager config, you can run "amtool check-config" on your generated
> > output to validate it.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Prometheus Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to prometheus-use...@googlegroups.com.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/prometheus-users/839d3e00-83b6-47b3-a032-3754ff69718dn%40googlegroups.com
> > <https://groups.google.com/d/msgid/prometheus-users/839d3e00-83b6-47b3-a032-3754ff69718dn%40googlegroups.com?utm_medium=email&utm_source=footer>
> > .
> >
>
> --
> You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/CAMV%3D_gYJGFQ2simU8a7OBjv5VPhV7R8PAAP9rRP_Yd6h-ub%3D6A%40mail.gmail.com.

--
Julien Pivotto
@roidelapluie
Reply all
Reply to author
Forward
0 new messages