Class: SnmpAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/monitor/server/snmp/snmptrap_analyzer.rb

Instance Method Summary collapse

Constructor Details

#initialize(buff) ⇒ SnmpAnalyzer

Returns a new instance of SnmpAnalyzer.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/monitor/server/snmp/snmptrap_analyzer.rb', line 4

def initialize(buff)
  @buff=buff

@mib=SNMP::MIB.new()
libs=["SNMPv2-SMI", "SNMPv2-MIB", "IF-MIB", "IP-MIB", "TCP-MIB", "UDP-MIB"]
libs.each do |lb|
@mib.load_module(lb)
end
  @sender = Thread.start do
 	 while $config.snmptrap_mon
    	   send_messages if buff.full?
    	   sleep(1)
  Thread.pass
 	 end
  end
	$log.debug("end of SnmpAnalyzer thread")
end

Instance Method Details

#get_threadObject



22
23
24
# File 'lib/monitor/server/snmp/snmptrap_analyzer.rb', line 22

def get_thread
  @sender
end

#send_messagesObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/monitor/server/snmp/snmptrap_analyzer.rb', line 39

def send_messages
  while @buff.has_more?
    snmptrap_msg=@buff.get
if snmptrap_msg != nil
	src=snmptrap_msg.source_ip
	if $host[src] != nil && $host[src].snmptrap_monitoring.size() > 0
		find_oid_val=nil
		snmptrap_vers=0
	  if snmptrap_msg.class == SNMP::SNMPv2_Trap
		 snmptrap_vers=2
		 find_oid_val=snmptrap_msg.trap_oid().join('.')
	  elsif SNMP::SNMPv1_Trap
		 snmptrap_vers=1
		 find_oid_val=snmptrap_msg.enterprise.join('.')
		 if snmptrap_msg.generic_trap() == :enterpriseSpecific
	  		 find_oid_val="#{find_oid_val}.6.#{snmptrap_msg.specific_trap}"
		 else
			 find_oid_val="#{find_oid_val}."+snmptrap_msg.generic_trap()
		 end
	  else 
		  $log.error("unkwown Snmp Trap version")
	  end
	  if find_oid_val != nil
		 $host[src].snmptrap_monitoring.each_value do |snmptrap_mon|
			 if snmptrap_mon.active?() 
			    trap_ref_value=to_oid($snmptrap_refs[snmptrap_mon.get_snmptrap_ref()].get_oid())
				 find_oid_value=to_oid(find_oid_val)
				 if (trap_ref_value == find_oid_value) && (find_oid_value!=nil)
					$event_win.add_event(EventWindow::TRAP_EVENT_TYPE, get_level_from_status($status[snmptrap_mon.raw_severity()-1]), $host[src], "Snmp Trap(v#{snmptrap_vers}): #{$snmptrap_refs[snmptrap_mon.get_snmptrap_ref()].name}")
					if $status_value[snmptrap_mon.raw_severity()-1] > $host[src].trap_sev
						$host[src].set_trap_severity(snmptrap_mon.raw_severity()-1)
					end							
					break
				 end
			 end
		 end
	  end
	end
end
end
end

#to_oid(oid_name) ⇒ Object

convert oid_name to oid, return nil if error



29
30
31
32
33
34
35
36
37
# File 'lib/monitor/server/snmp/snmptrap_analyzer.rb', line 29

def to_oid(oid_name)
	oid=nil
	begin
		oid=@mib.oid(oid_name).to_s
	rescue
		$log.error("SNMP trap: dont understand #{oid_name}")
	end
	return oid
end