SlideShare a Scribd company logo
Advanced REST API Scripting
Todd Radel
Senior Manager, Enablement and Adoption
About Me
Todd Radel
SENIOR MANAGER
ENABLEMENT & ADOPTION, US EAST
• More than 20 years experience in the
software industry
• Java, .NET, Python, Perl
• Author of the Python SDK for
AppDynamics REST API
• Author of six AppDynamics Extensions:
F5, Tibco EMS, Redis, Keynote, SQL,
URL Monitor
Copyright © 2014 AppDynamics. All rights reserved. 2
tradel@appdynamics.com
+1 (484) 857-2335
tradel
todd.radel
linkedin.com/in/tradel
Today’s Agenda
Copyright © 2014 AppDynamics. All rights reserved. 3
1
2 Installing and using the Python SDK
3 Reporting on license usage
Hello World (in 3 languages!)
BUILDING ON THE FIRST REST API WEBINAR, WE WILL SHOW
YOU HOW TO SCRIPT AND AUTOMATE COMMON TASKS
4 DevOps integration – disabling health rules
during code deployment
Hello World
Hello World
OBJECTIVE
• Retrieve a list of business applications from the controller
• Print to stdout
FLAVORS
• Bash/cURL
• PowerShell
• Python – The Hard Way
• Python – The Easy Way
Copyright © 2014 AppDynamics. All rights reserved. 5
Bash and cURL
#! /bin/bash
# Print the list of tiers for an application
curl -X GET -u user1@customer1:welcome
"http://localhost:8080/controller/rest/applications?output=jso
n"
Copyright © 2014 AppDynamics. All rights reserved. 6
Windows PowerShell
# Print the list of tiers for an application
$usr="user1@customer1"
$pwd="welcome"
$headers = @{
Authorization = "Basic " +
[System.Convert]::ToBase64String(
[System.Text.Encoding]::ASCII.GetBytes(
"$($usr):$($pwd)"))
}
$url="http://localhost:8080/controller/rest/applications?outpu
t=json"
$response = Invoke-RestMethod $url -Headers $Headers
$response | ForEach-Object { [string]$_.id + " " + $_.name }
Python – The Hard Way
#! /usr/bin/env python
# Print the list of tiers for an application
import requests
usr = "user1@customer1"
pwd = "welcome"
url =
"http://localhost:8080/controller/rest/applications?output=jso
n"
response = requests.get(url, auth=(usr, pwd))
json = response.json()
for app in json:
print app['id'], app['name']
Copyright © 2014 AppDynamics. All rights reserved. 8
Python – The Easy Way
#! /usr/bin/env python
# Print the list of tiers for an application
from appd.request import AppDynamicsClient
c = AppDynamicsClient("http://localhost:8080",
"user1", "welcome")
for app in c.get_applications():
print app.id, app.name
# Wasn’t that easy?
Copyright © 2014 AppDynamics. All rights reserved. 9
Getting Started With The Python SDK
BREAKING NEWS:
AppDynamicsREST is now in the
Python Package Index!
Copyright © 2014 AppDynamics. All rights reserved. 11
Downloading and Installing
1. Install Python 2.7 from https://www.python.org/downloads/
2. Install PIP (if earlier than Python 2.7.9)
curl https://bootstrap.pypa.io/get-pip.py > get-pip.py
python get-pip.py
3. Install AppDynamicsREST
pip install AppDynamicsREST
4. Get coding!
Copyright © 2014 AppDynamics. All rights reserved. 12
Hello World – Your First Script
#! /usr/bin/env python
# Print the list of tiers for an application
from appd.request import AppDynamicsClient
c = AppDynamicsClient("http://localhost:8080",
"user1", "welcome")
for app in c.get_applications():
print app.id, app.name
Copyright © 2014 AppDynamics. All rights reserved. 13
Retrieving Metric Data
#! /usr/bin/env python
# Export key business metrics from AppDynamics
from appd.request import AppDynamicsClient
c = AppDynamicsClient("http://localhost:8080", "user1", "welcome")
metrics = c.get_metrics(metric_path='Business Transaction
Performance|Business Transactions|ECommerce
Server|ViewCart.addToCart|Average Response Time (ms)',
app_id='ACME Book Store Application',
time_range_type='BEFORE_NOW',
duration_in_mins=60,
rollup=False)
for point in metrics[0].values:
print point.start_time, 'Average Response Time: ',
point.value
Copyright © 2014 AppDynamics. All rights reserved. 14
License Usage Report
Hello World
OBJECTIVE
• Get count of licenses used per product (Java, .NET, etc.)
in the past 15 days
• Make a beautiful chart
TOOLS
• Python
• AppDynamicsREST
• PyGal
Copyright © 2014 AppDynamics. All rights reserved. 16
Source Code, Page 1
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta
from collections import OrderedDict, defaultdict
import pygal
import tzlocal
from appd.request import AppDynamicsClient
import creds.demo2 as creds
# Set up API client
c = AppDynamicsClient(creds.url, creds.user, creds.password, creds.account)
# Get my tenant account info
my_acct = c.get_my_account()
# Calculate start and end dates - we will start at midnight and go back 15 days
days = 15
mytz = tzlocal.get_localzone()
end_dt = datetime.now(mytz).replace(hour=0, minute=0, second=0, microsecond=0)
start_dt = end_dt - timedelta(days)
# Get license usage for my account
usage = c.get_license_usage(my_acct.id, None, start_dt, end_dt)
Copyright © 2014 AppDynamics. All rights reserved. 17
Source Code, Page 2
def daterange(start_dt, end_dt):
for n in range(int((end_dt - start_dt).days)):
yield start_dt + timedelta(days=n)
# Get the list of all licensed products:
products = set(x.license_module for x in usage.usages)
products = [x for x in products if 'eum' not in x and 'analytics' not in x]
usage_by_product = defaultdict(OrderedDict)
for product in products:
for day in daterange(start_dt, end_dt):
units = [x.max_units_used for x in usage.usages if
x.created_on.date() == day.date() and x.license_module == product]
usage_by_product[product][day] = max(units)
# Make a simple graph and display it
chart = pygal.StackedBar(x_label_rotation=45, width=1000)
chart.title = 'License Usage By Product - ' + c.base_url
chart.x_labels = [str(x.date()) for x in daterange(start_dt, end_dt)]
for product in products:
chart.add(product, usage_by_product[product].values())
chart.render_to_file('all_usage.svg')
Copyright © 2014 AppDynamics. All rights reserved. 18
Output
Copyright © 2014 AppDynamics. All rights reserved. 19
Enable & Disable Health Rules
Hello World
OBJECTIVES
• Programmatically enable and disable health rules
• Perform code deployments without triggering false alerts
TOOLS
• Python
• AppDynamicsREST v2
Copyright © 2014 AppDynamics. All rights reserved. 21
Wait … What is v2?
• Version 2 of AppDynamicsREST is being developed
• Supports original AppDynamics REST API and v2.0
• Supports XML or JSON output
• Fully RESTful object model
Old: c.get_nodes(app_id=10, tier_id=12)
New: c.application(10).tier(12).nodes
Best: c.application(‘ACME Book Store’)
.tier(‘E-Commerce’)
.nodes
Copyright © 2014 AppDynamics. All rights reserved. 22
New Features in v2
• Accounts
• Users
• Policies
• Health rules
• License usage
• License status
• App Agent Operations
• Collect log files
• Collect debug logs
• Take thread dumps
• Configuration import/export
Copyright © 2014 AppDynamics. All rights reserved. 23
Disabling Health Rules
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from appd.http.service import AppDynamicsService
c = AppDynamicsService('user1', 'welcome',
base_url='http://localhost:8080')
app = c.my_account.application('ACME Book Store')
for hr in app.health_rules:
hr.disable()
Copyright © 2014 AppDynamics. All rights reserved. 24
Output
Copyright © 2014 AppDynamics. All rights reserved. 25
Enabling Health Rules
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from appd.http.service import AppDynamicsService
c = AppDynamicsService('user1', 'welcome',
base_url='http://localhost:8080')
app = c.my_account.application('ACME Book Store')
for hr in app.health_rules:
hr.enable()
Copyright © 2014 AppDynamics. All rights reserved. 26
Output
Copyright © 2014 AppDynamics. All rights reserved. 27
Office Hours/Q&A
Further Reading
• Product Documentation
https://docs.appdynamics.com/display/PRO41/Use+the+AppDynami
cs+REST+API
• REST API SDK On Python Package Index
https://pypi.python.org/pypi/AppDynamicsREST
Thank You!

