Have configured alarm action to run a command, Is there a way for me to pass the Esxi host name for which the alarm has been triggered ?
TIA
Have a look at Horst's (oldish) document named Fun with vSphere Alarms
In section 5 of that document he demonstrates a method to discover all environment variables that are available when an alarm is fired.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
When an Alarm is fired, there are a number of environment variables available, see Alarm Environment Variables for Scripts.
The hostname is in VMWARE_ALARM_EVENT_HOST.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Thanks Much for the response.
Am being dumb here,
Have tried passing the host name through alarm as well as script, But am unable to figure it out.
I tried with TargetName and VMWARE_ALARM_TARGET_NAME but no luck
Below is what I have in TT.cmd.
Set Parm1= {VMWARE_ALARM_TARGET_NAME}
echo "am being called" >> "C:\ProgramData\VMware\VMware VirtualCenter\scripts\test.txt"
echo Parm1 >> "C:\ProgramData\VMware\VMware VirtualCenter\scripts\test.txt"
C:\Windows\System32\cmd.exe /c powershell.exe -noninteractive -noprofile -file "C:\ProgramData\VMware\VMware VirtualCenter\scripts\tt.ps1" %Parm1%
Below is the code in tt.ps1
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$Test
)
write-host $Test
$ExchangeServer = "***********"
$FromAddress = "**********"
$to = "**************"
$te = "Am being called by Alarm"
$te | Out-File -filepath "C:\ProgramData\VMware\VMware VirtualCenter\scripts\test.txt" -Append
Send-MailMessage -from $FromAddress -To $to -Body "test 1 and $Test" -Subject "top" -SmtpServer $ExchangeServer
Have a look at Horst's (oldish) document named Fun with vSphere Alarms
In section 5 of that document he demonstrates a method to discover all environment variables that are available when an alarm is fired.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference