Skip to content

Commit

Permalink
Take EMS and Events on the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Mar 7, 2017
1 parent ad838e6 commit d05d92b
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions tools/event_history.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
require 'rbvmomi'
require 'trollop'

def parse_args(argv)
opts = Trollop.options do
banner <<-EOS
Print all event history from the VC specified by the ems parameter
Usage:
rails r event_history.rb --ems=NAME_OF_EMS --events=[LIST,OF,EVENT,TYPES]
EOS

opt :ems, 'EMS name', :type => :string
opt :events, 'List of event types to include, e.g.: TaskEvent', :type => :string
end

opts
end

options = parse_args(ARGV)

ems = if options[:ems]
ManageIQ::Providers::Vmware::InfraManager.find_by(:name => options[:ems])
else
ManageIQ::Providers::Vmware::InfraManager.first
end

raise "EMS not found" if ems.nil?

#TODO parse command line args
ems = ManageIQ::Providers::Vmware::InfraManager.first
host = ems.hostname
user = ems.authentication_userid(:default)
password = ems.authentication_password(:default)
filter_events = ['TaskEvent', 'VmBeingDeployedEvent', 'VmDeployedEvent']
filter_events = options[:events].try(:split, ',') || []

connect_opts = {
:host => host,
Expand All @@ -23,8 +48,7 @@
eventCollector.RewindCollector()
until (events = eventCollector.ReadNextEvents(:maxCount => 100)).empty?
events.each do |event|
next if event.kind_of?(RbVmomi::VIM::TaskEvent) && event.info.name != 'CloneVM_Task'
puts "#{event.class.name} ID: #{event.key} Chain ID: #{event.chainId} Time: #{event.createdTime} VM: #{event.vm.vm}: #{event.fullFormattedMessage}"
puts "#{event.class.name} ID: #{event.key} Chain ID: #{event.chainId} Time: #{event.createdTime} #{event.fullFormattedMessage}"
end
end

Expand Down

0 comments on commit d05d92b

Please sign in to comment.