More Related Content

PDF
AppDynamics Administration - AppSphere16
PDF
AppDynamics Custom Transaction Correlation
PDF
End User Monitoring with AppDynamics - AppSphere16
PPTX
Become an AppDynamics Dashboard Rockstar - AppD Summit Europe
PDF
Synthetic Monitoring Deep Dive - AppSphere16
PPTX
Understanding REST APIs in 5 Simple Steps
PDF
Appdynamics Training Session
PDF
AppDynamics Administration - AppSphere16
AppDynamics Custom Transaction Correlation
End User Monitoring with AppDynamics - AppSphere16
Become an AppDynamics Dashboard Rockstar - AppD Summit Europe
Synthetic Monitoring Deep Dive - AppSphere16
Understanding REST APIs in 5 Simple Steps
Appdynamics Training Session

What's hot (20)

PDF
Spring Boot & Actuators
PDF
Presentation swagger
PPTX
서비스 지향 아키텍쳐 (SOA)
PPT
PPTX
Postman Introduction
PPTX
Azure serverless Full-Stack kickstart
PPTX
Appium ppt
PDF
Introduction To Single Page Application
PDF
I Love APIs 2015 : Zero to Thousands TPS Private Cloud Operations Workshop
PPTX
Api testing
PDF
REST API 디자인 개요
PDF
Memory Heap Analysis with AppDynamics - AppSphere16
PDF
I Love APIs 2015: Advanced Crash Course in Apigee Edge Workshop
PPTX
What is an API?
PPTX
Tesseract OCR Engine
PDF
AWS 를 활용한 저지연 라이브 (Low Latency Live) 서비스 구현 - 류재춘 컨설턴트/에반젤리스트, GS Neot다 :: AW...
PPTX
An Introduction To REST API
PPT
Introduction To Django
PDF
Api presentation
PDF
Python/Django Training
Spring Boot & Actuators
Presentation swagger
서비스 지향 아키텍쳐 (SOA)
Postman Introduction
Azure serverless Full-Stack kickstart
Appium ppt
Introduction To Single Page Application
I Love APIs 2015 : Zero to Thousands TPS Private Cloud Operations Workshop
Api testing
REST API 디자인 개요
Memory Heap Analysis with AppDynamics - AppSphere16
I Love APIs 2015: Advanced Crash Course in Apigee Edge Workshop
What is an API?
Tesseract OCR Engine
AWS 를 활용한 저지연 라이브 (Low Latency Live) 서비스 구현 - 류재춘 컨설턴트/에반젤리스트, GS Neot다 :: AW...
An Introduction To REST API
Introduction To Django
Api presentation
Python/Django Training
Ad

