irgendwr / TelegramAlert

🔔 Telegram Notification Plugin for Graylog
https://irgendwr.github.io/TelegramAlert/
MIT License
128 stars 18 forks source link

How to send value field messages to TelegramAlert #4

Closed thiennt9295 closed 6 years ago

thiennt9295 commented 6 years ago

Hi author,

I try send field message from Graylog to telegram, but i recieve null or no value message. Ex. %streamTitle%: %backlog%

#########################
%message%
Source: %source%
Source: ${source}
Facility: %facility%
Facility: ${facility}
Stream_url: %stream_url%
Stream_url: ${stream_url}

Telegram recieved:

Mongo Authentication 

#########################
%message%
Source: %source%
Source: ${source}
Facility: %facility%
Facility: ${facility}
Streamurl: %streamurl%
Streamurl: ${streamurl}
irgendwr commented 6 years ago

Hi issuecreator,

which version of the plugin do you have? I assume v2.0?

The release v2.0 implements the template engine according to the graylog documentation (read it for an explanation on how to use it). Your template is not valid since you can't directly access a messages field this way.

An alert is not triggered by one message only but can instead be triggered by no message at all or even multiple ones, this is why all the messages are stored in the backlog variable. This means that to print the source and facility of each message you have to loop over the backlog:

[${stream.title}](${stream_url}): ${alert_condition.title}
```
${foreach backlog message}
  Message: ${message.message}
  Source: ${message.source}
  Facility: ${message.fields.facility}
  Streamurl: ${stream_url}
${end}
```

Also: don't forget the surrounding ``` since the message could contain markdown characters that are used for formatting telegram messages, this way the text is formatted as a code block.

thiennt9295 commented 6 years ago

HI @irgendwr If i keep fomat as above, i can't receive message, i get error below:

at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.run(DefaultBotSession.java:187) [telegram-alert.jar:?]
2018-03-20T00:55:10.699Z ERROR [Telegram Bots Api] BOTSESSION
org.telegram.telegrambots.exceptions.TelegramApiRequestException: Error getting updates
        at org.telegram.telegrambots.api.methods.updates.GetUpdates.deserializeResponse(GetUpdates.java:119) ~[telegram-alert.jar:?]
        at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.getUpdatesFromServer(DefaultBotSession.java:256) ~[telegram-alert.jar:?]
irgendwr commented 6 years ago

You have v1.0, download the latest release.

thiennt9295 commented 6 years ago

No, i installed v2.x, lastest. Version: 2.4.3+2c41897, codename Wildwuchs Help me, Thanks.

irgendwr commented 6 years ago

I'm not talking about your graylog version, but the version of my plugin.

thiennt9295 commented 6 years ago

Great @irgendwr Thanks,