Last active
August 29, 2017 13:50
-
-
Save artifactsauce/4efa20c593f5604d2be8 to your computer and use it in GitHub Desktop.
サーバー側での処理結果をPushbulletで通知する ref: http://qiita.com/artifactsauce/items/b4165ec1229d1ce3f1dd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requires 'LWP::Protocol'; | |
requires 'LWP::Protocol::https'; | |
requires 'JSON'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo yum install perl-IO-Socket-SSL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cpanm IO::Socket::SSL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ some-command | PUSHBULLET_ACCESS_TOKEN="YOUR_ACCESS_TOKEN" /path/to/pushbullet-pushes.pl "Notification title" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUSHBULLET_ACCESS_TOKEN="YOUR_ACCESS_TOKEN" | |
0 4 1 */2 * root /path/to/letsencrypt-update.sh | /path/to/pushbullet-pushes.pl "Lets' Encrypt Updated" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Data::Dumper; | |
use HTTP::Tiny; | |
use Encode; | |
use Encode::Guess qw/shift-jis euc-jp 7bit-jis/; | |
use JSON::PP qw/encode_json decode_json/; | |
my $config = load_config( "$ENV{HOME}/.pushbullet.json" ); | |
my $access_token = $ENV{PUSHBULLET_ACCESS_TOKEN} // $config->{pushbullet_access_token} // ""; | |
my $endpoint = "https://api.pushbullet.com/v2/pushes"; | |
my $title = $ARGV[0]; | |
my $body = ""; | |
while ( <STDIN> ) { | |
chomp $_; | |
$body .= "$_\n"; | |
} | |
my $decoder = Encode::Guess->guess( $body ); | |
if ( ref $decoder ) { | |
$body = $decoder->decode( $body ); | |
} | |
my $json_data = { | |
title => $title, | |
body => $body, | |
type => "note", | |
}; | |
my $headers = { | |
'Access-Token' => $access_token, | |
'Content-Type' => 'application/json', | |
}; | |
my $ua = HTTP::Tiny->new; | |
my $response = $ua->post( $endpoint, { | |
'headers' => \%$headers, | |
'content' => encode_json( $json_data ), | |
} ); | |
unless ( $response->{success} ) { | |
print STDERR Dumper $response; | |
exit 1; | |
} | |
exit 0; | |
sub load_config { | |
my $file = shift; | |
return {} unless -f $file; | |
open my $fh, '<', $file or die $!; | |
$config = decode_json( join '', <$fh> ); | |
close $fh; | |
return $config; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUSHBULLET_ACCESS_TOKEN="YOUR_ACCESS_TOKEN" | |
0 4 1 */2 * root /path/to/something-update.sh | /path/to/pushbullet-pushes.pl "Updated something" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment