Home > ADDM, Powershell > Querying BMC ADDM / Atrium from Powershell.

Querying BMC ADDM / Atrium from Powershell.

We have a new discovery appliance at a client site – BMC atrium.

I was having a look at it and unfortunately it does not have a normal SQL backend . . so it is not as easy to collect information as I would like (well . . .it is if you do a little legwork)

Looking through the docs, I found they do have an API – and actually . . the API was incredibly simple to use – just need some web access.

Well. my weapon of choice is always PowerShell . . so all I need is a simple web query no?

there are a few tricks though.

I do not want to have to keep providing my password
I would not like any clear text passwords knocking about
I want to be able to pass Queries that contain special characters
I’d like a simply object returned that can easily be manipulated using normal PowerShell syntax.

Here’s what I came up with.

Note – you’ll need to specify a server and a proxy (or include these in your function by editing the values in the first line of the function

Remember – it would be best practice to create a read-only account and use these creds for queries.


Function get-Addm ([string]$query,$servername"myserver.lab.local", $username, $password, $proxy="myproxy.lab.local", [switch]$resetpwd)
	{
	# Use system reflection to convert string to URL.
	[System.Reflection.Assembly]::LoadWithPartialName("System.Web") | out-null
	$query = [System.Web.HttpUtility]::UrlEncode($query)
	
	# Check for password / gather password info
	If ($resetpwd)
		{del $env:userprofile\$username.txt}
	If (!$username)
		{
		write-host "No Username specified - using $env:username" -fore Green
		$username = $env:username
		}
	if (test-path $env:userprofile\$username.txt)
		{
		write-host "Stored creds found for $username" -fore Green
		}
		else
		{
		write-host "No Password saved for $username - please specify a valid pwd" -fore Green
		read-host -assecurestring | convertfrom-securestring | out-file $env:userprofile\$username.txt
		}
		$password = get-content $env:userprofile\$username.txt | convertto-securestring
		$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$password

	# Decrypt stored creds 
	$pw =  $credentials.GetNetworkCredential().password
	
	# Create Web request
	$proxy = new-object System.Net.WebProxy $proxy
	# $proxy.credentials = $proxycred.GetNetworkCredential()
	
	$WebClient = New-Object System.Net.WebClient
	$webclient.proxy = $proxy 
	$url = "https://$servername/ui/api/CsvApi?query=$query&username=$username&password=$pw"
	$Webclient.DownloadFile($url, "$env:temp\tmp.csv")
		#Import captured CSV
	$csv = import-csv "$env:temp\tmp.csv"
	return $csv
	}

So now I can simply generate a custom query in the GUI – then recycle this query for future searches, using Powershell – and get an opbject returned which I can edit as per normal Powershell queries.

so – for example, I’d like all windows servers and the DNS servers currently configured for these:

get-addm -query "SEARCH Host WHERE (os HAS SUBSTRING 'windows') SHOW name, os, vendor, virtual, partition, #InferredElement:Inference:Associate:DiscoveryAccess.endpoint, #DeviceWithInterface:DeviceInterface:InterfaceOfDevice:NetworkInterface.dns_servers AS 'DNS Servers'" -username "read_only" -servername "myappliance"

Categories: ADDM, Powershell Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.