HI Luc,
just thought of putting sepatate script for alarms .
this is calculting alarm at cluster level .if you cud suggest on following points.
1:will it include all alarms of all viobjects (vms.esxi.datastores)inside cluster ??
2.can you modify it so that cluster name part has different color everytime it loops.
$path1 = 'D:\hc'
$path = "D:\hc\data-$(Get-Date -Format 'yyyyMMdd-HHmm').html"
$head = @'
<style>
body { background-color:#dddddd;
font-family:Tahoma;
font-size:12pt; }
td, th { border:1px solid black;
border-collapse:collapse; }
th { color:white;
background-color:black; }
table, tr, td, th { padding: 2px; margin: 0px }
table { margin-left:50px; }
</style>
'@
$fragments = @()
$clusters=get-cluster
foreach ($line in $clusters) {
$cluster = Get-Cluster -name $line
foreach ($triggered in $cluster.ExtensionData.TriggeredAlarmState)
{
If ($triggered.OverallStatus -like "red" -or $triggered.OverallStatus -like "yellow" )
{
#Write-Host "check alarm on " $e.Name -ForegroundColor Yellow
$lineitem = { } | Select Name, AlarmInfo
$alarmDef = Get-View -Id $triggered.Alarm
$lineitem.Name = $e.Name
$lineitem.AlarmInfo = $alarmDef.Info.Name
$Report += $lineitem
}
}
$fragments += $cluster|select name | Convertto-html -property name -precontent '<h2>clustername</h2>'|out-string
$fragments += $report |
ConvertTo-Html -PreContent '<h2>clusteralarm</h2>' |
Out-String
}
ConvertTo-HTML -head $head -PostContent $fragments |Out-String | Out-File -FilePath $path
1. I'm afraid only partially.
A VSAN datastore is defined on the cluster level, so yes, alarms for a VSAN datastore will be shown.
But other datastores are connected on the Datacenter level, they will not be shown in your report.
2. There are many ways of doing that, and they would probably all require a web designer (which I'm not) to do it right :smileygrin:
Just a small example, where the background colour is selected randomly from 4 defined colours.
$path = "D:\hc\data-$(Get-Date -Format 'yyyyMMdd-HHmm').html"
$head = @'
<style>
body { background-color:#dddddd;
font-family:Tahoma;
font-size:12pt; }
td, th { border:1px solid black;
border-collapse:collapse; }
th { color:white;
background-color:black; }
table, tr, td, th { padding: 2px; margin: 0px }
table { margin-left:50px; }
.green{background-color:#008000}
.blue{background-color:#0000ff}
.red{background-color:#ff0000}
.yellow{background-color:#ffff00}
</style>
'@
$colors = 'green', 'blue', 'red', 'yellow'
$fragments = @()
$clusters = get-cluster
foreach ($line in $clusters)
{
$cluster = Get-Cluster -name $line
foreach ($triggered in $cluster.ExtensionData.TriggeredAlarmState)
{
If ($triggered.OverallStatus -like "red" -or $triggered.OverallStatus -like "yellow" )
{
#Write-Host "check alarm on " $e.Name -ForegroundColor Yellow
$lineitem = { } | Select Name, AlarmInfo
$alarmDef = Get-View -Id $triggered.Alarm
$lineitem.Name = $e.Name
$lineitem.AlarmInfo = $alarmDef.Info.Name
$Report += $lineitem
}
}
$fragments += ConvertTo-Html -PreContent '<h2>clustername</h2>' | out-string
[xml]$clus = $cluster | select name | Convertto-html -property name -Fragment
$clus.table.tr[1].SetAttribute('class', "$($colors | Get-Random)")
$fragments += $clus.InnerXml | Out-String
$fragments += $report |
ConvertTo-Html -PreContent '<h2>clusteralarm</h2>' |
Out-String
}
ConvertTo-HTML -head $head -PostContent $fragments | Out-String | Out-File -FilePath $path
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
1. I'm afraid only partially.
A VSAN datastore is defined on the cluster level, so yes, alarms for a VSAN datastore will be shown.
But other datastores are connected on the Datacenter level, they will not be shown in your report.
2. There are many ways of doing that, and they would probably all require a web designer (which I'm not) to do it right :smileygrin:
Just a small example, where the background colour is selected randomly from 4 defined colours.
$path = "D:\hc\data-$(Get-Date -Format 'yyyyMMdd-HHmm').html"
$head = @'
<style>
body { background-color:#dddddd;
font-family:Tahoma;
font-size:12pt; }
td, th { border:1px solid black;
border-collapse:collapse; }
th { color:white;
background-color:black; }
table, tr, td, th { padding: 2px; margin: 0px }
table { margin-left:50px; }
.green{background-color:#008000}
.blue{background-color:#0000ff}
.red{background-color:#ff0000}
.yellow{background-color:#ffff00}
</style>
'@
$colors = 'green', 'blue', 'red', 'yellow'
$fragments = @()
$clusters = get-cluster
foreach ($line in $clusters)
{
$cluster = Get-Cluster -name $line
foreach ($triggered in $cluster.ExtensionData.TriggeredAlarmState)
{
If ($triggered.OverallStatus -like "red" -or $triggered.OverallStatus -like "yellow" )
{
#Write-Host "check alarm on " $e.Name -ForegroundColor Yellow
$lineitem = { } | Select Name, AlarmInfo
$alarmDef = Get-View -Id $triggered.Alarm
$lineitem.Name = $e.Name
$lineitem.AlarmInfo = $alarmDef.Info.Name
$Report += $lineitem
}
}
$fragments += ConvertTo-Html -PreContent '<h2>clustername</h2>' | out-string
[xml]$clus = $cluster | select name | Convertto-html -property name -Fragment
$clus.table.tr[1].SetAttribute('class', "$($colors | Get-Random)")
$fragments += $clus.InnerXml | Out-String
$fragments += $report |
ConvertTo-Html -PreContent '<h2>clusteralarm</h2>' |
Out-String
}
ConvertTo-HTML -head $head -PostContent $fragments | Out-String | Out-File -FilePath $path
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
tx I m checking.