HPE PRO diagnostic script.

HewlettPackard.Servers.ProLiant.SNMPPRO.DiagnosticAction (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
DiagnosticAction WriteAction System.CommandExecuter Default

Overrideable Parameters:

IDParameterTypeSelector
EventDescriptionstring$Config/EventDescription$

Source Code:

<WriteActionModuleType ID="HewlettPackard.Servers.ProLiant.SNMPPRO.DiagnosticAction" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="EventDescription" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="EventDescription" Selector="$Config/EventDescription$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="DiagnosticAction" TypeID="System!System.CommandExecuter">
<ApplicationName>%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>"&amp; '$file/Hewlett-PackardPROVMDiagnostic.ps1$' '$Config/EventDescription$'"</CommandLine>
<TimeoutSeconds>360</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>Hewlett-PackardPROVMDiagnostic.ps1</Name>
<Contents><Script>
function GetProScript {
####################### BEGIN
'
function new-array { $args }
function FailGenericError
{
Param ([string]$proTipID, [string]$message)
eventcreate /T Error /ID 310 /L Application /SO "HP PRO MP" /D "Fail: $message `n[PROTipID: + $proTipID]"
Set-PROTip -PROTipID $proTipID -ActionDetails $message -TipStatus Failed | Select Name,Source,Severity,Status
}
function FailHostNotFound
{
Param ([string]$proTipID, [string]$message)
eventcreate /T Error /ID 311 /L Application /SO "HP PRO MP" /D "Fail: No source host found. `n[PROTipID: $proTipID]"
$params = new-array "$MPElement[Name='ProMessage.SourceHostNotfound']$" $message
Set-PROTip -PROTipID $proTipID -ActionDetailsOpsMgrString $params -TipStatus Failed | Select Name,Source,Severity,Status
}
function FailNoQuickMoveAvailable
{
Param ([string]$proTipID, [string]$message)
eventcreate /T Error /ID 312 /L Application /SO "HP PRO MP" /D "Fail: No quick move or cluster available. `n[PROTipID: $proTipID]"
$params = new-array "$MPElement[Name='ProMessage.NoQuickMoveAvailable']$" $message
Set-PROTip -PROTipID $proTipID -ActionDetailsOpsMgrString $params -TipStatus Failed | Select Name,Source,Severity,Status
}
function FailNoVMToMigrate
{
Param ([string]$proTipID, [string]$message)
eventcreate /T Error /ID 313 /L Application /SO "HP PRO MP" /D "Fail: No virtual machine found to migrate. `n[PROTipID: $proTipID]"
$params = new-array "$MPElement[Name='ProMessage.NoVMFound.MigrationEligible']$" $message
Set-PROTip -PROTipID $proTipID -ActionDetailsOpsMgrString $params -TipStatus Failed | select Name,Source,Severity,Status
}
function FailNoHostToMigrateTo
{
Param ([string]$proTipID, [string]$message)
eventcreate /T Error /ID 314 /L Application /SO "HP PRO MP" /D "Fail: No target host found to migrate. `n[PROTipID: $proTipID]"
$params = new-array "$MPElement[Name='ProMessage.TargetHostNotfound']$" $message
Set-PROTip -PROTipID $proTipID -ActionDetailsOpsMgrString $params -TipStatus Failed | select Name,Source,Severity,Status
}

$Error.Clear()
Add-PsSnapIn "Microsoft.SystemCenter.VirtualMachineManager"
if ($Error.Count -ne 0) {
$message = $Error[0]
eventcreate /T Error /ID 315 /L Application /SO "HP PRO MP" /D "$message: Virtual Machine Manager PowerShell SnapIn is not configured on the system."
return
}

$eventContent = $args[0].Split(":")
if ($eventContent.Count -lt 4) {
$message = $args[0]
eventcreate /T Error /ID 316 /L Application /SO "HP PRO MP" /D "Invalid number of parameters are passed to the script. $message"
return
}

$hostName = $eventContent[0].Trim()
$serverName = $eventContent[1].Trim()
$proTipID = $eventContent[2].Trim()
$moveMode = $eventContent[3].Replace("\n","").Trim()
if (($hostName.Length -eq 0) -or ($serverName.Length -eq 0) -or ($proTipID.Length -eq 0) -or (($moveMode -ne "QuickMove") -and ($moveMode -ne "LANMove"))) {
$message = $args[0]
eventcreate /T Error /ID 317 /L Application /SO "HP PRO MP" /D "Invalid parameter content. $message"
return
}

eventcreate /T Information /ID 302 /L Application /SO "HP PRO MP" /D "Starting implementation. Host: $hostName, Server: $serverName, PRO Tip ID: $proTipID, Move mode: $moveMode"

$Error.Clear()
$serverObj = Get-VMMServer -ComputerName $serverName
if ($Error.Count -ne 0) {
FailGenericError $proTipID $Error[0]
return
}

Set-PROTip -PROTipID $proTipID -TipStatus Running | Select Name,Source,Severity,Status

$hostObj = Get-VMHost -ComputerName $hostName -VMMServer $serverObj
if ($hostObj -eq $null) {
FailHostNotFound $proTipID $hostName
return
}
$hostObj | Get-VM | Select Name,HostName
if ($hostObj.VMs.Count -eq 0) {
FailNoVMToMigrate $proTipID $hostName
return
}

$targetVMs = @()
foreach ($cVM in $hostObj.VMs | where { ($_.Status -eq "Running") -and ($_.ExcludeFromPRO -ne $true)} ) {
$targetVMs = $targetVMs + $cVM
}
if ($targetVMs.Count -eq 0) {
FailNoVMToMigrate $proTipID $hostName
return
}

$isQuickMigration = $false
$hostList = @()
Get-VMhost | select Name
if (($hostObj.HostCluster -ne $null ) -and ($hostObj.HostCluster.Nodes.Count -ne 1)) {
foreach ($tmpHost in $hostObj.HostCluster.Nodes) {
if ($tmpHost.Name -ne $hostObj.Name ) {
$hostList = $hostList + $tmpHost
$isQuickMigration = $true
}
}
} else {
foreach ($tmpHost in $hostObj.VMHostGroup.Hosts) {
if ($tmpHost.Name -ne $hostObj.Name) {
$hostList = $hostList + $tmpHost
}
}
}

if (($hostList -eq $null) -or ($hostList.Count -eq 0)) {
FailNoHostToMigrateTo $proTipID $hostName
return
}

if (($moveMode -eq "QuickMove") -and ($isQuickMigration -eq $false)) {
FailNoQuickMoveAvailable $proTipID $hostName
return
}

foreach ($targetVM in $targetVMs) {
$vmHostRatings = @()
$vmHostRatings = $vmHostRatings + ( @(Get-VMHostRating -VM $targetVM -VMHost $hostList -IsMigration -UseDefaultPath) | Sort-Object -property Rating -Descending | where { $_.Rating -ne 0 } )
if ($vmHostRatings.Count -eq $null) {
FailNoHostToMigrateTo $proTipID $hostName
return
}

$targetVMHost = $hostList | where { ($_.Name -eq $vmHostRatings[0].VMHost.Name) }
if ($targetVMHost -eq $null) {
FailNoHostToMigrateTo $proTipID $hostName
return
}

$Error.Clear()
if ($isQuickMigration) {
Move-VM -VM $targetVM -VMHost $targetVMHost -PROTipID $proTipID
} else {
Move-VM -VM $targetVM -VMHost $targetVMHost -PROTipID $proTipID -Path $targetVMHost.VMPaths[0]
}
if ($Error.Count -ne 0) {
FailGenericError $proTipID $Error[0]
return
}
}

Set-PROTip -PROTipID $proTipID -TipStatus Resolved | select Name,Source,Severity,Status
eventcreate /T Information /ID 303 /L Application /SO "HP PRO MP" /D "Completed implementation. Host: $hostName, Server: $serverName, PRO Tip ID: $proTipID, Move mode: $moveMode"
Sleep 10
Set-VMHost -VMHost $hostName -AvailableForPlacement $false | select Name
eventcreate /T Information /ID 304 /L Application /SO "HP PRO MP" /D "Removed virtual machine placement availability to the host: $hostName, PRO Tip ID: $proTipID"
'
####################### END
}
function SetProScript {
$ScriptBody = GetProScript
Set-PROTip -PROTipID $proTipID -ActionScript $ScriptBody | select Name,Source,Severity,Status
}
function SetStatusQuickMove {
$paramsDetails = new-array "$MPElement[Name='ProMessage.QuickMoveDetails']$" $args[1] $args[2] $args[3]
$paramsSummary = new-array "$MPElement[Name='ProMessage.QuickMoveSummary']$"
Set-PROTip -PROTipID $args[0] -ActionDetailsOpsMgrString $paramsDetails -ActionSummaryOpsMgrString $paramsSummary | select Name,Source,Severity,Status
}
function SetStatusLANMove {
$paramsDetails = new-array "$MPElement[Name='ProMessage.LANMoveDetails']$" $args[1] $args[2] $args[3]
$paramsSummary = new-array "$MPElement[Name='ProMessage.LANMoveSummary']$"
Set-PROTip -PROTipID $args[0] -ActionDetailsOpsMgrString $paramsDetails -ActionSummaryOpsMgrString $paramsSummary | select Name,Source,Severity,Status
}
function SetStatus {
switch($args[1]) {
"QuickMove" {
SetStatusQuickMove $args[0] $args[2] $args[3] $args[4]
}
"LANMove" {
SetStatusLANMove $args[0] $args[2] $args[3] $args[4]
}
}
}
function new-array { $args }
function FailGenericError
{
Param ([string]$proTipID, [string]$message)
eventcreate /T Error /ID 310 /L Application /SO "HP PRO MP" /D "Fail: $message `n[PROTipID: $proTipID]"
Set-PROTip -PROTipID $proTipID -ActionDetails $message -TipStatus Failed | Select Name,Source,Severity,Status
}
function FailHostNotFound
{
Param ([string]$proTipID, [string]$message)
eventcreate /T Error /ID 311 /L Application /SO "HP PRO MP" /D "Fail: No source host found. `n[PROTipID: $proTipID]"
$params = new-array "$MPElement[Name='ProMessage.SourceHostNotfound']$" $message
Set-PROTip -PROTipID $proTipID -ActionDetailsOpsMgrString $params -TipStatus Failed | Select Name,Source,Severity,Status
}
function FailNoQuickMoveAvailable
{
Param ([string]$proTipID, [string]$message)
eventcreate /T Error /ID 312 /L Application /SO "HP PRO MP" /D "Fail: No quick move or cluster available. `n[PROTipID: $proTipID]"
$params = new-array "$MPElement[Name='ProMessage.NoQuickMoveAvailable']$" $message
Set-PROTip -PROTipID $proTipID -ActionDetailsOpsMgrString $params -TipStatus Failed | Select Name,Source,Severity,Status
}
function FailNoVMToMigrate
{
Param ([string]$proTipID, [string]$message)
eventcreate /T Error /ID 313 /L Application /SO "HP PRO MP" /D "Fail: No virtual machine found to migrate. `n[PROTipID: $proTipID]"
$params = new-array "$MPElement[Name='ProMessage.NoVMFound.MigrationEligible']$" $message
Set-PROTip -PROTipID $proTipID -ActionDetailsOpsMgrString $params -TipStatus Failed | select Name,Source,Severity,Status
}
function FailNoHostToMigrateTo
{
Param ([string]$proTipID, [string]$message)
eventcreate /T Error /ID 314 /L Application /SO "HP PRO MP" /D "Fail: No target host found to migrate. `n[PROTipID: $proTipID]"
$params = new-array "$MPElement[Name='ProMessage.TargetHostNotfound']$" $message
Set-PROTip -PROTipID $proTipID -ActionDetailsOpsMgrString $params -TipStatus Failed | select Name,Source,Severity,Status
}

$Error.Clear()
Add-PsSnapIn "Microsoft.SystemCenter.VirtualMachineManager"
if ($Error.Count -ne 0) {
$message = $Error[0]
eventcreate /T Error /ID 315 /L Application /SO "HP PRO MP" /D "$message: Virtual Machine Manager PowerShell SnapIn is not configured on the system."
return
}

$eventContent = $args[0].Split(":")
if ($eventContent.Count -lt 4) {
$message = $args[0]
eventcreate /T Error /ID 316 /L Application /SO "HP PRO MP" /D "Invalid number of parameters are passed to the script. $message"
return
}

$hostName = $eventContent[0].Trim()
$serverName = $eventContent[1].Trim()
$proTipID = $eventContent[2].Trim()
$moveMode = $eventContent[3].Replace("\n","").Trim()
if (($hostName.Length -eq 0) -or ($serverName.Length -eq 0) -or ($proTipID.Length -eq 0) -or (($moveMode -ne "QuickMove") -and ($moveMode -ne "LANMove"))) {
$message = $args[0]
eventcreate /T Error /ID 317 /L Application /SO "HP PRO MP" /D "Invalid parameter content. $message"
return
}

eventcreate /T Information /ID 300 /L Application /SO "HP PRO MP" /D "Starting diagnostic. Host: $hostName, Server: $serverName, PRO Tip ID: $proTipID, Move mode: $moveMode"

$Error.Clear()
$serverObj = Get-VMMServer -ComputerName $serverName
if ($Error.Count -ne 0) {
FailGenericError $proTipID $Error[0]
return
}

SetProScript

$hostObj = Get-VMHost -ComputerName $hostName -VMMServer $serverObj
if ($hostObj -eq $null) {
FailHostNotFound $proTipID $hostName
return
}
$hostObj | Get-VM | Select Name,HostName
if ($hostObj.VMs.Count -eq 0) {
FailNoVMToMigrate $proTipID $hostName
return
}

$targetVMs = @()
foreach ($cVM in $hostObj.VMs | where { ($_.Status -eq "Running") -and ($_.ExcludeFromPRO -ne $true)} ) {
$targetVMs = $targetVMs + $cVM
}
if ($targetVMs.Count -eq 0) {
FailNoVMToMigrate $proTipID $hostName
return
}

$isQuickMigration = $false
$hostList = @()
Get-VMhost | select Name
if (($hostObj.HostCluster -ne $null ) -and ($hostObj.HostCluster.Nodes.Count -ne 1)) {
foreach ($tmpHost in $hostObj.HostCluster.Nodes) {
if ($tmpHost.Name -ne $hostObj.Name ) {
$hostList = $hostList + $tmpHost
$isQuickMigration = $true
}
}
} else {
foreach ($tmpHost in $hostObj.VMHostGroup.Hosts) {
if ($tmpHost.Name -ne $hostObj.Name) {
$hostList = $hostList + $tmpHost
}
}
}

if (($hostList -eq $null) -or ($hostList.Count -eq 0)) {
FailNoHostToMigrateTo $proTipID $hostName
return
}

if (($moveMode -eq "QuickMove") -and ($isQuickMigration -eq $false)) {
FailNoQuickMoveAvailable $proTipID $hostName
return
}

foreach ($targetVM in $targetVMs) {
$vmHostRatings = @()
$vmHostRatings = $vmHostRatings + ( @(Get-VMHostRating -VM $targetVM -VMHost $hostList -IsMigration -UseDefaultPath) | Sort-Object -property Rating -Descending | where { $_.Rating -ne 0 } )
if ($vmHostRatings.Count -eq $null) {
FailNoHostToMigrateTo $proTipID $hostName
return
}

$targetVMHost = $hostList | where { ($_.Name -eq $vmHostRatings[0].VMHost.Name) }
if ($targetVMHost -eq $null) {
FailNoHostToMigrateTo $proTipID $hostName
return
}

SetStatus $proTipID $moveMode $targetVM.Name $hostName $targetVMHost.Name
eventcreate /T Information /ID 301 /L Application /SO "HP PRO MP" /D "Completed diagnostic. Host: $hostName, Server: $serverName, PRO Tip ID: $proTipID, Move mode: $moveMode"
return
}
</Script></Contents>
</File>
</Files>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="DiagnosticAction"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>