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

Fix the issue that alerts don't send SNMP traps. #11988

Merged
merged 2 commits into from
Oct 18, 2016
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
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