alerta / alerta-contrib

Contributed integrations, plugins and custom webhooks
http://alerta.io
MIT License
119 stars 170 forks source link

Telegram callback_data length limit for blackuot button #309

Closed sotona- closed 4 years ago

sotona- commented 4 years ago

Issue Summary Telegram plugin can set an inline_keyboard for ack, close and blackout buttons. Callback_data for each button is limited to 64 bytes. Ack and Close buttons use fixed length("/[ack|close] event_uuid"), but Blackout button data can easily exceed the limit, b.c. it contains environment name, host name and alert rule name.

Environment docker image alerta-web:7.4.1

To Reproduce

  1. configure alerta with telegram plugin and TELEGRAM_WEBHOOK_URL
  2. create a host with 27 symbols name
  3. create an alert rule with 18 symbols name
  4. make an alert. Blackout button data will be like a: /blackout Production|hostname.mycompany.com:9182|windows_low_memory with 67 bytes length.
  5. telegram api will reply 400 code
satterly commented 4 years ago

Sorry but this sounds like a limitation with Telegram. Do you have a suggested fix?

jjh74 commented 4 years ago

Would something like this work: send inline-keyboard with /blackout + alert.id

and in https://github.com/alerta/alerta/blob/master/alerta/webhooks/telegram.py#L88 lookup env, resource and event from alert(id) ?

satterly commented 4 years ago

no because Alerta can't know which of the relevant attributes the operator wanted to define for the blackout period. ie. resource or event or env or all or others.

jjh74 commented 4 years ago

Hmm, I must be missing something here. This is how I understand this works:

  1. alerta sends an alert to telegram (with inline keyboard with callback_data: '/blackout Production|hostname.mycompany.com:9182|windows_low_memory' (these are always set to alert.environment, alert.resource and alert.event)).
  2. User(operator) clicks blackout button for this alert on telegram
  3. telegram sends POST to /webhooks/telegram with callback_data (from step1).
  4. telegram webhook parses callback_data and extracts environment, resource and event and creates blackout:
    blackout = Blackout(environment, resource=resource, event=event)
    blackout.create()

    So what I don't understand is that why can't step1 just send callback_data: '/blackout alert_id' and step4 do:

    alert = Alert.find_by_id(alert_id, customers=customers)
    blackout = Blackout(alert.environment, resource=alert.resource, event=alert.event)

    since operator can't choose/change blackout values that come in the callback_data ?

jjh74 commented 4 years ago

I think https://github.com/alerta/alerta/blob/master/alerta/webhooks/telegram.py#L88 might be wrong:

satterly commented 4 years ago

@jjh74 I've looked at this again and you are right about just sending the alert ID and extracting the environment, resource and event to generate the blackout period.