-
-
Save hospitableit/32f39351f725c2d504446dd76a6283c0 to your computer and use it in GitHub Desktop.
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
try | |
{ | |
#Define username and encrypted password | |
$UserName = "Blah Blah" | |
$EncryptedPassword = "Blah Blah" | |
$SecurePassword = $EncryptedPassword | ConvertTo-SecureString | |
$Marshal = [System.Runtime.InteropServices.Marshal] | |
$Bstr = $Marshal::SecureStringToBSTR($SecurePassword) | |
$Password = $Marshal::PtrToStringAuto($Bstr) | |
$Marshal::ZeroFreeBSTR($Bstr) | |
#Define the Cisco UCS CIMC FQDN | |
$UCSCIMC = "host.domain.com" | |
# Disable SSL certificate checking so we can connect to servers using a cert signed by a private CA | |
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} | |
#Send the requests using TLS1.2 | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
# Initial POST with username and password to get the API session cookie | |
$Auth = @{uri = "https://$UCSCIMC/nuova"; | |
Method = 'POST'; | |
Body = "<aaaLogin inName='$UserName' inPassword='$Password'></aaaLogin>"; | |
} | |
[xml]$AuthXML = Invoke-WebRequest @Auth -UseBasicParsing | |
# Extract and Escape any troublesome characters in the API session cookie | |
$AuthCookie = $AuthXML.aaaLogin.outCookie | |
$CleanAuthCookie = [RegEx]::Escape($AuthCookie) | |
# POST Request to get the Health status of the StorageController | |
$StorageQuery = @{uri = "https://$UCSCIMC/nuova"; | |
Method = 'POST'; | |
Body = "<configResolveClass cookie='$CleanAuthCookie' classId='storageControllerProps' inHierarchical='false'/>"; | |
} | |
[xml]$StorageQueryXML = invoke-restmethod @StorageQuery | |
#Tidy up by logging out of the API Session | |
invoke-restmethod -Method post -uri "https://$UCSCIMC/nuova" -body "<aaaLogout inCookie='$CleanAuthCookie' />" | Out-Null | |
#Extract the value of the health property from the response | |
$StorageHealth = $StorageQueryXML.configResolveClass.outConfigs.storageControllerProps.health | |
# If the result isnt Good then set the error flag | |
If ($StorageHealth -ne "Good") { | |
$StorageHealthState = 1 | |
} | |
Else { | |
$StorageHealthState = 0 | |
} | |
#Output for PRTG | |
Write-Host "<prtg>" | |
Write-Host "<result>" | |
"<channel>Storage_Health</channel>" | |
"<value>$StorageHealthState</value>" | |
"<showChart>1</showChart>" | |
"<showTable>1</showTable>" | |
"<LimitMaxError>0</LimitMaxError>" | |
"<LimitMode>1</LimitMode>" | |
"</result>" | |
Write-Host "<Text>$StorageHealth</Text>" | |
Write-Host "</prtg>" | |
} | |
#If try code block fails then throw an error to PRTG | |
catch | |
{ | |
Write-Host "<prtg>" | |
Write-host "<error>1</error>" | |
Write-Host "<text>Sensor Error</text>" | |
Write-Host "</prtg>" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment