gnms 2.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gnms might be problematic. Click here for more details.

Files changed (140) hide show
  1. data/LICENSE +459 -0
  2. data/README +29 -0
  3. data/bin/gnms +11 -0
  4. data/gnms.gemspec +70 -0
  5. data/lib/cmd_parse.rb +747 -0
  6. data/lib/config_global.rb +414 -0
  7. data/lib/contact.rb +171 -0
  8. data/lib/external/crypt/blowfish-tables.rb +190 -0
  9. data/lib/external/crypt/blowfish.rb +110 -0
  10. data/lib/external/crypt/cbc.rb +123 -0
  11. data/lib/external/crypt/stringxor.rb +27 -0
  12. data/lib/external/fog.rb +41 -0
  13. data/lib/external/jjmx.rb +45 -0
  14. data/lib/external/sms.rb +282 -0
  15. data/lib/external/xmpp4r-simple.rb +497 -0
  16. data/lib/format.rb +85 -0
  17. data/lib/gnms.rb +329 -0
  18. data/lib/gui/about_window.rb +177 -0
  19. data/lib/gui/adddelnode.rb +799 -0
  20. data/lib/gui/base_window.rb +789 -0
  21. data/lib/gui/canvas_map.rb +498 -0
  22. data/lib/gui/charts/gruff.rb +51 -0
  23. data/lib/gui/color_macro.rb +145 -0
  24. data/lib/gui/config_window.rb +2151 -0
  25. data/lib/gui/custom_plugin_window.rb +90 -0
  26. data/lib/gui/debug_window.rb +46 -0
  27. data/lib/gui/event_window.rb +469 -0
  28. data/lib/gui/find_node_window.rb +438 -0
  29. data/lib/gui/help_window.rb +47 -0
  30. data/lib/gui/ipcalculator.rb +147 -0
  31. data/lib/gui/jmx_ref_window.rb +309 -0
  32. data/lib/gui/link_view.rb +46 -0
  33. data/lib/gui/mib_browser.rb +585 -0
  34. data/lib/gui/node_host_property.rb +3712 -0
  35. data/lib/gui/node_host_view.rb +270 -0
  36. data/lib/gui/node_network_property.rb +1059 -0
  37. data/lib/gui/node_network_view.rb +186 -0
  38. data/lib/gui/node_view.rb +672 -0
  39. data/lib/gui/oid_ref_window.rb +288 -0
  40. data/lib/gui/snmptrap_ref_window.rb +288 -0
  41. data/lib/gui/sub/account_frame.rb +196 -0
  42. data/lib/gui/sub/contact_frame.rb +519 -0
  43. data/lib/gui/syslog_ref_window.rb +288 -0
  44. data/lib/gui/treenode_window.rb +320 -0
  45. data/lib/gui/update_window.rb +124 -0
  46. data/lib/gui/widgets.rb +169 -0
  47. data/lib/gui/wmi_ref_window.rb +286 -0
  48. data/lib/interface.rb +16 -0
  49. data/lib/ipcalc.rb +266 -0
  50. data/lib/link.rb +45 -0
  51. data/lib/main.rb +1091 -0
  52. data/lib/monitor/client/custom/custom_monitoring.rb +40 -0
  53. data/lib/monitor/client/jmx/jmx_attr_monitoring.rb +36 -0
  54. data/lib/monitor/client/jmx/jmx_monitoring.rb +83 -0
  55. data/lib/monitor/client/jmx/jmx_ref.rb +114 -0
  56. data/lib/monitor/client/snmp/mibs/SNMPv2-MIB.txt +854 -0
  57. data/lib/monitor/client/snmp/mibs/SNMPv2-SMI.txt +344 -0
  58. data/lib/monitor/client/snmp/oid_ref.rb +141 -0
  59. data/lib/monitor/client/snmp/snmp.rb +178 -0
  60. data/lib/monitor/client/snmp/snmp_monitoring.rb +58 -0
  61. data/lib/monitor/client/wmi/wmi.rb +139 -0
  62. data/lib/monitor/client/wmi/wmi_monitoring.rb +60 -0
  63. data/lib/monitor/client/wmi/wmi_ref.rb +141 -0
  64. data/lib/monitor/custom_plugin.rb +50 -0
  65. data/lib/monitor/server/msg_buffer.rb +39 -0
  66. data/lib/monitor/server/snmp/snmptrap_analyzer.rb +81 -0
  67. data/lib/monitor/server/snmp/snmptrap_capture.rb +26 -0
  68. data/lib/monitor/server/snmp/snmptrap_monitoring.rb +32 -0
  69. data/lib/monitor/server/snmp/snmptrap_ref.rb +135 -0
  70. data/lib/monitor/server/snmp/snmptrap_server.rb +50 -0
  71. data/lib/monitor/server/syslog/syslog_analyzer.rb +141 -0
  72. data/lib/monitor/server/syslog/syslog_capture.rb +28 -0
  73. data/lib/monitor/server/syslog/syslog_monitoring.rb +32 -0
  74. data/lib/monitor/server/syslog/syslog_ref.rb +136 -0
  75. data/lib/monitor/server/syslog/syslog_server.rb +43 -0
  76. data/lib/node.rb +1020 -0
  77. data/lib/node_db.rb +2668 -0
  78. data/lib/node_host.rb +215 -0
  79. data/lib/node_listener.rb +639 -0
  80. data/lib/node_network.rb +269 -0
  81. data/lib/node_property.rb +39 -0
  82. data/lib/notify/alarm.rb +247 -0
  83. data/lib/notify/irc_bot.rb +167 -0
  84. data/lib/notify/xmpp_bot.rb +107 -0
  85. data/lib/service.rb +36 -0
  86. data/lib/version.rb +8 -0
  87. data/pixmap/bg/map_bg.jpg +0 -0
  88. data/pixmap/bg/map_bg2.jpg +0 -0
  89. data/pixmap/logo.jpg +0 -0
  90. data/pixmap/logo_icon.png +0 -0
  91. data/pixmap/os/3com.png +0 -0
  92. data/pixmap/os/aix.gif +0 -0
  93. data/pixmap/os/amiga.png +0 -0
  94. data/pixmap/os/beos.png +0 -0
  95. data/pixmap/os/cisco.png +0 -0
  96. data/pixmap/os/freebsd.png +0 -0
  97. data/pixmap/os/hp.png +0 -0
  98. data/pixmap/os/hurd.gif +0 -0
  99. data/pixmap/os/irix.gif +0 -0
  100. data/pixmap/os/linux.png +0 -0
  101. data/pixmap/os/mac.png +0 -0
  102. data/pixmap/os/netbsd.gif +0 -0
  103. data/pixmap/os/netware.png +0 -0
  104. data/pixmap/os/openbsd.png +0 -0
  105. data/pixmap/os/os2warp.gif +0 -0
  106. data/pixmap/os/qnx.gif +0 -0
  107. data/pixmap/os/sco.gif +0 -0
  108. data/pixmap/os/sgi.xpm +111 -0
  109. data/pixmap/os/solaris.gif +0 -0
  110. data/pixmap/os/unix.gif +0 -0
  111. data/pixmap/os/unknown.png +0 -0
  112. data/pixmap/os/vms.xpm +345 -0
  113. data/pixmap/os/windows.png +0 -0
  114. data/pixmap/type/cloud.png +0 -0
  115. data/pixmap/type/device.png +0 -0
  116. data/pixmap/type/firewall.png +0 -0
  117. data/pixmap/type/gateway.png +0 -0
  118. data/pixmap/type/home.png +0 -0
  119. data/pixmap/type/host.png +0 -0
  120. data/pixmap/type/network.png +0 -0
  121. data/pixmap/type/printer.png +0 -0
  122. data/pixmap/type/router.png +0 -0
  123. data/pixmap/type/server.png +0 -0
  124. data/pixmap/type/switch.png +0 -0
  125. data/pixmap/type/vm.png +0 -0
  126. data/plugins/Defaultme.rb +7 -0
  127. data/plugins/DnsCheck.rb +46 -0
  128. data/plugins/FooMonitor.rb +26 -0
  129. data/plugins/HttpVirtualHostMonitor.rb +43 -0
  130. data/plugins/MysqlShowStatusMonitor.rb +64 -0
  131. data/plugins/PgsqlPercentConnectionMonitor.rb +72 -0
  132. data/plugins/SshCpuLoadMonitor.rb +85 -0
  133. data/plugins/SshDiskMonitor.rb +69 -0
  134. data/plugins/SshFgtAvExpiredMonitor.rb +75 -0
  135. data/plugins/SshPercentUsedRamMonitor.rb +74 -0
  136. data/plugins/TelnetCpuLoadMonitor.rb +69 -0
  137. data/plugins/example1.rb +15 -0
  138. data/plugins/example2.rb +7 -0
  139. data/sound/beep.wav +0 -0
  140. metadata +378 -0
@@ -0,0 +1,178 @@
1
+ #
2
+ # module to use snmp linux command
3
+ #
4
+ require 'timeout'
5
+ require "#{GNMSLIB}"+'/config_global'
6
+
7
+ #
8
+ # return the value of the entry
9
+ #
10
+ def get_snmp_OID(node, oid)
11
+
12
+ #get values from node network
13
+ version=node.get_default_inherit_snmp_version()
14
+ port=node.get_default_inherit_snmp_port()
15
+ timeout=node.get_default_inherit_snmp_timeout()
16
+ retr=node.get_default_inherit_snmp_retry()
17
+
18
+ community_read = $config.read_community
19
+ community_write = $config.write_community
20
+ if node.get_account_id("snmp")
21
+ community_read, community_write = node.get_account_id("snmp")
22
+ end
23
+
24
+ begin
25
+ print "get_snmp_OID: ", node.ip, " ", community_read, " ", community_write, " ", get_snmp_version(version), " ", port.to_i, " ", timeout.to_i, " ", retr.to_i,"\n"
26
+ SNMP::Manager.open(:Host => node.ip, :Community => community_read, :WriteCommunity => community_write, :Version => get_snmp_version(version), :Port => port.to_i, :Timeout => timeout.to_i, :Retries => retr.to_i) do |manager|
27
+ response = manager.get(oid)
28
+ response.each_varbind do |vb|
29
+ return vb.value.to_s
30
+ end
31
+ end
32
+ rescue Exception => msg
33
+ $log.error("Error in get_snmp_OID: #{msg}")
34
+ return "Error"
35
+ end
36
+ end
37
+
38
+ #
39
+ # return an array of the value of the entry
40
+ #
41
+ def walk_snmp_OID(node, oid)
42
+
43
+ #get values from node network
44
+ version=node.get_default_inherit_snmp_version()
45
+ port=node.get_default_inherit_snmp_port()
46
+ timeout=node.get_default_inherit_snmp_timeout()
47
+ retr=node.get_default_inherit_snmp_retry()
48
+
49
+ community_read = $config.read_community
50
+ community_write = $config.write_community
51
+ if node.get_account_id("snmp")
52
+ community_read, community_write = node.get_account_id("snmp")
53
+ end
54
+
55
+ begin
56
+ snmp_manager=SNMP::Manager.open(:Host => node.ip, :Community => community_read, :WriteCommunity => community_write, :Version => get_snmp_version(version), :Port => port.to_i, :Timeout => timeout.to_i, :Retries => retr.to_i) do |manager|
57
+ resultt=[]
58
+ manager.walk(oid) {|vb|
59
+ resultt.push(vb.to_s)
60
+ }
61
+ return resultt
62
+ end
63
+ rescue Exception => msg
64
+ $log.error("Error in get_snmp_OID: #{msg}")
65
+ return "Error"
66
+ end
67
+ end
68
+
69
+ #
70
+ # set the value of the entry
71
+ #
72
+ def set_snmp(node, oid, value)
73
+
74
+ #get values from node network
75
+ version=node.get_default_inherit_snmp_version()
76
+ port=node.get_default_inherit_snmp_port()
77
+ timeout=node.get_default_inherit_snmp_timeout()
78
+ retr=node.get_default_inherit_snmp_retry()
79
+
80
+ community_read = $config.read_community
81
+ community_write = $config.write_community
82
+ if node.get_account_id("snmp")
83
+ community_read, community_write = node.get_account_id("snmp")
84
+ end
85
+
86
+ begin
87
+ if oid ==nil || value == nil
88
+ $log.error("Error in set_snmp_OID: oid/value is null")
89
+ return "Error"
90
+ end
91
+ SNMP::Manager.open(:Host => node.ip, :Community => community_read, :WriteCommunity => community_write, :Version => get_snmp_version(version), :Port => port.to_i, :Timeout => timeout.to_i, :Retries => retr.to_i) do |manager|
92
+ varbind=SNMP::VarBind.new(oid,SNMP::OctetString.new(value))
93
+ response = manager.set(varbind)
94
+ if response.error_status().to_s != "noError"
95
+ return response.error_status().to_s
96
+ end
97
+ end
98
+ return 0
99
+ rescue Exception => msg
100
+ $log.error("Error in set_snmp_OID: #{msg}")
101
+ return "Error"
102
+ end
103
+ end
104
+
105
+ #
106
+ # Return uptime of an host
107
+ #
108
+ def get_snmp_uptime(node)
109
+ if node.status == CRITICAL
110
+ return "Error"
111
+ end
112
+ return get_snmp_OID(node, "sysUpTime.0")
113
+ end
114
+
115
+ #
116
+ # Return location of an host
117
+ #
118
+ def get_snmp_location (node)
119
+ if node.status == CRITICAL
120
+ return "Error"
121
+ end
122
+ return get_snmp_OID(node, "sysLocation.0")
123
+ end
124
+
125
+ #
126
+ # Return contact of an host
127
+ #
128
+ def get_snmp_contact(node)
129
+ if node.status == CRITICAL
130
+ return "Error"
131
+ end
132
+ return get_snmp_OID(node, "sysContact.0")
133
+ end
134
+
135
+ #
136
+ # Return the description of an host
137
+ #
138
+ def get_snmp_description(node)
139
+ if node.status == CRITICAL
140
+ return "Error"
141
+ end
142
+ return get_snmp_OID(node, "sysDescr.0")
143
+ end
144
+
145
+ #
146
+ # Return the name of a node
147
+ #
148
+ def get_snmp_name(host)
149
+ if node.status == CRITICAL
150
+ return "Error"
151
+ end
152
+ return get_snmp_OID(node, "sysName.0")
153
+ end
154
+
155
+ #
156
+ # Return the MAC address of the ip give in argument,
157
+ # use snmp
158
+ #
159
+ def mac(ip)
160
+ #first try to solve it by the help of local arp table
161
+ temp=mac_tablelocal(ip)
162
+ #print ">>>>>>>",temp.chomp,"<<<<<<<",ip,"\n"
163
+ if (temp!="")
164
+ return temp.chomp
165
+ end
166
+ if !$config.snmp_mon || $host[ip].status == CRITICAL
167
+ return ""
168
+ end
169
+ #puts "in map() 1 for #{ip}"
170
+ val=get_snmp_OID($host[ip], "ipAdEntIfIndex.#{ip}")
171
+
172
+ if !val || val == "Error"
173
+ return
174
+ end
175
+ result=get_snmp_OID($host[ip], "ifPhysAddress.#{val}")
176
+ #puts "map() result: #{result}"
177
+ return result
178
+ end
@@ -0,0 +1,58 @@
1
+ require "#{GNMSLIB}"+'/monitor/client/snmp/snmp'
2
+
3
+ class SnmpMonitoring
4
+ attr_accessor :oidref, :threshold
5
+
6
+ TESTOP=["=", "!=", "<", ">"]
7
+
8
+ def initialize (st, oidref_name, op, th, sev)
9
+ @state=st
10
+ @oidref=oidref_name
11
+ @oper=op
12
+ @threshold=th
13
+ #index of $status
14
+ @severity=sev
15
+ end
16
+
17
+ def oper()
18
+ return TESTOP[@oper]
19
+ end
20
+
21
+ def get_state()
22
+ return @state
23
+ end
24
+
25
+ def active?()
26
+ return @state==1
27
+ end
28
+ #
29
+ # compute the value
30
+ #
31
+ def value(manager, node)
32
+ if node != nil
33
+ strcalc=$oid_refs[@oidref].value.dup
34
+ strcalctp=strcalc.split(/\+/)
35
+ for oidref in strcalctp
36
+ begin
37
+ response=manager.get(oidref)
38
+ rescue Exception => msg
39
+ $log.error("Exception could not request get SNMP for #{oidref}: #{msg}")
40
+ raise
41
+ return
42
+ end
43
+ response.each_varbind do |vb|
44
+ strcalc.gsub!(oidref,vb.value.to_s)
45
+ end
46
+ end
47
+ return strcalc
48
+ end
49
+ end
50
+
51
+ def raw_severity()
52
+ return @severity
53
+ end
54
+
55
+ def severity()
56
+ return $status[@severity]
57
+ end
58
+ end #class
@@ -0,0 +1,139 @@
1
+
2
+ #
3
+ # return the value corresponding to the good attribute.
4
+ # a bug in wmic does not return only requested attributes
5
+ #
6
+ def find_separated_value_from_two_lines(l1, l2, attribute)
7
+ if (l1 == nil) || (l2 == nil)
8
+ return nil
9
+ end
10
+ attrt=l1.split('|')
11
+ valuet=l2.split('|')
12
+ if attrt.index(attribute) == nil
13
+ return nil
14
+ end
15
+ return valuet[attrt.index(attribute)]
16
+ end
17
+
18
+
19
+ #
20
+ # return the ComputerSystem description using a wmi request
21
+ #
22
+ def get_wmi_description(login, password, host)
23
+ resultt=wmi_request(login, password, host, "select Description from Win32_ComputerSystem")
24
+
25
+ #format is as below
26
+ #CLASS: Win32_ComputerSystem
27
+ #Description|Name
28
+ #AT/AT COMPATIBLE|KOMA-PC
29
+ return find_separated_value_from_two_lines(resultt[1], resultt[2], "Description")
30
+ end
31
+
32
+
33
+ #
34
+ # return the bootup state using a wmi request
35
+ #
36
+ def get_wmi_boot_state(login, password, host)
37
+ resultt=wmi_request(login, password, host, "select BootupState from Win32_ComputerSystem")
38
+ return find_separated_value_from_two_lines(resultt[1], resultt[2], "BootupState")
39
+ end
40
+
41
+ #
42
+ # return the thermal state severity using a wmi request
43
+ #
44
+ def get_wmi_thermal_state(login, password, host)
45
+ resultt=wmi_request(login, password, host, "select ThermalState from Win32_ComputerSystem")
46
+ value=find_separated_value_from_two_lines(resultt[1], resultt[2], "ThermalState")
47
+ if value.to_i == 1
48
+ return "Other"
49
+ elsif value.to_i == 3
50
+ return "Safe"
51
+ elsif value.to_i == 4
52
+ return "Warning"
53
+ elsif value.to_i == 5
54
+ return "Critical"
55
+ elsif value.to_i == 6
56
+ return "Nonrecoverable"
57
+ elsif value.to_i == 2
58
+ return "Unkown"
59
+ end
60
+ return nil
61
+
62
+ #from http://msdn.microsoft.com/en-us/library/aa394102.aspx
63
+ #1 (0x1) Other
64
+ #2 (0x2) Unknown
65
+ #3 (0x3) Safe
66
+ #4 (0x4) Warning
67
+ #5 (0x5) Critical
68
+ #6 (0x6)Nonrecoverable
69
+
70
+ end
71
+
72
+ #
73
+ # return the number of processor on the host using a wmi request
74
+ #
75
+ def get_wmi_nb_proc(login, password, host)
76
+ resultt=wmi_request(login, password, host, "select NumberOfProcessors from Win32_ComputerSystem")
77
+ return find_separated_value_from_two_lines(resultt[1], resultt[2], "NumberOfProcessors")
78
+ end
79
+
80
+ #
81
+ # return system type using a wmi request
82
+ #
83
+ def get_wmi_system_type(login, password, host)
84
+ resultt=wmi_request(login, password, host, "select SystemType from Win32_ComputerSystem")
85
+ return find_separated_value_from_two_lines(resultt[1], resultt[2], "SystemType")
86
+ end
87
+
88
+ #
89
+ # return the concatenation of OS and SP level using a wmi request
90
+ #
91
+ def get_wmi_os(login, password, host)
92
+ resultt=wmi_request(login, password, host, "select Name,CSDVersion from Win32_OperatingSystem")
93
+ val1=find_separated_value_from_two_lines(resultt[1], resultt[2], "Name")
94
+ val2=find_separated_value_from_two_lines(resultt[1], resultt[2], "CSDVersion")
95
+ if !val1
96
+ return nil
97
+ end
98
+ if !val2 || (val2 == "")
99
+ val2=0
100
+ end
101
+ return "#{val1} SP#{val2}"
102
+ end
103
+
104
+ #
105
+ # return product type using a wmi request
106
+ #
107
+ def get_wmi_product_type(login, password, host)
108
+ #1 Work Station
109
+ #2 Domain Controller
110
+ #3 Server
111
+ #seems it does not exist in windows 2000 server
112
+ resultt=wmi_request(login, password, host, "select ProductType from Win32_OperatingSystem")
113
+ value=find_separated_value_from_two_lines(resultt[1], resultt[2], "ProductType")
114
+ if value.to_i == 1
115
+ return "Workstation"
116
+ elsif value.to_i == 2
117
+ return "Domain Controller"
118
+ elseif value.to_i == 3
119
+ return "Server"
120
+ end
121
+ return nil
122
+ end
123
+
124
+ #
125
+ # return host name using a wmi request
126
+ #
127
+ def get_wmi_name(login, password, host)
128
+ resultt=wmi_request(login, password, host, "select Name from Win32_ComputerSystem")
129
+ return find_separated_value_from_two_lines(resultt[1], resultt[2], "Name")
130
+ end
131
+
132
+ #
133
+ # return domain name using a wmi request
134
+ #
135
+ def get_wmi_domain(login, password, host)
136
+ resultt=wmi_request(login, password, host, "select Domain from Win32_ComputerSystem")
137
+ return find_separated_value_from_two_lines(resultt[1], resultt[2], "Domain")
138
+ end
139
+
@@ -0,0 +1,60 @@
1
+ require "#{GNMSLIB}"+'/monitor/client/wmi/wmi'
2
+
3
+ class WmiMonitoring
4
+ attr_accessor :wmiref, :value
5
+
6
+ TESTOP=["=", "!=", "<", ">","Contain","Not contain"]
7
+
8
+ def initialize (st, wmiref_name, op, th, sev)
9
+ @state=st
10
+ @wmiref=wmiref_name
11
+ @oper=op
12
+ @value=th
13
+ #index of $status
14
+ @severity=sev
15
+ end
16
+
17
+ def oper()
18
+ return TESTOP[@oper]
19
+ end
20
+
21
+ def get_state()
22
+ return @state
23
+ end
24
+
25
+ def active?()
26
+ return @state==1
27
+ end
28
+
29
+ #
30
+ # compute the value
31
+ #
32
+ def request(node)
33
+ if node != nil
34
+ wmiref=$wmi_refs[@wmiref].value.dup
35
+ if node.get_account_id("wmi")
36
+ begin
37
+ login, password = node.get_account_id("wmi")
38
+ resultt=wmi_request(login, password, node.ip, wmiref)
39
+ if resultt.size() > 0
40
+ return resultt
41
+ end
42
+ rescue Exception => msg
43
+ $log.error("Exception WMI request for #{wmiref}: #{msg}")
44
+ raise
45
+ end
46
+ else
47
+ $log.error("wmi login/password not set for host #{node.ip}")
48
+ end
49
+ end
50
+ return nil
51
+ end
52
+
53
+ def raw_severity()
54
+ return @severity
55
+ end
56
+
57
+ def severity()
58
+ return $status[@severity]
59
+ end
60
+ end #class
@@ -0,0 +1,141 @@
1
+ class WMIRef
2
+ attr_accessor :name, :description, :value
3
+
4
+ TABLENAME='wmi_ref'
5
+ ########global management#########
6
+
7
+ #
8
+ # add an wmi_ref
9
+ # arg n for uniq name, descr the description and calc the calcul to do
10
+ # return true if deleted otherwise false
11
+ #
12
+ def WMIRef::add_wmi_ref(n, descr, calc)
13
+ if $wmi_refs[n] == nil
14
+ $wmi_refs[n] = WMIRef.new(n, descr, calc)
15
+ return true
16
+ end
17
+ return false
18
+ end
19
+
20
+
21
+ #
22
+ # delete an wmi_ref
23
+ # return true is entry delete otherwise false
24
+ #
25
+ def WMIRef::del_wmi_ref(n)
26
+ if !$wmi_refs[n].used?()
27
+ $wmi_refs.delete(n)
28
+ return true
29
+ end
30
+ return false
31
+ end
32
+
33
+ def WMIRef::write_db_wmiref()
34
+ if defined?($db) && ($db !=nil)
35
+ $db.transaction
36
+ ps=db_delete_all_prp(TABLENAME)
37
+ if ps
38
+ ps.execute()
39
+ stmt=db_insert_ref_prp(TABLENAME)
40
+ $wmi_refs.each_value do |wmi_ref|
41
+ stmt.execute(wmi_ref.name, wmi_ref.description, wmi_ref.value)
42
+ end
43
+ $db.commit
44
+ else
45
+ $db.rollback
46
+ end
47
+ end
48
+ end
49
+
50
+ def WMIRef::write_wmiref_conf_file(fic_name=WMIREFS_CONF_FILE)
51
+ field_separator='~'
52
+ fic=Tempfile.new(File.basename(fic_name))
53
+ $wmi_refs.each_value do |wmi_ref|
54
+ fic.puts "#{wmi_ref.name}#{field_separator}#{wmi_ref.description}#{field_separator}#{wmi_ref.value}"
55
+ end
56
+ fic.close()
57
+ FileUtils.move(fic.path, fic_name)
58
+ end
59
+
60
+ def WMIRef::read_db_wmiref()
61
+ if defined?($db) && ($db !=nil)
62
+ db_select_all_prp(TABLENAME).execute do |rs|
63
+ rs.each do |name, description, value|
64
+ add_wmi_ref(name,description,value)
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ def WMIRef::read_wmiref_conf_file(fic=WMIREFS_CONF_FILE)
71
+ field_separator='~'
72
+ if FileTest.exist?(fic)
73
+ fic = File.new(fic,'r')
74
+ lign=fic.gets
75
+ while lign
76
+ lign_t = lign.split(field_separator)
77
+ if lign_t.size() == 3
78
+ add_wmi_ref(lign_t[0],lign_t[1],lign_t[2].chomp())
79
+ end
80
+ lign=fic.gets
81
+ end
82
+ fic.close
83
+ else
84
+ puts "wmirefs conf file not found"
85
+ end
86
+ end
87
+
88
+ #
89
+ # return a table of all wmirefs name
90
+ #
91
+ def WMIRef::get_wmi_refs_name()
92
+ name_t=[]
93
+ $wmi_refs.each_key {|name|
94
+ name_t.push name
95
+ }
96
+ return name_t
97
+ end
98
+
99
+ #
100
+ # check if a given wmi ref name is defined
101
+ #
102
+ def WMIRef::wmi_ref_exist?(name)
103
+ return $wmi_refs[name] != nil
104
+ end
105
+
106
+ #
107
+ # return number of wmi ref
108
+ #
109
+ def WMIRef::wmi_ref_nb_entry()
110
+ return $wmi_refs.size
111
+ end
112
+
113
+ ########end global management#########
114
+
115
+
116
+ def initialize (n, descr, calc)
117
+ #name is the identifier, it must be uniq
118
+ @name=n
119
+ @description=descr
120
+ @value=calc
121
+ @nb_use=0
122
+ end
123
+
124
+ def add_use()
125
+ @nb_use+=1
126
+ end
127
+
128
+ def del_use()
129
+ @nb_use-=1
130
+ end
131
+
132
+ def used?()
133
+ return @nb_use>0
134
+ end
135
+
136
+ def to_str()
137
+ print "WMIRef: ", @name, " ", @description, " ", @value
138
+ end
139
+
140
+
141
+ end #class