VMware Cloud Community
Dinu26
Contributor
Contributor
Jump to solution

Passing host name to triggered alarm

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
Dinu26
Contributor
Contributor
Jump to solution

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

pastedImage_0.png

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos