Class: OIDRef
- Inherits:
-
Object
- Object
- OIDRef
- Defined in:
- lib/monitor/client/snmp/oid_ref.rb
Constant Summary collapse
- TABLENAME =
'oid_ref'
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.add_oid_ref(n, descr, calc) ⇒ Object
add an oid_ref arg n for uniq name, descr the description and calc the calcul to do return true if deleted otherwise false.
-
.del_oid_ref(n) ⇒ Object
delete an oid_ref return true is entry delete otherwise false.
-
.get_oid_refs_name ⇒ Object
return a table of all oidrefs name.
-
.oid_ref_exist?(name) ⇒ Boolean
check if a given oid ref name is defined.
-
.oid_ref_nb_entry ⇒ Object
return number of oid ref.
- .read_db_oidref ⇒ Object
- .read_oidref_conf_file(fic = OIDREFS_CONF_FILE) ⇒ Object
- .write_db_oidref ⇒ Object
- .write_oidref_conf_file(fic_name = OIDREFS_CONF_FILE) ⇒ Object
Instance Method Summary collapse
- #add_use ⇒ Object
- #del_use ⇒ Object
-
#initialize(n, descr, calc) ⇒ OIDRef
constructor
A new instance of OIDRef.
- #to_str ⇒ Object
- #used? ⇒ Boolean
Constructor Details
#initialize(n, descr, calc) ⇒ OIDRef
Returns a new instance of OIDRef.
116 117 118 119 120 121 122 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 116 def initialize (n, descr, calc) #name is the identifier, it must be uniq @name=n @description=descr @value=calc @nb_use=0 end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 2 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 2 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
2 3 4 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 2 def value @value end |
Class Method Details
.add_oid_ref(n, descr, calc) ⇒ Object
add an oid_ref arg n for uniq name, descr the description and calc the calcul to do return true if deleted otherwise false
12 13 14 15 16 17 18 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 12 def OIDRef::add_oid_ref(n, descr, calc) if $oid_refs[n] == nil $oid_refs[n] = OIDRef.new(n, descr, calc) return true end return false end |
.del_oid_ref(n) ⇒ Object
delete an oid_ref return true is entry delete otherwise false
25 26 27 28 29 30 31 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 25 def OIDRef::del_oid_ref(n) if !$oid_refs[n].used?() $oid_refs.delete(n) return true end return false end |
.get_oid_refs_name ⇒ Object
return a table of all oidrefs name
91 92 93 94 95 96 97 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 91 def OIDRef::get_oid_refs_name() name_t=[] $oid_refs.each_key {|name| name_t.push name } return name_t end |
.oid_ref_exist?(name) ⇒ Boolean
check if a given oid ref name is defined
102 103 104 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 102 def OIDRef::oid_ref_exist?(name) return $oid_refs[name] != nil end |
.oid_ref_nb_entry ⇒ Object
return number of oid ref
109 110 111 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 109 def OIDRef::oid_ref_nb_entry() return $oid_refs.size end |
.read_db_oidref ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 60 def OIDRef::read_db_oidref() if defined?($db) && ($db !=nil) db_select_all_prp(TABLENAME).execute do |rs| rs.each do |name, description, value| add_oid_ref(name,description,value) end end end end |
.read_oidref_conf_file(fic = OIDREFS_CONF_FILE) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 70 def OIDRef::read_oidref_conf_file(fic=OIDREFS_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_oid_ref(lign_t[0],lign_t[1],lign_t[2].chomp()) end lign=fic.gets end fic.close else puts "oidrefs conf file not found" end end |
.write_db_oidref ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 33 def OIDRef::write_db_oidref() if defined?($db) && ($db !=nil) $db.transaction ps=db_delete_all_prp(TABLENAME) if ps ps.execute() stmt=db_insert_ref_prp(TABLENAME) $oid_refs.each_value do |oid_ref| stmt.execute(oid_ref.name, oid_ref.description, oid_ref.value) end $db.commit else $db.rollback end end end |
.write_oidref_conf_file(fic_name = OIDREFS_CONF_FILE) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 50 def OIDRef::write_oidref_conf_file(fic_name=OIDREFS_CONF_FILE) field_separator='~' fic=Tempfile.new(File.basename(fic_name)) $oid_refs.each_value do |oid_ref| fic.puts "#{oid_ref.name}#{field_separator}#{oid_ref.description}#{field_separator}#{oid_ref.value}" end fic.close() FileUtils.move(fic.path, fic_name) end |
Instance Method Details
#add_use ⇒ Object
124 125 126 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 124 def add_use() @nb_use+=1 end |
#del_use ⇒ Object
128 129 130 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 128 def del_use() @nb_use-=1 end |
#to_str ⇒ Object
136 137 138 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 136 def to_str() print "OIDRef: ", @name, " ", @description, " ", @value end |
#used? ⇒ Boolean
132 133 134 |
# File 'lib/monitor/client/snmp/oid_ref.rb', line 132 def used?() return @nb_use>0 end |