Is there a way to log a custom message to VM virtual center ?
I use a vCLI script to reset a vm. I want to report from where (which PC ) this script is initiated.
And it would be great if it is possible to report this to the event or task list of the VM which is going to be reset.
You can report from where and who this script is initiated by following script
#!/usr/bin/perl -w # CustomEvent.pl # use strict; use warnings; use VMware::VILib; use VMware::VIRuntime; my %opts = ( vmname => { type => "=s", help => "Name the virtual machine associated with the event", required => 1, }, ); Opts::add_options(%opts); Opts::parse(); Opts::validate(); Util::connect(); my $vmname = Opts::get_option('vmname'); my $username, my $compname; ($username = `echo %USERNAME%`) =~ /(\S+)/; $username = $1; ($compname = `echo %COMPUTERNAME%`) =~ /(\S+)/; $compname = $1; my $EventManager = Vim::get_service_content()->eventManager; my $EventManager_view = Vim::get_view(mo_ref => $EventManager); my $vm_ref = Vim::find_entity_view(view_type => 'VirtualMachine', filter => {'name' => $vmname}); eval { $EventManager_view->LogUserEvent(entity => $vm_ref, msg => "CE_RESTARTVM : VM $vmname restarted by $username from $compname."); Util::trace(0, "\n CUSTOMEVENT \'VM $vmname restarted by $username from $compname.\' post Successfully.\n"); }; if ($@) {print "Error: ". $@ . "\n";} Util::disconnect();
You can report from where and who this script is initiated by following script
#!/usr/bin/perl -w # CustomEvent.pl # use strict; use warnings; use VMware::VILib; use VMware::VIRuntime; my %opts = ( vmname => { type => "=s", help => "Name the virtual machine associated with the event", required => 1, }, ); Opts::add_options(%opts); Opts::parse(); Opts::validate(); Util::connect(); my $vmname = Opts::get_option('vmname'); my $username, my $compname; ($username = `echo %USERNAME%`) =~ /(\S+)/; $username = $1; ($compname = `echo %COMPUTERNAME%`) =~ /(\S+)/; $compname = $1; my $EventManager = Vim::get_service_content()->eventManager; my $EventManager_view = Vim::get_view(mo_ref => $EventManager); my $vm_ref = Vim::find_entity_view(view_type => 'VirtualMachine', filter => {'name' => $vmname}); eval { $EventManager_view->LogUserEvent(entity => $vm_ref, msg => "CE_RESTARTVM : VM $vmname restarted by $username from $compname."); Util::trace(0, "\n CUSTOMEVENT \'VM $vmname restarted by $username from $compname.\' post Successfully.\n"); }; if ($@) {print "Error: ". $@ . "\n";} Util::disconnect();
thanks....
sry for the response time... but vacation ..... what can I say...
thanks....
sry for the response time... but vacation ..... what can I say...