Skip to content

Commit

Permalink
Merge pull request #11988 from lfu/snmp_trap_1381287
Browse files Browse the repository at this point in the history
Fix the issue that alerts don't send SNMP traps.
(cherry picked from commit f62e14e)

https://bugzilla.redhat.com/show_bug.cgi?id=1381287
  • Loading branch information
chessbyte committed Oct 19, 2016
1 parent fd4c697 commit 5c08fab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
18 changes: 9 additions & 9 deletions app/models/miq_snmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def self.trap_v1(inputs)

# A list of additional varbinds to send with the trap.
object_list = inputs[:object_list] || inputs['object_list'] || []
vars = MiqSnmp.create_var_bind_list(object_list)
vars = create_var_bind_list(object_list)

hosts = host.kind_of?(Array) ? host : [host]
hosts.each do |host|
Expand All @@ -72,11 +72,11 @@ def self.trap_v2(inputs)
# trap_oid: An ObjectId or String with the OID identifier for this trap.
trap_oid = inputs[:trap_oid] || inputs['trap_oid']
raise MiqException::Error, _("MiqSnmp.trap_v2: Ensure that a trap object id is provided") if trap_oid.nil?
trap_oid = MiqSnmp.subst_oid(trap_oid)
trap_oid = subst_oid(trap_oid)

# A list of additional varbinds to send with the trap.
object_list = inputs[:object_list] || inputs['object_list'] || []
vars = MiqSnmp.create_var_bind_list(object_list, trap_oid)
vars = create_var_bind_list(object_list, trap_oid)

hosts = host.kind_of?(Array) ? host : [host]
hosts.each do |host|
Expand All @@ -103,7 +103,7 @@ def self.available_types
def self.create_var_bind_list(object_list, base = nil)
vars = []
object_list.each do |tuple|
oid = MiqSnmp.subst_oid(tuple[:oid], base)
oid = subst_oid(tuple[:oid], base)
value = tuple[:value]
type = tuple[:type] || tuple[:var_type]
snmpType = AVAILABLE_TYPES_HASH[type]
Expand All @@ -118,16 +118,16 @@ def self.subst_oid(oid, base = nil)
oid = oid.strip

# Set base to our enterprise oid, if uninitialize
base = MiqSnmp.enterprise_oid_string if base.nil?
base = enterprise_oid_string if base.nil?

# If it begins with a dot, append it to the base
return "#{base}#{oid}" if oid[0, 1] == "."

# Need to move these to ManageIQ MIB
oid = case oid.downcase
when "info" then "#{MiqSnmp.enterprise_oid_string}.1"
when "warn", "warning" then "#{MiqSnmp.enterprise_oid_string}.2"
when "crit", "critical", "error" then "#{MiqSnmp.enterprise_oid_string}.3"
when "info" then "#{enterprise_oid_string}.1"
when "warn", "warning" then "#{enterprise_oid_string}.2"
when "crit", "critical", "error" then "#{enterprise_oid_string}.3"
when "description" then "#{base}.1"
when "category" then "#{base}.2"
when "message" then "#{base}.3"
Expand All @@ -151,7 +151,7 @@ def self.system_uptime
private_class_method :system_uptime

def self.agent_address
VMDB::Config.new("vmdb").get(:server, :host)
Settings.server.host
end
private_class_method :agent_address
end
12 changes: 12 additions & 0 deletions spec/models/miq_snmp_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe MiqSnmp do
describe '.trap_v2' do
it 'calls subst_oid' do
expect(MiqSnmp).to receive(:subst_oid).at_least(1).and_return("1.2.3")

MiqSnmp.trap_v2(:host => ["localhost"],
:sysuptime => 1,
:trap_oid => "info",
:object_list => [{:oid => "1.2.3", :var_type => "Integer", :value => "1"}])
end
end
end

0 comments on commit 5c08fab

Please sign in to comment.