forked from roa/pabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert Abraham
committed
Sep 3, 2012
1 parent
ae7a024
commit 725defe
Showing
5 changed files
with
131 additions
and
63 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package Pabbix::Auth; | ||
|
||
use strict; | ||
use warnings; | ||
use Moo; | ||
use Pabbix::Request; | ||
|
||
sub getAuthToken | ||
{ | ||
my $self = shift; | ||
my $json = { | ||
jsonrpc => "2.0", | ||
method => "user.authenticate", | ||
params => { | ||
user => $self->user, | ||
password => $self->passwd | ||
}, | ||
id => "0" | ||
}; | ||
|
||
my $response = Pabbix::Request->new( | ||
url => $self->url, | ||
json => $json, | ||
); | ||
return $response->makeReq()->{'result'}; | ||
} | ||
|
||
has url => ( | ||
is => 'ro', | ||
); | ||
|
||
has user => ( | ||
is => 'ro', | ||
); | ||
|
||
has passwd => ( | ||
is => 'ro', | ||
); | ||
|
||
1; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package Pabbix::Request; | ||
|
||
use strict; | ||
use warnings; | ||
use Moo; | ||
use LWP::UserAgent; | ||
use JSON::XS; | ||
|
||
sub makeReq | ||
{ | ||
my $self = shift; | ||
my $req = HTTP::Request->new( POST => ($self->url) ); | ||
$req->content( encode_json( $self->json ) ); | ||
my $ua = LWP::UserAgent->new; | ||
$ua->timeout(10); | ||
|
||
$req->content_type( 'application/json-rpc' ); | ||
my $response = $ua->request($req); | ||
if( $response->is_success ) | ||
{ | ||
return decode_json( $response->decoded_content ); | ||
} | ||
else | ||
{ | ||
die $response->status_line; | ||
} | ||
} | ||
|
||
has url => ( | ||
is => 'ro', | ||
); | ||
|
||
has json => ( | ||
is => 'ro' | ||
); | ||
|
||
1; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package Pabbix::Trigger; | ||
|
||
use strict; | ||
use warnings; | ||
use Moo; | ||
use Pabbix::Request; | ||
|
||
sub getTrigger | ||
{ | ||
my $self = shift; | ||
my $json = { | ||
jsonrpc => "2.0", | ||
method => "trigger.get", | ||
params => { | ||
output => "extend", | ||
expandData => "host", | ||
filter => { | ||
value => 1 | ||
} | ||
}, | ||
auth => $self->authToken, | ||
id => 0 | ||
}; | ||
|
||
my $response = Pabbix::Request->new( | ||
url => $self->url, | ||
json => $json, | ||
); | ||
return $response->makeReq(); | ||
} | ||
|
||
has url => ( | ||
is => 'ro', | ||
); | ||
|
||
has authToken => ( | ||
is => 'ro', | ||
); | ||
|
||
1; |