Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move event filters into the database. #3636

Merged
merged 8 commits into from
Aug 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions app/models/blacklisted_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
class BlacklistedEvent < ActiveRecord::Base
belongs_to :ext_management_system, :foreign_key => "ems_id"

default_value_for :enabled, true
after_save :queue_sync_blacklisted_event_names
after_destroy :queue_sync_blacklisted_event_names, :audit_deletion
after_create :audit_creation

def audit_deletion
$audit_log.info("Blacklisted event [#{event_name}] for provider [#{provider_model}] with ID [#{ems_id}] has been deleted by user [#{self.class.current_userid}]")
end

def audit_creation
$audit_log.info("Creating blacklisted event [#{event_name}] for provider [#{provider_model}] with ID [#{ems_id}] by user [#{self.class.current_userid}]")
end

def enabled=(value)
return if enabled == value

super
$audit_log.info("Blacklisted event [#{event_name}] for provider [#{provider_model}] with ID [#{ems_id}] had enabled changed to #{value} by user [#{self.class.current_userid}]")
end

def self.seed
MiqRegion.my_region.lock do
ExtManagementSystem.descendants.each do |ems|
missing_events = ems.default_blacklisted_event_names - where(:provider_model => ems.name, :ems_id => nil).pluck(:event_name)
create(missing_events.collect { |e| {:event_name => e, :provider_model => ems.name, :system => true} })
end
end
end

def self.current_userid
User.current_userid || 'system'
end

def queue_sync_blacklisted_event_names
# notify MiqServer to sync with the blacklisted events
servers = MiqRegion.my_region.active_miq_servers
return if servers.blank?
_log.info("Queueing sync_blacklisted_event_names for [#{servers.length}] active_miq_servers, ids: #{servers.collect(&:id)}")

servers.each do |s|
MiqQueue.put(
:class_name => "MiqServer",
:instance_id => s.id,
:method_name => "sync_blacklisted_event_names",
:server_guid => s.guid,
:priority => MiqQueue::HIGH_PRIORITY,
:queue_name => 'miq_server'
)
end
end
end
34 changes: 0 additions & 34 deletions app/models/ems_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ def self.bottleneck_event_groups
VMDB::Config.new('event_handling').config[:bottleneck_event_groups]
end

def self.filtered_events
VMDB::Config.new('event_handling').config[:filtered_events]
end

def self.group_and_level(event_type)
group, v = self.event_groups.find { |k, v| v[:critical].include?(event_type) || v[:detail].include?(event_type) }
if group.nil?
Expand Down Expand Up @@ -102,8 +98,6 @@ def self.add(ems_id, event_hash)
process_availability_zone_in_event!(event_hash)
process_cluster_in_event!(event_hash)

return if events_filtered?(event_hash, self.filtered_events[event_type.to_sym])

# Write the event
new_event = create_event(event_hash)

Expand All @@ -113,34 +107,6 @@ def self.add(ems_id, event_hash)
return new_event
end

FILTER_KEYS = [
# Filter Key | Event Key | Object Description
#========================================================
['ems', :ems_id, "EMS" ],
['src_vm', :vm_or_template_id, "source VM" ],
['dest_vm', :dest_vm_or_template_id, "dest VM" ],
['src_host', :host_id, "source Host" ],
['dest_host', :dest_host_id, "dest Host" ]
]

def self.events_filtered?(event_hash, filter)
return false if filter.nil?

log_prefix = "Skipping caught event [#{event_hash[:event_type]}] chainId [#{event_hash[:chain_id]}]"
FILTER_KEYS.each do |filter_key, event_key, object_description|
if event_filtered?(event_hash, event_key, filter, filter_key)
_log.info "#{log_prefix} for #{object_description} [#{event_hash[event_key]}]"
return true
end
end

return false
end

def self.event_filtered?(event_hash, event_hash_key, filter, filter_key)
filter.has_key?(filter_key) && filter[filter_key].include?(event_hash[event_hash_key])
end