Viewers also liked (20)

PPTX
Webinar - Building Custom Extensions With AppDynamics
PPTX
AppDynamics Advanced BT Configuration
PPT
Building a CRM on top of ElasticSearch
PDF
Enterprise Sales
PPTX
Rapid Deployment of BMC Remedy Solutions 2006
PPTX
BMC Control-M for SAP, BPI, and AFT - VPMA - Secret Weapons for a Successful...
PPTX
How The Container Store uses AppDynamics in their development lifecycle
PPTX
Cerner APM Journey with AppDynamics
PDF
AppDynamics- A sneak peak into the product that is disrupting the Application...
PPTX
What's New in the BMC Remedy Suite
PPTX
Introduction to appDynamics
PDF
AppSphere 15 - Toys vs Tools: AppDynamics, a Swiss Army Knife for IT Professi...
PPTX
Sales Onboarding - Accelerating New Hire Productivity
PDF
Cloud & DevOps = A Match made in IT Heaven: Clyde Logue, BMC Software
PDF
How AppDynamics leveraged sales enablement to grow from one to 350 reps
PDF
Velocity Presentation - Unified Monitoring with AppDynamics
PPTX
BMC Engage - ITAM 2015-2020: The Evolving Role of the IT Asset Manager
PPTX
BMC Engage 2015: IT Asset Management - An essential pillar for the digital en...
PDF
Under the Hood: Monitoring Azure and .NET - AppSphere16
PPTX
Why and How to Monitor Application Performance in Azure
Webinar - Building Custom Extensions With AppDynamics
AppDynamics Advanced BT Configuration
Building a CRM on top of ElasticSearch
Enterprise Sales
Rapid Deployment of BMC Remedy Solutions 2006
BMC Control-M for SAP, BPI, and AFT - VPMA - Secret Weapons for a Successful...
How The Container Store uses AppDynamics in their development lifecycle
Cerner APM Journey with AppDynamics
AppDynamics- A sneak peak into the product that is disrupting the Application...
What's New in the BMC Remedy Suite
Introduction to appDynamics
AppSphere 15 - Toys vs Tools: AppDynamics, a Swiss Army Knife for IT Professi...
Sales Onboarding - Accelerating New Hire Productivity
Cloud & DevOps = A Match made in IT Heaven: Clyde Logue, BMC Software
How AppDynamics leveraged sales enablement to grow from one to 350 reps
Velocity Presentation - Unified Monitoring with AppDynamics
BMC Engage - ITAM 2015-2020: The Evolving Role of the IT Asset Manager
BMC Engage 2015: IT Asset Management - An essential pillar for the digital en...
Under the Hood: Monitoring Azure and .NET - AppSphere16
Why and How to Monitor Application Performance in Azure
Ad

Similar to Advanced REST API Scripting With AppDynamics (20)

PPTX
Sst hackathon express
PPTX
Powering your Apps via Google Cloud Platform
PPTX
Programmable infrastructure with FlyScript
PPTX
API Services: Building State-of-the-Art APIs
PDF
Back to the Future: Containerize Legacy Applications
PDF
Securing Red Hat OpenShift Containerized Applications At Enterprise Scale
PDF
Docker Birthday #5 Meetup Cluj - Presentation
PDF
Mobile-Enabling Enterprise APIs: A Case Study with MasterCard
PPTX
Testing Your Android and iOS Apps with Appium in Testdroid Cloud
PDF
Introduction to Titanium and how to connect with a PHP backend
PDF
CloudLand 2023: Rock, Paper, Scissors Cloud Competition - Go vs. Java
PDF
citus™ iot ecosystem
PDF
Openshift: The power of kubernetes for engineers - Riga Dev Days 18
PDF
Pivotal + Apigee Workshop (June 4th, 2019)
PDF
Getting More Out of the Node.js, PHP, and Python Agents - AppSphere16
KEY
Building production-quality apps with Node.js
PDF
AppSphere 15 - PHP, Node.js and Python Deep Dive
DOC
Rituraj Vaishnav Updated
PPTX
The Powerful and Comprehensive API for Mobile App Development and Testing
PPTX
Monitoring Cloud Native Apps on Pivotal Cloud Foundry with AppDynamics
Sst hackathon express
Powering your Apps via Google Cloud Platform
Programmable infrastructure with FlyScript
API Services: Building State-of-the-Art APIs
Back to the Future: Containerize Legacy Applications
Securing Red Hat OpenShift Containerized Applications At Enterprise Scale
Docker Birthday #5 Meetup Cluj - Presentation
Mobile-Enabling Enterprise APIs: A Case Study with MasterCard
Testing Your Android and iOS Apps with Appium in Testdroid Cloud
Introduction to Titanium and how to connect with a PHP backend
CloudLand 2023: Rock, Paper, Scissors Cloud Competition - Go vs. Java
citus™ iot ecosystem
Openshift: The power of kubernetes for engineers - Riga Dev Days 18
Pivotal + Apigee Workshop (June 4th, 2019)
Getting More Out of the Node.js, PHP, and Python Agents - AppSphere16
Building production-quality apps with Node.js
AppSphere 15 - PHP, Node.js and Python Deep Dive
Rituraj Vaishnav Updated
The Powerful and Comprehensive API for Mobile App Development and Testing
Monitoring Cloud Native Apps on Pivotal Cloud Foundry with AppDynamics

Recently uploaded (20)

PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
System and Network Administraation Chapter 3
PPTX
Transform Your Business with a Software ERP System
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Digital Strategies for Manufacturing Companies
PDF
Designing Intelligence for the Shop Floor.pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Digital Systems & Binary Numbers (comprehensive )
How to Migrate SBCGlobal Email to Yahoo Easily
Wondershare Filmora 15 Crack With Activation Key [2025
System and Network Administraation Chapter 3
Transform Your Business with a Software ERP System
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
L1 - Introduction to python Backend.pptx
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Navsoft: AI-Powered Business Solutions & Custom Software Development
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
CHAPTER 2 - PM Management and IT Context
Digital Strategies for Manufacturing Companies
Designing Intelligence for the Shop Floor.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Softaken Excel to vCard Converter Software.pdf
Reimagine Home Health with the Power of Agentic AI​
wealthsignaloriginal-com-DS-text-... (1).pdf

Advanced REST API Scripting With AppDynamics

  • 1. Advanced REST API Scripting Todd Radel Senior Manager, Enablement and Adoption
  • 2. About Me Todd Radel SENIOR MANAGER ENABLEMENT & ADOPTION, US EAST • More than 20 years experience in the software industry • Java, .NET, Python, Perl • Author of the Python SDK for AppDynamics REST API • Author of six AppDynamics Extensions: F5, Tibco EMS, Redis, Keynote, SQL, URL Monitor Copyright © 2014 AppDynamics. All rights reserved. 2 tradel@appdynamics.com +1 (484) 857-2335 tradel todd.radel linkedin.com/in/tradel
  • 3. Today’s Agenda Copyright © 2014 AppDynamics. All rights reserved. 3 1 2 Installing and using the Python SDK 3 Reporting on license usage Hello World (in 3 languages!) BUILDING ON THE FIRST REST API WEBINAR, WE WILL SHOW YOU HOW TO SCRIPT AND AUTOMATE COMMON TASKS 4 DevOps integration – disabling health rules during code deployment
  • 5. Hello World OBJECTIVE • Retrieve a list of business applications from the controller • Print to stdout FLAVORS • Bash/cURL • PowerShell • Python – The Hard Way • Python – The Easy Way Copyright © 2014 AppDynamics. All rights reserved. 5
  • 6. Bash and cURL #! /bin/bash # Print the list of tiers for an application curl -X GET -u user1@customer1:welcome "http://localhost:8080/controller/rest/applications?output=jso n" Copyright © 2014 AppDynamics. All rights reserved. 6
  • 7. Windows PowerShell # Print the list of tiers for an application $usr="user1@customer1" $pwd="welcome" $headers = @{ Authorization = "Basic " + [System.Convert]::ToBase64String( [System.Text.Encoding]::ASCII.GetBytes( "$($usr):$($pwd)")) } $url="http://localhost:8080/controller/rest/applications?outpu t=json" $response = Invoke-RestMethod $url -Headers $Headers $response | ForEach-Object { [string]$_.id + " " + $_.name }
  • 8. Python – The Hard Way #! /usr/bin/env python # Print the list of tiers for an application import requests usr = "user1@customer1" pwd = "welcome" url = "http://localhost:8080/controller/rest/applications?output=jso n" response = requests.get(url, auth=(usr, pwd)) json = response.json() for app in json: print app['id'], app['name'] Copyright © 2014 AppDynamics. All rights reserved. 8
  • 9. Python – The Easy Way #! /usr/bin/env python # Print the list of tiers for an application from appd.request import AppDynamicsClient c = AppDynamicsClient("http://localhost:8080", "user1", "welcome") for app in c.get_applications(): print app.id, app.name # Wasn’t that easy? Copyright © 2014 AppDynamics. All rights reserved. 9
  • 10. Getting Started With The Python SDK
  • 11. BREAKING NEWS: AppDynamicsREST is now in the Python Package Index! Copyright © 2014 AppDynamics. All rights reserved. 11
  • 12. Downloading and Installing 1. Install Python 2.7 from https://www.python.org/downloads/ 2. Install PIP (if earlier than Python 2.7.9) curl https://bootstrap.pypa.io/get-pip.py > get-pip.py python get-pip.py 3. Install AppDynamicsREST pip install AppDynamicsREST 4. Get coding! Copyright © 2014 AppDynamics. All rights reserved. 12
  • 13. Hello World – Your First Script #! /usr/bin/env python # Print the list of tiers for an application from appd.request import AppDynamicsClient c = AppDynamicsClient("http://localhost:8080", "user1", "welcome") for app in c.get_applications(): print app.id, app.name Copyright © 2014 AppDynamics. All rights reserved. 13
  • 14. Retrieving Metric Data #! /usr/bin/env python # Export key business metrics from AppDynamics from appd.request import AppDynamicsClient c = AppDynamicsClient("http://localhost:8080", "user1", "welcome") metrics = c.get_metrics(metric_path='Business Transaction Performance|Business Transactions|ECommerce Server|ViewCart.addToCart|Average Response Time (ms)', app_id='ACME Book Store Application', time_range_type='BEFORE_NOW', duration_in_mins=60, rollup=False) for point in metrics[0].values: print point.start_time, 'Average Response Time: ', point.value Copyright © 2014 AppDynamics. All rights reserved. 14
  • 16. Hello World OBJECTIVE • Get count of licenses used per product (Java, .NET, etc.) in the past 15 days • Make a beautiful chart TOOLS • Python • AppDynamicsREST • PyGal Copyright © 2014 AppDynamics. All rights reserved. 16
  • 17. Source Code, Page 1 #! /usr/bin/env python # -*- coding: utf-8 -*- from datetime import datetime, timedelta from collections import OrderedDict, defaultdict import pygal import tzlocal from appd.request import AppDynamicsClient import creds.demo2 as creds # Set up API client c = AppDynamicsClient(creds.url, creds.user, creds.password, creds.account) # Get my tenant account info my_acct = c.get_my_account() # Calculate start and end dates - we will start at midnight and go back 15 days days = 15 mytz = tzlocal.get_localzone() end_dt = datetime.now(mytz).replace(hour=0, minute=0, second=0, microsecond=0) start_dt = end_dt - timedelta(days) # Get license usage for my account usage = c.get_license_usage(my_acct.id, None, start_dt, end_dt) Copyright © 2014 AppDynamics. All rights reserved. 17
  • 18. Source Code, Page 2 def daterange(start_dt, end_dt): for n in range(int((end_dt - start_dt).days)): yield start_dt + timedelta(days=n) # Get the list of all licensed products: products = set(x.license_module for x in usage.usages) products = [x for x in products if 'eum' not in x and 'analytics' not in x] usage_by_product = defaultdict(OrderedDict) for product in products: for day in daterange(start_dt, end_dt): units = [x.max_units_used for x in usage.usages if x.created_on.date() == day.date() and x.license_module == product] usage_by_product[product][day] = max(units) # Make a simple graph and display it chart = pygal.StackedBar(x_label_rotation=45, width=1000) chart.title = 'License Usage By Product - ' + c.base_url chart.x_labels = [str(x.date()) for x in daterange(start_dt, end_dt)] for product in products: chart.add(product, usage_by_product[product].values()) chart.render_to_file('all_usage.svg') Copyright © 2014 AppDynamics. All rights reserved. 18
  • 19. Output Copyright © 2014 AppDynamics. All rights reserved. 19
  • 20. Enable & Disable Health Rules
  • 21. Hello World OBJECTIVES • Programmatically enable and disable health rules • Perform code deployments without triggering false alerts TOOLS • Python • AppDynamicsREST v2 Copyright © 2014 AppDynamics. All rights reserved. 21
  • 22. Wait … What is v2? • Version 2 of AppDynamicsREST is being developed • Supports original AppDynamics REST API and v2.0 • Supports XML or JSON output • Fully RESTful object model Old: c.get_nodes(app_id=10, tier_id=12) New: c.application(10).tier(12).nodes Best: c.application(‘ACME Book Store’) .tier(‘E-Commerce’) .nodes Copyright © 2014 AppDynamics. All rights reserved. 22
  • 23. New Features in v2 • Accounts • Users • Policies • Health rules • License usage • License status • App Agent Operations • Collect log files • Collect debug logs • Take thread dumps • Configuration import/export Copyright © 2014 AppDynamics. All rights reserved. 23
  • 24. Disabling Health Rules #! /usr/bin/env python # -*- coding: utf-8 -*- from appd.http.service import AppDynamicsService c = AppDynamicsService('user1', 'welcome', base_url='http://localhost:8080') app = c.my_account.application('ACME Book Store') for hr in app.health_rules: hr.disable() Copyright © 2014 AppDynamics. All rights reserved. 24
  • 25. Output Copyright © 2014 AppDynamics. All rights reserved. 25
  • 26. Enabling Health Rules #! /usr/bin/env python # -*- coding: utf-8 -*- from appd.http.service import AppDynamicsService c = AppDynamicsService('user1', 'welcome', base_url='http://localhost:8080') app = c.my_account.application('ACME Book Store') for hr in app.health_rules: hr.enable() Copyright © 2014 AppDynamics. All rights reserved. 26
  • 27. Output Copyright © 2014 AppDynamics. All rights reserved. 27
  • 29. Further Reading • Product Documentation https://docs.appdynamics.com/display/PRO41/Use+the+AppDynami cs+REST+API • REST API SDK On Python Package Index https://pypi.python.org/pypi/AppDynamicsREST

Editor's Notes

  • #12: With documentation and hints for syntax completion Over 1000 downloads per month!
  • #13: If you already have Python installed, skip step 1. If you already have pip (or easy_install), skip step 2.
  • #15: Live demo - using metric browser, right-click and “Copy Full Path”, paste into script (bt_performance.py) Enhance to display all BT’s (bt_performance_2.py)
  • #16: file:///Users/tradel/Code/REST-API-Webinar/all_usage.svg
  • #21: http://localhost:8080/controller/#/location=ALERT_RESPOND_HEALTH_RULES&timeRange=last_15_minutes.BEFORE_NOW.-1.-1.15&application=10 Switch to appdynamics-dexml project