search
top

Retrieving SmartQuota Data on Isilon with RestAPI and PowerShell

Introduction

Many different tools available for administrators to manage storage devices and create reports and or monitors. With EMC Isilon we have RestAPI available to make calls for information. In this post we will cover how to use PowerShell to make calls to Isilon and get Smartquota data (path, thresholds for advisory & hard) and usage data and convert it from bytes to GB. The basis of the script can be used as the main shell to create more customized scripts.

Prerequisites

To be able to execute RestAPI calls to Isilon you will need to create an account and add the appropriate roles. For GET operations a read-only account is all that you will need. For this post we will create a local group and grant PlatformAPI and Quota read-only roles.

The Code

So now lets get down to the meat of the post and the code we need to execute the RestAPI calls in PowerShell for Isilon.

 

<# 
 .SYNOPSIS 
 This script will Dump quotas data off Isilon and displays advisory, hard and usage. RestAPI account needs PlatformAPI and Quotas Roles.
 
 .DESCRIPTION 
 This script will Dump quotas data off Isilon and displays advisory, hard and usage. RestAPI account needs PlatformAPI and Quotas Roles.
 
 .NOTES 
 File Name : getisilonquotas.ps1
 Author :
 Version : 1.0 (April 19, 2018 )
 
 .OUTPUTS 
 Screen Output. can be modified to save to csv 
 
 .EXAMPLE 
 C:\PS> .\getisilonquotas.ps1 
 
#>

add-type @"
 using System.Net;
 using System.Security.Cryptography.X509Certificates;
 public class TrustAllCertsPolicy : ICertificatePolicy {
 public bool CheckValidationResult(
 ServicePoint srvPoint, X509Certificate certificate,
 WebRequest request, int certificateProblem) {
 return true;
 }
 }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

$username = 'root'
$password = 'passw0rd'
$EncodedAuthorization = [System.Text.Encoding]::UTF8.GetBytes($username + ':' + $password)
$EncodedPassword = [System.Convert]::ToBase64String($EncodedAuthorization)
$headers = @{"Authorization"="Basic $($EncodedPassword)"}

# create Uri
# Change IP address to that of the target Isilon.
$baseurl = 'https://xxx.xx.xxx.xxx:8080' 
$resourceurl = "/platform/1/quota/quotas"
$uri = $baseurl + $resourceurl

# get share and print
$ISIObject = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers

# Uncomment below and comment out bottom line to export to csv
# $ISIObject.quotas | select-object -Property path,@{Name="Advisory Threshold GB";E={($_.thresholds.advisory/1GB)}},@{Name="Hard Threshold GB";E={($_.thresholds.hard/1GB)}},@{Name="Usage GB";E={"{0:N}" -f ($_.usage.logical/1GB) -as [float]}} | Export-Csv -Path c:\temp\quotas.csv

$ISIObject.quotas | select-object -Property path,@{Name="Advisory Threshold GB";E={($_.thresholds.advisory/1GB)}},@{Name="Hard Threshold GB";E={($_.thresholds.hard/1GB)}},@{Name="Usage GB";E={"{0:N}" -f ($_.usage.logical/1GB) -as [float]}}

 

Let’s take a deeper look into the code example what it is doing. The first part of the script is setting the security to be able to connect to your Isilon array. This code is not original, I found this at code from blogs.msdn.com. Just copy and paste this section and change the username and password. This will work for any other RestAPI in PowerShell using Basic Authentication.

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

$username = 'root'
$password = 'passw0rd'
$EncodedAuthorization = [System.Text.Encoding]::UTF8.GetBytes($username + ':' + $password)
$EncodedPassword = [System.Convert]::ToBase64String($EncodedAuthorization)
$headers = @{"Authorization"="Basic $($EncodedPassword)"}

Next section of the code we will setup our URI (Uniform Resource Identifier).  we will identify three variables called $baseurl, $resourceurl and $uri. The $baseurl is the https ip address of the Isilon node you want to run the query against. For the $resourceurl variable we will be using the /platform/1/quota/quotas resource path. You can get a list of all available resource available from EMC RestfulAPI documentation for Isilon. The final $uri is the combining of the two previous variables.

# create Uri
$baseurl = 'https://xxx.xxx.xxx.xxx:8080' 
$resourceurl = "/platform/1/quota/quotas/"
$uri = $baseurl + $resourceurl

Next section of the code we are going to create an object and make a Invole-RestMethod cmdlet and GET action using security for authentication.

$ISIObject = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers

Now we are ready to get the quotas. For the output I am looking for Advisory Threshold GB, Hard Threshold GB and Usage GB from quotas. I have added converting the output to GB instead of bytes to make it easier to read.

# Uncomment below and comment out bottom line to export to csv
# $ISIObject.quotas | select-object -Property path,@{Name="Advisory Threshold GB";E={($_.thresholds.advisory/1GB)}},@{Name="Hard Threshold GB";E={($_.thresholds.hard/1GB)}},@{Name="Usage GB";E={"{0:N}" -f ($_.usage.logical/1GB) -as [float]}} | Export-Csv -Path c:\temp\quotas.csv

$ISIObject.quotas | select-object -Property path,@{Name="Advisory Threshold GB";E={($_.thresholds.advisory/1GB)}},@{Name="Hard Threshold GB";E={($_.thresholds.hard/1GB)}},@{Name="Usage GB";E={"{0:N}" -f ($_.usage.logical/1GB) -as [float]}}

 

The output from the scripts.

Isilon RestAPI

Conclusion

So we have explored making a basic Restful API call to Isilon to get specific quota information. With this you can now start to explore  other RestfulAPI options available on Isilon.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

top