def self.process_object_in_event!(klass, event, options = {})
prefix = options[:prefix]
key_prefix = options[:key_prefix] || klass.name.underscore
Expand Down
16 changes: 16 additions & 0 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def self.supported_types_and_descriptions_hash
has_many :ems_events, -> { order "timestamp" }, :class_name => "EmsEvent", :foreign_key => "ems_id"
has_many :policy_events, -> { order "timestamp" }, :class_name => "PolicyEvent", :foreign_key => "ems_id"

has_many :blacklisted_events, :foreign_key => "ems_id", :dependent => :destroy
has_many :ems_folders, :foreign_key => "ems_id", :dependent => :destroy
has_many :ems_clusters, :foreign_key => "ems_id", :dependent => :destroy
has_many :resource_pools, :foreign_key => "ems_id", :dependent => :destroy
Expand Down Expand Up @@ -186,6 +187,10 @@ def self.provision_workflow_class
end
end

def self.default_blacklisted_event_names
[]
end

# UI methods for determining availability of fields
def supports_port?
false
Expand Down Expand Up @@ -477,4 +482,15 @@ def stop_event_monitor_queue_on_credential_change
self.stop_event_monitor_queue
end
end

def blacklisted_event_names
(
self.class.blacklisted_events.where(:enabled => true).pluck(:event_name) +
blacklisted_events.where(:enabled => true).pluck(:event_name)
).uniq.sort
end

def self.blacklisted_events
BlacklistedEvent.where(:provider_model => name, :ems_id => nil)
end
end
8 changes: 8 additions & 0 deletions app/models/manageiq/providers/amazon/cloud_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def self.hostname_required?
false
end

def self.default_blacklisted_event_names
%w(
ConfigurationSnapshotDeliveryCompleted
ConfigurationSnapshotDeliveryStarted
ConfigurationSnapshotDeliveryFailed
)
end

validates :provider_region, :inclusion => {:in => ManageIQ::Providers::Amazon::Regions.names}

def description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ def after_initialize
do_exit("Unable to find instance for EMS ID [#{@cfg[:ems_id]}].", 1) if @ems.nil?
do_exit("EMS ID [#{@cfg[:ems_id]}] failed authentication check.", 1) unless @ems.authentication_check.first

# Get the filtered events from the event_handling config
@filtered_events = VMDB::Config.new("event_handling").config[:filtered_events]
@filtered_events = @filtered_events.each_with_object([]) { |(k, v), ary| ary << k.to_s if v.nil? }
@filtered_events = @ems.blacklisted_event_names
_log.info "#{log_prefix} Event Catcher skipping the following events:"
$log.log_hashes(@filtered_events.sort)
$log.log_hashes(@filtered_events)

# Global Work Queue
@queue = Queue.new
Expand Down Expand Up @@ -64,6 +62,22 @@ def filtered_events
@filtered_events
end

# Called when there is any change in BlacklistedEvent
def sync_blacklisted_events
return unless @ems
filters = @ems.blacklisted_event_names

if @filtered_events.nil? || @filtered_events != filters
adds = filters - @filtered_events
deletes = @filtered_events - filters

@filtered_events = filters
_log.info("Synchronizing blacklisted events: #{filters}")
_log.info(" Blacklisted events added: #{adds}")
_log.info(" Blacklisted events deleted: #{deletes}")
end
end

def stop_event_monitor
raise NotImplementedError, "must be implemented in subclass"
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/manageiq/providers/openstack/cloud_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ def self.description
@description ||= "OpenStack".freeze
end

def self.default_blacklisted_event_names
%w(
scheduler.run_instance.start
scheduler.run_instance.scheduled
scheduler.run_instance.end
)
end

def supports_port?
true
end
Expand Down
11 changes: 11 additions & 0 deletions app/models/manageiq/providers/redhat/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ def self.description
@description ||= "Red Hat Enterprise Virtualization Manager".freeze
end

