VMware Cloud Community
vcpguy
Expert
Expert

Getting Alerts with username in email !!!

Hi, how can I get the username of the person who triggered a event in vsphere with the help of alarms?

Example- I can get the alert if someone disbaled the drs on the cluster.But i need to know who did that in the e-mail alert itself and not searching in the events section on VI client.

Any ideas/suggeations.

P.S this is the nice link of vsphere alerts

http://communities.vmware.com/docs/DOC-12145


Thanks

----------------------------------------------------------------------------- Please don't forget to reward Points for helpful hints; answers; suggestions. My blog: http://vmwaredevotee.com
Tags (3)
0 Kudos
6 Replies
hicksj
Virtuoso
Virtuoso

If you process the alert via external command (see "Run a Command" and associated info pgs.11-13 of the doc you referenced), then an environment variable with the username is available:  VMWARE_ALARM_EVENT_USERNAME

Regards,

J

0 Kudos
vcpguy
Expert
Expert

Thanks for the info. But, I am not sure, how can I implement this. Can you please explain with an example.

Thanks

----------------------------------------------------------------------------- Please don't forget to reward Points for helpful hints; answers; suggestions. My blog: http://vmwaredevotee.com
0 Kudos
MauroBonder
VMware Employee
VMware Employee

go to vcenter in alarm tab > definitions > new alarm or edit > actions > add > send a notification email > in configuration space put email dsired.

configure in vcenter - Administration > vCenter Server Settings > Mail.

Please, don't forget the awarding points for "helpful" and/or "correct" answers.     Mauro Bonder - Moderator

*Please, don't forget the awarding points for "helpful" and/or "correct" answers. *Por favor, não esqueça de atribuir os pontos se a resposta foi útil ou resolveu o problema.* Thank you/Obrigado
0 Kudos
hicksj
Virtuoso
Virtuoso

Are you familiar at all with any scripting?  VB, Perl, PowerShell?  Use whatever is most comfortable...

All you need to do is

- use one of their native functions to read in environment variables.  In perl, for example, reading the event's username from the command session would be:  "my $eventUser = $ENV{VMWARE_ALARM_EVENT_USERNAME};"

- repeat for the other variables you are interested in, such as "my $eventDesc = $ENV{VMWARE_ALARM_EVENTDESCRIPTION};"

- use an SMTP function within the scripting tool, such as "use Net::SMTP;" in perl  (if not obvious, I'm normally use perl)

- build a message body from the variables that vCenter passes to the command session, and send it.  (there are tons of examples out on the 'net on how to do this)

There are lots of sample scripts up on VMTN as well.  Some powershell samples can be found here: http://communities.vmware.com/community/vmtn/developer/codecentral/vsphere_powercli

If I had already coded the above, I'd be happy to share.  I see value in coding this up, so if I get some time to do so, I'll post it up.  If you go ahead and do it, please post for everyone to use.

It would be nice if the "Send a notification email" action in the alert settings had a template that could be modified.  That would be a lot easier than breaking out to a command prompt to execute an external script...  However, there are a lot of short comings in vCenter's alert function.  In an external script, you could also check for time of day - maybe you don't care about particular events after 8pm at night, or maybe you want to keep track of the number of events and only execute a notification if the event happens 5 times in an hour.  There's a lot more flexibility with scripting, and correspondingly more work Smiley Wink

Regards,

0 Kudos
hicksj
Virtuoso
Virtuoso

Mauro,

The OP is not having problems sending the mail, its the format of the message.  They want additional information (i.e. who triggered the event that caused the alert).

0 Kudos
MauroBonder
VMware Employee
VMware Employee

that´s ok .

Now i understand what he need. Smiley Wink about powercli i´m not expert to help.

*Please, don't forget the awarding points for "helpful" and/or "correct" answers. *Por favor, não esqueça de atribuir os pontos se a resposta foi útil ou resolveu o problema.* Thank you/Obrigado
0 Kudos