Hello @LucD , please help,I don't know how to implement host status check
$vmhosts=get-vmhost ((Get-AlarmDefinition -Name "Test alarm*").Entity)|?{$_.ConnectionState -eq "Connected"}
foreach ($vmhost in $vmhosts)
{
$vmhostCluster=Get-Cluster $vmhost.parent
if (($vmhostCluster|Get-VMHost|?{$_.State -ne "Connected"}).count -eq 0){Set-VMHost -VMHost $vmhost -State "Maintenance"}
next I want the email to be sent if the host Maintenance
If ( $ ) {$Body ="<h2> Host $ vmhost is faulty, enter to MM is not possible because another host is already output to MM. </h2>"} else {$ Body = "<h2> Host $ vmhost is faulty, enter to MM is starting </ h2> "}}
I'm not sure what exactly you mean by 'host memory status'.
Is that an Alarm that is fired?
Further, it seems you have a condition where an ESXi node can only be placed in maintenance mode when there is no other ESXi node in maintenance mode.
Are these ESXi nodes in the same cluster?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is that an Alarm that is fired? -Yes. it's default vcentr alarm "Host memory status".
$vmhosts=get-vmhost ((Get-AlarmDefinition -Name "Host memory status*").Entity)|?{$_.ConnectionState -eq "Connected"}
Further, it seems you have a condition where an ESXi node can only be placed in maintenance mode when there is no other ESXi node in maintenance mode - all right.I want to enter only 1 host to mm
No, they can be in different clusters- No, they can be in different clusters
$vmhostCluster=Get-Cluster $vmhost.parent
if (($vmhostCluster|Get-VMHost|?{$_.State -ne "Connected"}).count -eq 0){Set-VMHost -VMHost $vmhost -State "Maintenance"}
The next question is, where are you going to run that code that is triggered by the Alarm.
Is that a script that will run permanently on a dedicated station and monitor the Alarms?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I used this "https://docs.vmware.com/en/VMware-vSphere/6.7/com.vmware.vsphere.monitoring.doc/GUID-AB74502C-5F01-4...
I just need to add to the script the ability to check status and send mails.
That only works when you run your vCenter on a Windows server.
And that option doesn't exist anymore in vSphere 7.
Although technically possible, you shall not run scripts on a VCSA.
It might void your support.
And I will definitely not tell you how to do this.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Now we are using vcsa 6.7, support helped to solve this case, the script is running on linux server, vcsa is connected to the server via ssh with private key and satrt script, powercli is installed on this Linux server and it works
And how did support configure the Alarm action to trigger that script on another Linux server?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
in script mem_alarm:
#!/bin/sh
ssh user@host sudo pwsh /tmp/mem_alarm.ps1
in script mem_alarm.ps1:
$ErrorActionPreference= 'Stop'
$vmhosts=get-vmhost ((Get-AlarmDefinition -Name "Test alarm*").Entity)|?{$_.ConnectionState -eq "Connected"}
foreach ($vmhost in $vmhosts)
{
$vmhostCluster=Get-Cluster $vmhost.parent
if (($vmhostCluster|Get-VMHost|?{$_.State -ne "Connected"}).count -eq 0){Set-VMHost -VMHost $vmhost -State "Maintenance"}
$ErrorActionPreference= 'Continue'
Disconnect-VIServer -Confirm:$false
If ( $ ) {$Body ="<h2> Host $ vmhost is faulty, enter to MM is not possible because another host is already output to MM. </h2>"} else {$ Body = "<h2> Host $ vmhost is faulty, enter to MM is starting </ h2> "}}
$SmtpServer = ""
$From = ""
$myemail=""
$MessageBody = $Body
$MailMessage = New-Object System.Net.Mail.MailMessage($From,$myemail,$Subject,$MessageBody)
$MailMessage.IsBodyHtml = $True
$MailMessage.Priority = [System.Net.Mail.MailPriority]::High
(New-Object Net.Mail.SmtpClient($SMTPServer)).Send($MailMessage)
The screenshot shows a test alarm, I will change it to a memory alarm
@nikpetrov95 Honestly I would use vSphere ProActive HA if i were you.
This will automatically enter the host into maintenance mode if hardware errors have been seen. You do however need to have hardware that supports this and use an according license (Enteprise Plus).
That script by the looks of it runs on your VCSA
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm not sure how ProActive HA can handle memory usage?
That feature handles HW failures afaik.
Oh, and please stop begging for points.
That is not even a thing anymore on the new Khoros platform
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This does not suit us, additional licenses are required, for example, due to integration with dell ome
VCSA is connected to a remote host and runs a script on the remote host
It doesn't so you are right. I misinterpreted the alarm in question. ProActive HA is for HW failures.
That mem_alarm script runs on your VCSA and triggers a script on another server.
You are definitely running a script on your VCSA.
I'm amazed that support (do you mean GSS) provided you with that.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for confirming that, and cleaning up your footer 😀
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can you help me finish the script?
Sure no problem, footer was from a long time ago, didn't een know it was there anymore :).
In regards to the vSphere ProActive HA situation, this works really really well on hardware issues. But it does come with a cost in regards to licensing.
Back on topic, like you said it's not supported to run this on the VCSA itself. If @nikpetrov95 runs this on another server (which doesn't look like it), is it the mail part that is not working now, or the entering maintenance mode? If the maintenance mode part, please check your condition.