Monthly Archives: January 2013

Basic Cisco UCS fault report

This will connect to a list of UCS environments in a text file, build the report for each one, then send a single email with the report for each environment. The report contains:

– Unacknowledged faults
– Hardware locator LEDs that are on (it’s common to forget to turn them off when the work is done)
– If you are short port licenses it will also do a report showing the relevant counts and for convenience output the serial numbers of the FIs.

You’ll have to make the usual changes to directories, email addresses, etc.

You can also grab the script from http://http://poshcode.org/3923 .

<#
.Synopsis
    Connects to multiple UCS environments listed in a text file and generates a basic fault report for each one, then sends one email with the results.  In the report are unacknowledged faults, hardware locator LEDs that are on, and if you are short on port licenses it will show that.  Variables and paths will have to be changed to match your environment.
#>

param($CredentialFile=$null)

if ($CredentialFile -eq $null) { Write-Host "Missing the path to the credential file." -BackgroundColor DarkYellow -ForegroundColor DarkRed; break }


#-----------------------------
# Prep
#-----------------------------
function Get-Now { (get-date -uformat %Y%m%d) + "_" + (get-date -uformat %H%M%S) }
if ((Get-Module -Name CiscoUcsPS) -eq $null) { Import-Module -Name C:\Ops\Modules\CiscoUCSPowerTool\CiscoUcsPS.psd1 }

#Static parameters
Set-Variable -Name ScriptDir   -Value "C:\Scripts" -Scope Local
Set-Variable -Name ReportPath  -Value "C:\Scripts\Reports\UCS_Fault_Reports" -Scope Local
Set-Variable -Name ReportFile  -Value "$($ReportPath)\UCS_Fault_Report_$(Get-Now).html" -Scope Local
Write-Verbose "`nStatic parameters`n-----------------`nScriptDir = $($ScriptDir)`nReportFile = $($ReportFile)`n"
$mailTo = "alertsdistgroup@yourcompany.com"
$mailFrom = "UCS_Fault_Reports@yourcompany.com"
$mailSMTP = "smtp.yourcompany.com"

If ( !(Test-Path $ReportPath) ) { mkdir $ReportPath }
. $ScriptDir\Hals_PSCredentials.ps1
# Setup credentials as described in https://batchlife.wordpress.com/2012/11/14/powershell-script-to-backup-a-cisco-ucs-fabric-interconnect-using-the-cisco-powertool-cmdlets/

$UcsCred = Import-PsCredential -Path $CredentialFile


#-----------------------------
# Start doing the real work.
#-----------------------------

Disconnect-Ucs 2>$null # Connect-Ucs will fail if you're already connected to a UCS

"<pre>" | Out-File -FilePath $ReportFile -Width 400
Get-Date | Out-File -FilePath $ReportFile -Append -Width 400

Get-Content C:\Scripts\Repo\StaticInfo\UCSs.txt | ForEach-Object { 
    Write-Output "=========================================================================================================="
    Connect-Ucs -Name $_ -Credential $UcsCred | select name,version,username,virtualipv4address | ft -a
    if ($DefaultUcs -eq $null) {
        $mailBody = @()
        $mailBody += "$(Get-Now) - Error connecting to UCS`n`n"
        $mailBody += $_
        Send-MailMessage  -From $mailFrom -To $mailTo -Subject "Backup-mUcs Error-- Failed connecting to $($Ucs)" -Body ($mailBody | Out-String) -SmtpServer $mailSMTP
    }
    else {
        Get-UcsFault | Where-Object { ($_.Severity -ne 'cleared') -and ($_.Ack -ne 'yes') } | sort lasttransition -Descending | select lasttransition,severity,status,type,dn,descr | ft -a
        Get-UcsLocatorLed | ? { $_.operstate -eq 'on' } | sort dn | select dn,adminstate,color,operstate,id | ft -a
        If (Get-UcsFault | Where-Object { ($_.Severity -ne 'cleared') -and ($_.Dn -match 'F0676') } ) { 
            "`n------ Port Licenses Needed ----------------------------------------------------------------------------"
            Get-UcsLicense | Select-Object Ucs,Scope,Feature,Sku,AbsQuant,DefQuant,UsedQuant,@{n="RemQuant";e={$_.AbsQuant-$_.UsedQuant}},Status,PeerStatus,OperState,GracePeriodUsed | ft -a
            Get-UcsLicenseServerHostId | select ucs,rn,hostid | ft -a
        }
        Disconnect-Ucs 
    }
} | Out-File -FilePath $ReportFile -Append -Width 400

"</pre>" | Out-File -FilePath $ReportFile -Append -Width 400

$body = Get-Content $ReportFile

Send-MailMessage  -From $mailFrom -To $mailTo -Subject "UCS Fault Report $(Get-Date)" -Body ($body | Out-String) -BodyAsHTML -SmtpServer $mailSMTP