def self.default_blacklisted_event_names
%w(
UNASSIGNED
USER_REMOVE_VG
USER_REMOVE_VG_FAILED
USER_VDC_LOGIN
USER_VDC_LOGOUT
USER_VDC_LOGIN_FAILED
)
end

def supports_port?
true
end
Expand Down
20 changes: 20 additions & 0 deletions app/models/manageiq/providers/vmware/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ def self.provision_class(via)
end
end

def self.default_blacklisted_event_names
%w(
AlarmActionTriggeredEvent
AlarmCreatedEvent
AlarmEmailCompletedEvent
AlarmEmailFailedEvent
AlarmReconfiguredEvent
AlarmRemovedEvent
AlarmScriptCompleteEvent
AlarmScriptFailedEvent
AlarmSnmpCompletedEvent
AlarmSnmpFailedEvent
AlarmStatusChangedEvent
AlreadyAuthenticatedSessionEvent
EventEx
UserLoginSessionEvent
UserLogoutSessionEvent
)
end

def control_monitor
MiqControlMonitor.find_by_ems(self)
end
Expand Down
6 changes: 5 additions & 1 deletion app/models/miq_server/configuration_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def set_config_remote(cfg)
end

def sync_config
@blacklisted_events = true
@vmdb_config = VMDB::Config.new("vmdb")
sync_log_level
sync_worker_monitor_settings
Expand All @@ -77,7 +78,10 @@ def sync_config_changed?
VMDB::Config.invalidate("vmdb")
@vmdb_config = VMDB::Config.new("vmdb")
end
stale
stale || @blacklisted_events.nil?
end

def sync_blacklisted_event_names
@blacklisted_events = nil
end
end
36 changes: 0 additions & 36 deletions config/event_handling.tmpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1413,42 +1413,6 @@ event_handling:
- refresh:
- ems

#
# The filtered_events section defines which events should not be added to the
# database. Keys that have nil values will be filtered at the event catcher
# level. Keys that do have values, in the format of a hash of object type to
# an array of ids, will be filtered such that they are not added to the event
# table.
#
filtered_events:
AlarmActionTriggeredEvent: # Vmware filtered events
AlarmCreatedEvent:
AlarmEmailCompletedEvent:
AlarmEmailFailedEvent:
AlarmReconfiguredEvent:
AlarmRemovedEvent:
AlarmScriptCompleteEvent:
AlarmScriptFailedEvent:
AlarmSnmpCompletedEvent:
AlarmSnmpFailedEvent:
AlarmStatusChangedEvent:
AlreadyAuthenticatedSessionEvent:
EventEx:
UNASSIGNED: # RHEV filtered events
USER_REMOVE_VG:
USER_REMOVE_VG_FAILED:
USER_VDC_LOGIN:
USER_VDC_LOGOUT:
USER_VDC_LOGIN_FAILED:
UserLoginSessionEvent:
UserLogoutSessionEvent:
scheduler.run_instance.start: # OpenStack filtered events
scheduler.run_instance.scheduled:
scheduler.run_instance.end:
ConfigurationSnapshotDeliveryCompleted: # Amazon filtered events
ConfigurationSnapshotDeliveryStarted:
ConfigurationSnapshotDeliveryFailed:

#
# The task_final_events section defines which events could be the final event
# for a task, and the list of those tasks for which that event is a final event.
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20150804194147_create_blacklisted_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateBlacklistedEvents < ActiveRecord::Migration
def change
create_table :blacklisted_events do |t|
t.string :event_name
t.string :provider_model
t.bigint :ems_id
t.boolean :system
t.boolean :enabled
t.timestamps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has added a bunch of noise to the migration specs...

DEPRECATION WARNING: #timestamps was called without specifying an option for null. In Rails 5, this behavior will change to null: false. You should manually specify null: true to prevent the behavior of your existing migrations from changing. (called from block in change at db/migrate/20150804194147_create_blacklisted_events.rb:9)

end
end
end
Loading