Scott Hinckley, Sr. Site Reliability Engineer at Microsoft Dynamics 365, presented at ThousandEyes Connect Seattle. He shares how his team automates web transaction monitoring using Powershell and the ThousandEyes API, integrates with back-end systems and shares some scripts for you to use.
8. Scale Issues
Browser Performance
• Initial load time per screen
• Time spent scrolling
• Timeouts on large dashboards
Note: ThousandEyes has greatly improved this performance over the last year
9. Scale Issues
Labor Cost
• Creating new tests required lots of copy/paste
• Many opportunities for key-in mistakes
• Became a full-time job for 1 person just entering tests
• Any change required manual re-visit of EVERY test
16. ž Error handling
ž Test and Alert parsing
ž Potential self-healing / remediation
ž Database interaction
ž .NET
ž Etc.
API Calls are the easy part
But PowerShell offers a lot more
17. More complex now
try
{
# Use GET method if appropriate
if ($method -eq 'GET')
{
# encapsulate to retain UTF-8 characters
$rawResponse = (Invoke-WebRequest $request -Method GET -Headers $headers)
} # end if GET
# else use POST method
else
{
# encapsulate to retain UTF-8 characters
$rawResponse = (Invoke-WebRequest $request -Method $method -Headers $headers -Body $postData)
} # end else Post
} # end try Invoke-WebRequest
# Catch if an error occurred in making the API call
Catch
{
# Get the error info returned from Invoke-Webrequest
$global:result = $_.Exception.response.GetResponseStream()
$global:reader = New-Object System.IO.StreamReader($global:result)
$global:responseBody = $global:reader.ReadToEnd();
#Add to it the custom error info and throw an exception
$myError = "$($errorInfo): $($global:responsebody)"
throw $myError
} # end catch from Invoke-WebRequest for POST
# Store response in powershell object convert back from the UTF-8 stream
$sr = [IO.StreamReader]::new($rawResponse.RawContentStream).ReadToEnd()
$response= ConvertFrom-JSON -InputObject $sr
19. BRIEF:
PowerShell functions to leverage the ThousandEyes API
Uses JSON for all calls
SUMMARY:
I took many of the small scripts and functions I've written to help automate
ThousandEyes and put them in this one container script with a menu to show
how they work. The intent is that these can be used for quick admin tasks, and
as a basis for your own automation.
ThousandEyes_via_PowerShell.ps1
20. Call_TE_API
ž ThousandEyes-specific wrapper for Invoke_WebRequest
ž Handles UTF-8 characters including double-byte
ž Captures error conditions
ž Returns the JSON results of the ThousandEyes API call
Meta:
21. Account Groups control access
ž Most ThousandEyes API calls return account group specific results
ž Each user/token combo has a default account group
ž Recommended:
ž Create account dedicated to automation with access to all groups
In the script:
ž Get_Default_Account_Group
ž List_Account_Groups
ž Change_Current_Account_Group
ž Changes which account group will be used by other functions
Account Groups:
22. ž Print_User_List
ž Prints list of all user IDs, names, and emails
ž Print_User_Details
ž Prints JSON details block for a specific user
Users:
23. ž Print_Usage_By_Test
ž Prints list of each tests:
TestID, test name, current and projected usage
ž Useful for finding expensive tests
ž Print_Usage_By_Group
ž Summarizes Cloud Unit usage by Account Group
ž Useful for budget alerting if combined with your cost/1K cloud units
ž Print_Test_Owners
ž Useful to identify top users
ž Try combining with Usage by Test to estimate per user costs
Usage:
24. ž Print_Alert_Rules (Optional pattern matching)
ž Prints list of alert rules by ID and Name
ž Print_Agents (Optional pattern matching)
ž Prints list of agents with ID, Name, Location, and Country
ž Print_Agent_IPs
ž Prints a list of each agent and what IP addresses it uses
Alert Rules and Agents:
25. ž Print_Alerts
ž Prints list of current alerts for an Account Group
ž AlertID, ruleID, ruleName, dateStart
ž Print_Alert_Details
ž Prints JSON detail block for a specific Alert ID
Alerts:
26. ž Get_Tests
ž loads list of tests visible to current account group
ž Print_Test_Names
ž Prints out all Test IDs and Names in current test list
ž Optional: Print only those matching a pattern
ž Print_Test_Details
ž Prints JSON details block for a specific test
Tests:
27. ž Change_Tests (required Test Name pattern to match)
ž Applies JSON configuration changes to tests
ž Only changes tests whose names match the pattern
ž Change_Enabled_State
ž Prompts enable/disable and test name pattern
ž Create_Transaction_Test
ž Example code for creating a basic transaction test
ž Must be modified with desired config to work
Test Creation / Modification: