2017年7月19日 星期三

Zabbix 3.0.x 整合 Line Alert 圖解



Zabbix 3.0.x 整合 Line Alert 圖解,下方有 Perl 的範例程式,可供參考,
使用其的慣用程式也行,至於 Line API 的使用方式可參考下面的其它參考資訊,
或見 https://github.com/line





































































Demo



























其它參考資訊

http://xrcd2.blogspot.tw/2016/12/perl-line-api.html
http://xrcd2.blogspot.tw/2017/07/line-api-emoticons.html

Demo Perl Shell:

[root@CentOS73 shell]# pwd
/usr/local/zabbix/shell
[root@CentOS73 shell]# cat line.pl
#!/usr/local/perl-5.26/bin/perl
# Line
#recipient = sys.argv[1]  $ARGV[0]
#subject = sys.argv[2]    $ARGV[1]
#body = sys.argv[3]       $ARGV[2]

$myid="$ARGV[0]";
$subj="$ARGV[1]";
$body="$ARGV[2]";

use LINE::Bot::API;
use LINE::Bot::API::Builder::SendMessage;
$bot = LINE::Bot::API->new(
 channel_secret => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
 channel_access_token => 'xxxxxxxxxxxxxxxxxxxxxx',
);

$messages = LINE::Bot::API::Builder::SendMessage->new;
$messages->add_text( text => "$subj \r\n \r\n $body " );
$bot->push_message($myid, $messages->build);
[root@CentOS73 shell]#


2017年7月14日 星期五

line API emoticons 試用

為解一個 line API 傳送文字的限制,在官網上看到的資訊,
順便玩玩這個  emoticons 功能.
官網上的 URL 為 https://devdocs.line.me/en/#send-message-object

Send message object

JSON object which contains the contents of the message you send.

Text
Image
Video
Audio
Location
Sticker
Imagemap
Template
Text

Text example
{
    "type": "text",
    "text": "Hello, world"
}
Field Type Required Description
type String Yes text
text String Yes Message text
Max: 2000 characters
Text example with emoticon

{
    "type": "text",
    "text": "Hello, world 􀂲"
}
You can include emoticons in your message text. Because emoticons are
a part of Unicode, they must be converted from their character codes.
Note that the character code, 0x1000B2, is used in the example on the
right. Although the emoticon does not show up correctly in the browser,
it will show up in LINE.
For a list of emoticons that can be sent with the Messaging API,
see emoticon list.

https://devdocs.line.me/files/emoticon.pdf

perl 的用法可參考
http://www.drdobbs.com/web-development/unicode-in-perl/184416148 

https://github.com/patch-orphan/text-emoticon-unicode-pm5


加上 https://github.com/line/line-bot-sdk-perl

所以可以加以變化成 如下的程式.....

[root@CentOS73 bin]# cat Send-Line-Message.pl
#!/usr/local/perl-5.26/bin/perl
use LINE::Bot::API;
use LINE::Bot::API::Builder::SendMessage;

$bot = LINE::Bot::API->new(
    channel_secret       => 'xxxxxxxxxxxxxxxxxxxxxxxxx',
    channel_access_token => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=',
);


use Text::Emoticon;
$emoticon = Text::Emoticon->new('Unicode');
$msg = $emoticon->filter('Howdy :) :( ');


$ToLineUid = 'Uxxxxxxxxxxxxxxxxxxxxxxxxxxxx';


$messages = LINE::Bot::API::Builder::SendMessage->new;
$messages->add_text( text => "Example push text \r\n $msg \x{1F480}" );
$bot->push_message($ToLineUid, $messages->build);
[root@CentOS73 bin]#

Demo



其它參考資訊

http://unicode.org/emoji/charts/full-emoji-list.html

http://xrcd2.blogspot.tw/2016/12/perl-line-api.html