Hi haukex,
in my private environment I follow some logfiles by File::Tail and report lines of interest to some TELEGRAM Channel via WWW::Telegram::BotAPI.
The TELEGRAM API knows some forms of limited formatting of the string to send. One of the formatting options is called "HTML", although there are only 3 or 4 fomatting tags similar to the HTML tags.
One e.g. is:
<strong>xxx</strong>
The example I gave is very much the same as a real logfile line. But if you wish I can give a real example:
$av_tmp_LINE = "Jun 3 23:20:05 f42252s5 postfix/pickup[204714]: E1E63
+A045C: uid=33 from=<www-data>"
$av_tmp_STRING = "Logfile: " . "<strong>" . $av_obj_TMP->{input} . "</
+strong>" . " " . $av_tmp_LINE;
Now the string $av_tmp_STRING should be sent to the TELEGRAM Channel using "HTML" formatting.
But unfotunately inside the string there is the "<www-data>" which looks like a formatting string, but is unsupported.
This causes the module to abort, although eval is used.
Messge:
"Request failed with error 'ERROR: code 400: Bad Request: can't parse
+entities: Unsupported start tag "www" at byte offset 53 at /usr/share
+/perl5/WWW/Telegram/BotAPI.pm line 224. WWW::Telegram::BotAPI::api_re
+quest(undef, undef, HASH(0x55e57ea8da98)) called at ./av_perlre.pl li
+ne 268 eval {...} called at ./av_perlre.pl line 266 ', but I'm still
+alive! at ./av_perlre.pl line 266."
Since I am not a very experience programmer, I probably have done something wrong. I have already reported the issue to the module creator.
My Code:
$av_std_RETVAL = eval
{
$av_obj_TGRAM->sendMessage (
{
chat_id => $av_loc_tgram_CHATID,
text => $av_tmp_STRING,
disable_notification => 'false',
parse_mode => 'HTML',
}
)
}
or warn "Request failed with error '$@', but I'm still alive!";
This is according to the docu. The docu says, by using eval the way above, the program will not abort - but it does.
|