Telegram doesn´t transport alarms

Hi,

I mentioned this already in my previouse ticket, but we solved only the generel transport issue.

So the next problem i got is the not working telegram transport. If I trigger the “Test”-Button, libreNMS sends the test message to the chat it is configured to. But no alert were transportet :frowning:

I have already set thispermissions:
chown -R librenms:librenms /opt/librenms/storage/
chmod -R g+w /opt/librenms/storage

And I put user librenms in the group www-data

This is the output of ./scripts/test-alert.php:

SQL[SELECT `device_id` FROM `devices` WHERE `hostname` = 'adminvm.pvs-bw.de']
SQL[SELECT alerts.id, alerts.device_id, alerts.rule_id, alerts.state, alerts.note FROM alerts WHERE alerts.device_id = 74 && alerts.rule_id = 1]
SQL[SELECT alert_log.id,alert_log.rule_id,alert_log.device_id,alert_log.state,alert_log.details,alert_log.time_logged,alert_rules.rule,alert_rules.severity,alert_rules.extra,alert_rules.name,alert_rules.builder FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = '74' && alert_log.rule_id = '1' && alert_rules.disabled = 0 ORDER BY alert_log.id DESC LIMIT 1]
SQL[SELECT DISTINCT a.* FROM alert_rules a  LEFT JOIN alert_device_map d ON a.id=d.rule_id  LEFT JOIN alert_group_map g ON a.id=g.rule_id  LEFT JOIN device_group_device dg ON g.group_id=dg.device_group_id  WHERE a.disabled = 0 AND ((d.device_id IS NULL AND g.group_id IS NULL) OR d.device_id='74' OR dg.device_id='74')]

Warning: gzuncompress(): data error in /opt/librenms/includes/alerts.inc.php on line 691
SQL[SELECT attrib_value FROM devices_attribs WHERE attrib_type = "disable_notify" && device_id = '74']
SQL[SELECT hostname, sysName, sysDescr, sysContact, os, type, ip, hardware, version, location, purpose, notes, uptime FROM devices WHERE device_id = '74']
SQL[SELECT * FROM devices_attribs WHERE `device_id` = '74']
SQL[SELECT `timestamp`, `loss`, `min`, `max`, `avg` FROM `device_perf` WHERE `device_id` = '74' ORDER BY `timestamp` LIMIT 1]
SQL[select * from `alert_templates` where exists (select * from `alert_template_map` where `alert_templates`.`id` = `alert_template_map`.`alert_templates_id` and `alert_rule_id` = ?) limit 1 ["1"] 0.33ms]

SQL[select * from `alert_templates` where `name` = ? limit 1 ["Default Alert Template"] 0.17ms]

SQL[SELECT alert_log.id,alert_log.time_logged,alert_log.details FROM alert_log WHERE alert_log.state != 2 && alert_log.state != 0 && alert_log.rule_id = '1' && alert_log.device_id = '74' && alert_log.id < '8013' ORDER BY id DESC LIMIT 1]
SQL[UPDATE `alert_log` set `details` ='<binary data>' WHERE id = '8013']
Issuing Alert-UID #8013/0: SQL[SELECT `rule_id` FROM `alerts` WHERE `id`='5244']
SQL[SELECT b.transport_id, b.transport_type FROM alert_transport_map AS a LEFT JOIN alert_transports AS b ON b.transport_id=a.transport_or_group_id WHERE a.target_type='single' AND a.rule_id='1' UNION DISTINCT SELECT d.transport_id, d.transport_type FROM alert_transport_map AS a LEFT JOIN alert_transport_groups AS b ON a.transport_or_group_id=b.transport_group_id LEFT JOIN transport_group_transport AS c ON b.transport_group_id=c.transport_group_id LEFT JOIN alert_transports AS d ON c.transport_id=d.transport_id WHERE a.target_type='group' AND a.rule_id='1']

Warning: file_put_contents(/opt/librenms/storage/framework/views/e141bc9854ae6125d3b1d27e3e3788c9): failed to open stream: Permission denied in /opt/librenms/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php on line 122

Warning: file_put_contents(/opt/librenms/storage/framework/views/395a15bbc87b88e8696b108c335401d7): failed to open stream: Permission denied in /opt/librenms/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php on line 122
mail => SQL[SELECT `transport_config` FROM `alert_transports` WHERE `transport_id`='2']
OKSQL[SELECT `devices`.*, `lat`, `lng` FROM `devices` LEFT JOIN locations ON `devices`.`location`=`locations`.`location` WHERE `device_id` = '74']
SQL[SELECT * FROM devices_attribs WHERE `device_id` = '74']
SQL[SELECT * FROM `vrf_lite_cisco` WHERE `device_id` = '74']
SQL[INSERT INTO `eventlog` (`host`,`device_id`,`reference`,`type`,`datetime`,`severity`,`message`,`username`)  VALUES ('74','74','NULL','alert',NOW(),'1','Issued recovery for rule \'Devices up/down\' to transport \'mail\'','')]
;
Warning: file_put_contents(/opt/librenms/storage/framework/views/e141bc9854ae6125d3b1d27e3e3788c9): failed to open stream: Permission denied in /opt/librenms/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php on line 122

Warning: file_put_contents(/opt/librenms/storage/framework/views/395a15bbc87b88e8696b108c335401d7): failed to open stream: Permission denied in /opt/librenms/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php on line 122
telegram => SQL[SELECT `transport_config` FROM `alert_transports` WHERE `transport_id`='1']
string(21) "API '' returned Error"
string(8) "Params: "
string(147) "Return: {"ok":false,"error_code":400,"description":"Bad Request: can't parse entities: Unsupported start tag \"[email protected]\" at byte offset 400"}"
ERROR: HTTP Status code 400
SQL[INSERT INTO `eventlog` (`host`,`device_id`,`reference`,`type`,`datetime`,`severity`,`message`,`username`)  VALUES ('74','74','NULL','error',NOW(),'5','Could not issue recovery for rule \'Devices up/down\' to transport \'telegram\' Error: HTTP Status code 400','')]
;

In your template (default one I guess) remove the < > from the last line:

Alert sent to: {foreach %contacts}%value < %key > {/foreach}

To be

Alert sent to: {foreach %contacts}%value %key {/foreach}

This solve my issue for telegram transports. Thanks!

And the fix has been merged, so you should be able to add again the < > if its visually better for you.

OK, this solved my issue. Thanks!

Great support :slight_smile:

OK, one more problem :frowning:

I have defined transport for mail and telegram. Both transports are working if a device generates an alert but the recovery message is only sent via telegram.

Any suggestions?

config error :roll_eyes:

Hi, so this is a reason why the support for html tags for telegram was reverted.

I think that we can use that html tags in our telegram transport. I know that there is no support for all html tags, but i believe that is better to edit default template in docs where is a problem with sending alert in this line:

@foreach ($alert->contacts as $key => $value)
  {{ $value }} <{{ $key }}>
@endforeach

and use a html tags which is possible in telegram alerts. instead of the line with information, which i think is not very needed. For example I just want to know when is device down or something like that and I dont want to read a lot of text of it.

There is a list of html tags supported for telegram:

<b>bold</b>, <strong>bold</strong>
<i>italic</i>, <em>italic</em>
<a href="http://www.example.com/">inline URL</a>
<a href="tg://user?id=123456789">inline mention of a user</a>
<code>inline fixed-width code</code>
<pre>pre-formatted fixed-width code block</pre>

and here is how I use it. It is in slovak language but I think it i better to read alerts with that tags

and here is an alert template for that telegram message. I edited it to english for you

@if ($alert->state == 1)❗️ Device <b>{{ $alert->hostname }}</b> is DOWN @endif @if ($alert->state == 2)⚠️ Acknowledged @endif @if ($alert->state == 3)⚠️ Recovering @endif @if ($alert->state == 0)✅ Device <b>{{ $alert->hostname }}</b> is UP @endif 
   <b>Time:</b> {{ $alert->timestamp }}
   <b>Last uptime</b>: {{ $alert->uptime_long }}
   <b>Time elapsed:</b> {{ $alert->elapsed }}
    <b>Location:</b> {{ $alert->location }}

So what do you think ?

1 Like