NAME
Net::AppDynamics::REST - AppDynamics AnyEvent Friendly REST Client
SYNOPSIS
use Net::AppDynamics::REST;
use AnyEvent;
my $cv=AnyEvent->condvar;
my $obj=Net::AppDynamics::REST->new(PASS=>'password',USER=>'Username',SERVER=>'SERVERNAME');
# to get a list of applications in a non blocking context
my $resut=$obj->list_applications;
# get a list of applications in a non blocking context
$cv->begin;
$obj->que_list_applications(sub {
my ($self,$id,$result,$request,$response)=@_;
$cv->end;
});
$obj->agent->run_next;
$cv->recv;
DESCRIPTION
Appdynamics AnyEvent friendly Rest client.
OO Declarations
Required
USER: Sets the user appd
PASS: Sets the password
SERVER: Sets the server
Optional
logger: sets the logging object
CUSTOMER: default customer1
PORT: default 8090
PROTO: default http
use_oauth: 0
# boolean value when set to true, the PASS option is assumed to be required for OAUTH.
cache_max_age: how long to keep the cache for in seconds
default value is 3600
agent: Gets/Sets the AnyEvent::HTTP::MultiGet object we will use
oauth_slack: 10
# how much slack we give oauth before we regenerate our token
For Internal use
data_cache: Data structure used to cache object resolion
cache_check: boolean value, if true a cache check is in progress
backlog array ref of post oauth requests to run
token current auth token structure
Moo::Roles
This module makes use of the following roles: HTTP::MultiGet::Role, Log::LogMethods and Data::Result::Moo
NonBlocking interfaces
All methods with a prefix of que_xxx are considered non blocking interfaces.
Default Callback arguments:
my $code=sub {
# 0: this Net::AppDynamics::REST Object
# 1: id, for internal use
# 2: Data::Result Final object ( if failed, it will say why it failed )
# 3: HTTP::Request Last Object|undef
# 4: HTTP::Response Last Object|undef
my ($self,$id,$result,$request,$response)=@_;
};
Blocking Interfaces
All interfaces that are prefixed with que_xxx have a corisponding blocking method that is simply the xxx portion of the method name.
Example Non Blocking version of que_list_applicatinos:
my $result->list_applicatinos();
When called without the que context the methods provides the more traditional blocking style inteface. When called in a blocking context only the Data::Result Object is returned.
Application Model API
Listing Applications
Blocking context my $result=$self->list_applications
Returns a Data::Result object, when true it contains the Listing of Applications, when false it contains why it failed.
Non Blocking context my $id=$self->que_list_applicatinos($cb)
Queues a requst to fetch the list of all applications.
Example Callback:
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object };
Listing Tiers
Each Application can contain many Tiers
Blocking context my $result=$self->list_tiers($application);
Returns a Data::Result Object, when true it contains the Listing of Tiers
Non Blocking context my $id=$self->que_list_tiers($cb,$application);
Queues a request to fetch the list of tiers within a given application.
Example Callback:
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object };
Listing Tier Details
Blocking context my $result=$self->list_tier($application,$tier);
Returns a Data::Result object, when true it contains the list of tiers.
Non BLocking Context my $id=$self->que_list_tier($cb,$application,$tier);
Ques a request for the details of the application tier.
Example Callback:
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object };
Listing Busuness Transactions
Each Application can contain many business transactions.
Blocking context my $result=$self->list_business_transactions($application)
Non Blocking context my $id=$self->que_list_business_transactions($cb,$application)
Queues a request to fetch the list of business transactions for a given application
Example Callback:
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object };
List Nodes
Each Application will contain many nodes
Blocking context my $result=$self->list_nodes($application)
Returns a Data::Result object, when true it contains the list of nodes.
Non Blocking context my $id=$self->que_list_nodes($cb,$application)
Ques a request to all the nodes in a given application
Example Callback:
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object };
List Tier Nodes
Each Application Tier will contain many nodes
Blocking context my $result=$self->list_nodes($application,$tier)
Returns a Data::Result object, when true it contains the list of nodes.
Non Blocking context my $id=$self->que_list_nodes($cb,$application,$tier)
Ques a request to all the nodes in a given application
Example Callback:
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object };
Listing Node Details
Blocking context my $id=$self->list_node($application,$node)
Returns a Data::Result object
Non BLocking context my $id=$self->que_list_node($cb,$application,$node)
Queues a request to list the details of a node in a given tier
Example Callback:
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object };
Listing BackEnds
Each application can contain many backends
Non Blocking context my $id=$self->que_list_backends($cb,$application)
Returns a Data::Result Object when true, it contains the list of backends.
Non Blocking context my $id=$self->que_list_backends($cb,$application)
Queues a request to list the backends for a given application
Example Callback:
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object };
Walking The entire api
THis method walks all aspects of the appdynamics api and returns a data structure.
The structure of $result->get_data when true contains the following anonymous hash.
Objects are listed by ids
ids: Anonymous hash of ids to object refrerences
# keys used to map names to object ids
applications, business_transactions, tiers, nodes
Each element contains an anonymous hash of of an array refres
Each element in the array ref refres back to an ids object.
Blocking context my $result=$self->walk_all()
Reutruns a Data::Result Object
Non Blocking context my $id=$self->que_walk_all($cb)
Queues a request to walk everything.. $cb arguments are different in this caes, $cb is called with the following arguments. Keep in mind this walks every single object in mass and up to 20 requests are run at a time ( by default ), so this can put a strain on your controler if run too often.
my $cb=sub { my ($self,$id,$result,$request,$response,$method,$application)=@_; # 0: this Net::AppDynamics::REST Object # 1: id, for internal use # 2: Data::Result Final object ( if failed, it will say why it failed ) # 3: HTTP::Request Last Object|undef # 4: HTTP::Response Last Object|undef # 5: method ( wich method this result set is for ) # 6: application ( undef the method is list_applications ) };
Alert and Response API
Queues a health rule violation lookup
For more details, please see: https://docs.appdynamics.com/display/PRO43/Alert+and+Respond+API#AlertandRespondAPI-RetrieveAllHealthRuleViolationsinaBusinessApplication
Blocking context my $result=$self->health_rule_violations($app,%args);
Example ( defaults if no arguments are passed ):
my $result=$self->health_rule_violations($cb,"PRODUCTION",'time-range-type'=>'BEFORE_NOW','duration-in-mins'=>15);
Non Blocking context my $id=$self->que_health_rule_violations($cb,$app,%args);
Example ( defaults if no arguments are passed ):
my $id=$self->que_health_rule_violations($cb,"PRODUCTION",'time-range-type'=>'BEFORE_NOW','duration-in-mins'=>15);
Example Callback:
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object };
Configuration Import and Export API
This section documents the Configuration Import and Export API.
Blocking context my $result=$self->export_policies($app)
Non Blocking context my $id=$self->que_export_policies($cb,$app)
Queues the exporting of a policy
Example Callback:
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object };
Finding Health rule violations
See: que_health_rule_violations and que_resolve for more information.
Blocking Context my $result=$self->find_health_rule_violations($type,$name)
Returns a Data::Result Object, when true the result will cointain health rules on anything that resolved.
Non Blocking Context my $id=$self->que_find_health_rule_violations($cb,$type,$name)
Listing Metrics
Getting Metrics for an Application
Non Blocking my $result=$self->que_get_application_metric($cb,$application,,%args);
Queues a request to fetch a given metric
Example Callback:
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object };
Blocking my $result=$self->get_application_metric($application,,%args);
In a blocking context, $result contains the results when true and why it failed when false.
Resolving Objects
Used to resolve tiers, nodes, business_transactions, and applications to thier application's id.
cb: standard callback
type: String representing the typpe of object to resolve (tiers|nodes|business_transactions|applications);
name: name to be resolved
Uses the internal cache to resolve the object, if the internal cache is out of date or empty the cache will be refreshed.
Blocking context my $result=$self->resolve($type,$name);
Returns a Data::Result object, when true it contains the resolved object.
Non Blocking context my $id=$self->que_resolve($cb,$type,$name);
Example Callback:
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object };
Internal Caching
The Net::AppDynamics::REST object uses an internal cache for resolving objects. The $forceCacheRefresh is a boolean value, when set to true it forces the cache to refresh reguardless of the age of the cache.
Non BLocking context my $result=$self->que_check_cache($cb,$forceCacheRefresh);
Returns a Data::Result object, when true it contains the cache.
BLocking context my $id=$self->que_check_cache($cb,$forceCacheRefresh);
Queues a cache check. The resolve cache is refreshed if it is too old.
Example Callback:
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object };
OO Inernal OO Methods
my $url=$self->base_url
Creates the base url for a request.
my $request=$self->create_get($path,%args);
Create a request object for $path with the required arguments
my $request=$self->que_setup_token($cb)
Runs a non blocking oauth request
my ($self,$id,$result,$request,$response)=@_; # 0 Net::AppDynamics::REST Object # 1 Id of the request # 2 Data::Result Object # 3 HTTP::Request Object # 4 HTTP::Response Object
my $result=$self->setup_token()
Runs a blocking oatuh request, reutrns a Data::Result object.
\&handle_token_setup
A Hard code ref used to handle setting up of oauth tokens
$self->do_oauth_request($req,$cb)
Handles the added logic for dealing with blocking and non blocking when oauth mode is inabled.
Bugs and Patches
Please report bugs and submit patches via https://rt.cpan.org
Todo
Implement more of the api.. it is pretty extensive, patches welcome!
See Also
https://docs.appdynamics.com/display/PRO43/AppDynamics+APIs
AUTHOR
Michael Shipper mailto:AKALINUX@CPAN.ORG