Last active
August 29, 2015 14:26
-
-
Save yasu47b/adcaf653b51e94d0b00a to your computer and use it in GitHub Desktop.
mojo useragentでzabbixからpng画像を取得するサンプル
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
use strict; | |
use warnings; | |
use 5.010; | |
use Data::Dumper; | |
use Mojo::UserAgent; | |
use Mojo::JSON('decode_json'); | |
my $conf = { | |
host=>'localhost', | |
user=>'admin', | |
pass=>'zabbix' | |
}; | |
my $ua = Mojo::UserAgent->new; | |
my $tx = $ua->build_tx(POST => 'http://'.$conf->{host}.'/zabbix/api_jsonrpc.php', | |
json => { | |
"method"=>"user.login", | |
"id"=>100, | |
"params"=>{ | |
"password"=> $conf->{pass}, | |
"user"=> $conf->{user}}, | |
"jsonrpc"=>"2.0"} | |
); | |
$tx->req->headers->header('Content-Type'=>'application/json-rpc'); | |
$tx = $ua->start($tx); | |
my $json = decode_json $tx->res->body; | |
my $token = $json->{result}; | |
$tx = $ua->build_tx(POST =>'http://'.$conf->{host}.'/zabbix/chart2.php?graphid=593&period=3600&stime=20150803175524&width=1024'); | |
$tx->req->cookies({name => 'zbx_sessionid', value => $token}); | |
$tx = $ua->start($tx); | |
#my $image = $tx->res->body; | |
my $image = $tx->res->content->asset->move_to('./image.png'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment