-
-
Save joesondow/4018509 to your computer and use it in GitHub Desktop.
Asgard Console examples
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
// ASG and ELB mismatched zones | |
asgardLocator.getInstance('nactest').acrossRegions { | |
def asgs = autoScaling | |
def elbs = loadBalancer | |
html.output << "<h3>${inRegion}</h3>" | |
def elbByName = elbs.inject([:]) { acc, elb -> | |
acc[elb.loadBalancerName] = elb | |
acc | |
} | |
asgs.each { asg -> | |
def elbsForAsg = asg.loadBalancerNames.collect { elbByName[it] } | |
elbsForAsg.each { elb -> | |
def asgZones = asg.availabilityZones.sort().join(', ') | |
def elbZones = elb?.availabilityZones?.sort()?.join(', ') | |
if (asgZones != elbZones) { | |
html.with { output << "ASG ${link { autoScaling asg.autoScalingGroupName} } differs from ELB ${link { loadBalancer elb?.loadBalancerName} }: ${diff(asgZones, elbZones)}</br>" } | |
} | |
} | |
} | |
} |
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
// Report on ASGs in subnets with purposes named something other than 'internal' or 'external' | |
asgardLocator.getInstance('nactest').acrossRegions { | |
List<String> misnamedSubnets = subnet.findAll { | |
it.purpose ? !(it.purpose in ['internal', 'external']) : false | |
} | |
//if (!misnamedSubnets) { return } | |
html.output << "<h3>${inRegion}</h3>" | |
misnamedSubnets.sort().each { subnet -> | |
List<String> asgsInMisnamedSubnets = autoScaling.findAll { asg -> | |
asg.VPCZoneIdentifier.contains(subnet.subnetId) | |
} | |
html.with { | |
output << "${subnet.purpose}<br />" | |
asgsInMisnamedSubnets*.autoScalingGroupName.each {id -> | |
output << "${link { autoScaling id }}<br />" | |
} | |
} | |
} | |
} |
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
// Display String with HTML and Groovy | |
html.with{ | |
output << "Test: <br /> ${2+8}" | |
} |
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
// Parameterize scripts with a config block. Make sure to give descriptions and maybe defaults. | |
config { | |
params { | |
your_name 'The name of the person executing this script.', 'Clay' | |
load_balancer_name 'The name of the load balancer that you would like to see JSON for.' | |
} | |
} | |
{ | |
html.output << 'Greetings ' + param.your_name + ', here is the Load Balancer info you requested:<br />' | |
asgardLocator.getInstance('nactest').with { | |
html.with { | |
output << inRegion('us-east-1') { loadBalancer param.load_balancer_name } | |
} | |
} | |
} |
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
// What is the difference in ELBs across regions. Could compare across Asgard instances just as easily. | |
asgardLocator.getInstance('nactest').with { | |
html.with { | |
output << diff( | |
inRegion('us-east-1') { loadBalancer 'helloclay--frontend' }, | |
inRegion('us-west-1') { loadBalancer 'helloclay--frontend' } | |
) | |
} | |
} |
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
config { | |
title 'Compare Fast Property values across regions for an Application' | |
params { | |
source_region 'Region that you would like to compare to all other regions.', 'us-east-1' | |
app_name 'Filter by Application.' | |
} | |
} | |
{ | |
def asgard = asgardLocator.getInstance('nactest') | |
def fastPropertiesForApp = asgard.inRegion(param.source_region).fastProperty.fastProperties. | |
findAll({it.appId == param.app_name}) | |
def getRegionProperties = { region -> | |
fastPropertiesForApp.findAll({!it.region || it.region == region}).inject([:]) { acc, property -> | |
acc[property.key] = property.value | |
acc | |
} | |
} | |
Map sourceProperties = getRegionProperties(param.source_region) | |
html.output << "<h3>${param.app_name} in ${param.source_region} vs</h3>" | |
asgard.acrossRegions { | |
if (inRegion == param.source_region) { return } | |
Map regionProperties = getRegionProperties(inRegion) | |
html.output << "<h4>${inRegion}</h4>" | |
if (regionProperties.isEmpty()) { | |
html.output << "<div class='text-error'>Properties for ${param.app_name} do not exist.</div>" | |
return | |
} | |
if (sourceProperties == regionProperties) { | |
html.output << "<div class='text-success'>Properties for ${param.app_name} are identical.</div>" | |
return | |
} | |
html.output << '<table class="table table-bordered">' | |
List<String> fastPropertyNames = (sourceProperties.keySet() + regionProperties.keySet()).unique().sort() | |
fastPropertyNames.each { | |
if (sourceProperties[it] != regionProperties[it]) { | |
html.output << "<tr><td>${it}</td><td>${html.diff(sourceProperties[it], regionProperties[it])}</td></tr>" | |
} | |
} | |
html.output << "</table>" | |
} | |
} |
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
// Report misconfigured ELBs (ones in an internal subnet without the internal scheme). | |
asgardLocator.getInstance('nactest').acrossRegions { | |
List<String> internalElbSubnets = subnet.findAll { | |
it.purpose == 'internal' && it.target.name == 'ELB' | |
} | |
List<String> misconfiguredElbs = loadBalancer.findAll { | |
it.subnets.intersect(internalElbSubnets*.subnetId) && (it.scheme != 'internal') | |
} | |
if (!misconfiguredElbs) { return } | |
html.with { | |
output << "<br />${inRegion}<br />" | |
misconfiguredElbs*.loadBalancerName.each {id -> | |
output << "${link { loadBalancer id }}<br />" | |
} | |
} | |
} |
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
// Simply display info about a specific load balancer. Works with any Asgard object, not just ELBs. Leave off the id to get a list. | |
asgardLocator.getInstance('nactest').with { | |
html.with { | |
output << inRegion('us-east-1') { loadBalancer 'helloclay--frontend' } | |
} | |
} |
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
// Report on load balancers in the VPC. Show me clickable links to Asgard. And do it across all regions. | |
asgardLocator.getInstance('nactest').acrossRegions { | |
def vpcLoadBalancers = loadBalancer.findAll { it.VPCId }.sort {it.loadBalancerName} | |
if (!vpcLoadBalancers) { return } | |
html.with { | |
output << "<br />${inRegion}<br />" | |
vpcLoadBalancers.each { lb -> | |
output << "${link { loadBalancer lb.loadBalancerName }} - ${lb.scheme}<br />" | |
} | |
} | |
} |
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
// Report on load balancers in the VPC with Sparklines! | |
def pieChartHtml = { allAwsObjects, vpcAwsObjects -> | |
html.sparkline([allAwsObjects.size(), vpcAwsObjects.size()], [ | |
Type: 'pie', | |
Height: '100', | |
Width: '100', | |
]) | |
} | |
html.output << """ | |
<h1>Percentage of VPC usage across regions.</h1> | |
<table class="table table-bordered"> | |
<tr><th>Region</th><th>ELBs</th><th>ASGs</th><th>Security Groups</th></tr> | |
""" | |
asgardLocator.getInstance('nactest').acrossRegions { | |
def allLoadBalancers = loadBalancer | |
def vpcLoadBalancers = allLoadBalancers.findAll { it.VPCId } | |
def allAsgs = autoScaling | |
def vpcAsgs = allAsgs.findAll { it.VPCZoneIdentifier } | |
def allSecurityGroups = security.securityGroups | |
def vpcSecurityGroups = allSecurityGroups.findAll { it.vpcId } | |
html.with { | |
output << """<tr><td>${inRegion}</td> | |
<td>${pieChartHtml(allLoadBalancers, vpcLoadBalancers)}</td> | |
<td>${pieChartHtml(allAsgs, vpcAsgs)}</td> | |
<td>${pieChartHtml(allSecurityGroups, vpcSecurityGroups)}</td> | |
</tr>""" | |
} | |
} | |
html.output << '</table>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment