benjojo / alertmanager-discord

Take your alertmanager alerts, into discord
Apache License 2.0
177 stars 78 forks source link

webhook 9094 port: trouble with binding #12

Closed Menogus closed 3 years ago

Menogus commented 3 years ago

alermanager.xml

global:
  resolve_timeout: 5m

route:
  group_by: ['alertname', 'cluster', 'job', 'env', 'service']
  group_wait: 10s
  group_interval: 10s
  repeat_interval: 1h
  receiver: 'discord_webhook'
  routes:
  - match:
      severity: warning
    receiver: 'discord_webhook'
  - match:
      severity: critical
    receiver: 'discord_webhook'
receivers:
- name: 'null'
- name: 'discord_webhook'
  webhook_configs:
  - url: 'http://0.0.0.0:9094'

if i run alertmanager first: root@watcher:~# systemctl start alertmanager

and then docker image:

root@watcher:~# docker run -p 9094:9094 --env-file envo d6 &

i have this error:

root@watcher:~# docker: Error response from daemon: driver failed programming external connectivity on endpoint nifty_mahavira (fb4aef42f88c4340c205e6fc693cb848d9f715d40f4e624988bcddd1bda8dfb3): Error starting userland proxy: listen tcp4 0.0.0.0:9094: bind: address already in use.
ERRO[0000] error waiting for container: context canceled

[1]+  Exit 125                docker run -p 9094:9094 --env-file envo d6

if first docker, and then alertmanager, i have same trouble with 9094 port:

Jan 15 15:18:09 watcher alertmanager[1463]: level=info ts=2021-01-15T12:18:09.457Z caller=cluster.go:161 component=cluster msg="setting advertise address explicitly" addr=172.17.0.1 port=9094
Jan 15 15:18:09 watcher alertmanager[1463]: level=error ts=2021-01-15T12:18:09.458Z caller=main.go:241 msg="unable to initialize gossip mesh" err="create memberlist: Could not set up network transport: failed to obtain an address: Failed to start TCP listener on \"0.0.0.0\" port 9094: listen tcp 0.0.0.0:9094: bind:
Jan 15 15:18:09 watcher systemd[1]: alertmanager.service: Main process exited, code=exited, status=1/FAILURE
Jan 15 15:18:09 watcher systemd[1]: alertmanager.service: Failed with result 'exit-code'.

how i can solve this problem ??

benjojo commented 3 years ago

Port 9094 is for the web hook, It appears to me you are trying to run both alertmanager-discord and alertmanager itself on port 9094.

You will either want to change the ports that alertmanager-discord works on, or disable the conflicting port on alertmanager

Menogus commented 3 years ago

hm.... so, these two packages (alertmanager and alertmanager-discord) are interchangeable ? I thought alertmanager-discord is an add-on for alertmanager for discord sending... so, if i must use alertmanager-discord instead of alertmanager, i have 3 question:

  1. how to use my alermanager.xml with docker image alertmanager-discord?
  2. alertmanager-discord support email sending?
  3. for prometheus config what config i would use like:
# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093
      - localhost:9093

alertmanager-discord dont use port 9093... how do i connect to this?

benjojo commented 3 years ago

so, these two packages (alertmanager and alertmanager-discord) are interchangeable ?

Nope, However it does appear that the alertmanager HA cluster stuff (that came after alertmanager-discord) has a port conflict with alertmanager-discord.

So you have two options, Either move/disable the HA cluster alertmanager, For example my alertmanager runs with this cmdline:

/usr/bin/alertmanager --config.file /etc/alertmanager.yml --cluster.advertise-address=127.0.0.1:65000 --cluster.listen-address=127.0.0.1:9099

or you can set the LISTEN_ADDRESS and set alertmanager-discord to listen on another port.

https://github.com/benjojo/alertmanager-discord/blob/ff1f9273cb757c70cb96439761458e94de91e3b9/main.go#L77-L78

Menogus commented 3 years ago

/usr/local/bin/alertmanager --config.file /etc/alertmanager.yml --cluster.advertise-address=127.0.0.1:65000 --cluster.listen-address=127.0.0.1:9099

its works!! thanks :)

but LISTEN_ADDRESS dont work with docker image:((

i set in file envo (try all 3 times):

#LISTEN_ADDRESS=9099
#LISTEN_ADDRESS=localhost:9099
LISTEN_ADDRESS=http://localhost:9099
DISCORD_WEBHOOK=https://discord.com/api/webhooks/xxx/zzzz

after docker run -p 9094:9094 --env-file envo d6 i got 9094: 2021/01/17 08:10:20 Listening on: 0.0.0.0:9094

thanatchakromsang commented 3 years ago

@Menogus LISTEN_ADDRESS env got override If you look into base Docker image files

ENTRYPOINT ["/go/bin/alertmanager-discord", "-listen.address", "0.0.0.0:9094"]

You can override these ENTRYPOINT by supply your own startup command