Class: SnmpTrapRef
- Inherits:
-
Object
- Object
- SnmpTrapRef
- Defined in:
- lib/monitor/server/snmp/snmptrap_ref.rb
Constant Summary collapse
- TABLENAME =
'snmptrap_ref'
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
-
.add_snmptrap_ref(n, descr, calc) ⇒ Object
return true if deleted otherwise false.
-
.del_snmptrap_ref(n) ⇒ Object
delete an snmptrap_ref return true is entry delete otherwise false.
-
.get_snmptrap_refs_name ⇒ Object
return a table of all SnmpTrapRef name.
- .read_db_snmptrapref ⇒ Object
- .read_snmptrapref_conf_file(fic = SNMPTRAPREFS_CONF_FILE) ⇒ Object
- .snmptrap_ref_exist?(name) ⇒ Boolean
- .write_db_snmptrapref ⇒ Object
- .write_snmptrapref_conf_file(fic_name = SNMPTRAPREFS_CONF_FILE) ⇒ Object
Instance Method Summary collapse
- #add_use ⇒ Object
- #del_use ⇒ Object
- #get_oid ⇒ Object
-
#initialize(n, descr, oid) ⇒ SnmpTrapRef
constructor
end global management###############.
- #set_value(oid) ⇒ Object
- #to_str ⇒ Object
- #used? ⇒ Boolean
- #value ⇒ Object
Constructor Details
#initialize(n, descr, oid) ⇒ SnmpTrapRef
end global management###############
99 100 101 102 103 104 105 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 99 def initialize (n, descr, oid) #name is the identifier, it must be uniq @name=n @description=descr @value=oid @nb_use=0 end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 2 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 2 def name @name end |
Class Method Details
.add_snmptrap_ref(n, descr, calc) ⇒ Object
return true if deleted otherwise false
11 12 13 14 15 16 17 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 11 def SnmpTrapRef::add_snmptrap_ref(n, descr, calc) if $snmptrap_refs[n] == nil $snmptrap_refs[n] = SnmpTrapRef.new(n, descr, calc) return true end return false end |
.del_snmptrap_ref(n) ⇒ Object
delete an snmptrap_ref return true is entry delete otherwise false
23 24 25 26 27 28 29 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 23 def SnmpTrapRef::del_snmptrap_ref(n) if !$snmptrap_refs[n].used?() $snmptrap_refs.delete(n) return true end return false end |
.get_snmptrap_refs_name ⇒ Object
return a table of all SnmpTrapRef name
86 87 88 89 90 91 92 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 86 def SnmpTrapRef::get_snmptrap_refs_name() name_t=[] $snmptrap_refs.each_key {|name| name_t.push name } return name_t end |
.read_db_snmptrapref ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 55 def SnmpTrapRef::read_db_snmptrapref() if defined?($db) && ($db !=nil) db_select_all_prp(TABLENAME).execute do |rs| rs.each do |name, description, value| add_snmptrap_ref(name,description,value) end end end end |
.read_snmptrapref_conf_file(fic = SNMPTRAPREFS_CONF_FILE) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 65 def SnmpTrapRef::read_snmptrapref_conf_file(fic=SNMPTRAPREFS_CONF_FILE) field_separator='~' if FileTest.exist?(fic) fic = File.new(fic,'r') lign=fic.gets while lign lign_t = lign.split(field_separator) if lign_t.size() == 3 add_snmptrap_ref(lign_t[0],lign_t[1],lign_t[2].chomp()) end lign=fic.gets end fic.close else puts "SnmpTrapRefs conf file not found" end end |
.snmptrap_ref_exist?(name) ⇒ Boolean
94 95 96 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 94 def SnmpTrapRef::snmptrap_ref_exist?(name) return $snmptrap_refs[name] != nil end |
.write_db_snmptrapref ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 31 def SnmpTrapRef::write_db_snmptrapref() if defined?($db) && ($db !=nil) $db.transaction db_delete_all_prp(TABLENAME).execute() stmt=db_insert_ref_prp(TABLENAME) $snmptrap_refs.each_value do |snmptrap_ref| stmt.execute(snmptrap_ref.name, snmptrap_ref.description, snmptrap_ref.value) end $db.commit end end |
.write_snmptrapref_conf_file(fic_name = SNMPTRAPREFS_CONF_FILE) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 43 def SnmpTrapRef::write_snmptrapref_conf_file(fic_name=SNMPTRAPREFS_CONF_FILE) field_separator='~' fic=Tempfile.new(File.basename(fic_name)) $snmptrap_refs.each_value do |snmptrap_ref| fic.puts "#{snmptrap_ref.name}#{field_separator}#{snmptrap_ref.description}#{field_separator}#{snmptrap_ref.value}" end fic.close() if !FileUtils.move(fic.path, fic_name) $log.error("Can not save snmp trap ref conf file") end end |
Instance Method Details
#add_use ⇒ Object
107 108 109 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 107 def add_use() @nb_use+=1 end |
#del_use ⇒ Object
111 112 113 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 111 def del_use() @nb_use-=1 end |
#get_oid ⇒ Object
123 124 125 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 123 def get_oid() return @value end |
#set_value(oid) ⇒ Object
131 132 133 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 131 def set_value(oid) @value=oid end |
#to_str ⇒ Object
119 120 121 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 119 def to_str() print "SnmpTrapRef: ", @name, " ", @description, " ", @value end |
#used? ⇒ Boolean
115 116 117 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 115 def used?() return @nb_use>0 end |
#value ⇒ Object
127 128 129 |
# File 'lib/monitor/server/snmp/snmptrap_ref.rb', line 127 def value() return @value end |