104 |
104 |
105 includes = self.format_mounts( config, 'include' ) || self.class.include |
105 includes = self.format_mounts( config, 'include' ) || self.class.include |
106 excludes = self.format_mounts( config, 'exclude' ) || self.class.exclude |
106 excludes = self.format_mounts( config, 'exclude' ) || self.class.exclude |
107 |
107 |
108 mounts.reject! do |path, percentage| |
108 mounts.reject! do |path, percentage| |
|
109 path = path.to_s |
109 excludes.match( path ) || ( includes && ! includes.match( path ) ) |
110 excludes.match( path ) || ( includes && ! includes.match( path ) ) |
110 end |
111 end |
111 |
112 |
112 errors = [] |
113 errors = [] |
113 warnings = [] |
114 warnings = [] |
149 |
150 |
150 |
151 |
151 ### Fetch information for Windows systems. |
152 ### Fetch information for Windows systems. |
152 ### |
153 ### |
153 def windows_disks( snmp ) |
154 def windows_disks( snmp ) |
154 raw = snmp.get_bulk([ |
155 oids = [ |
155 STORAGE_WINDOWS[:path], |
156 STORAGE_WINDOWS[:path], |
156 STORAGE_WINDOWS[:type], |
157 STORAGE_WINDOWS[:type], |
157 STORAGE_WINDOWS[:total], |
158 STORAGE_WINDOWS[:total], |
158 STORAGE_WINDOWS[:used] |
159 STORAGE_WINDOWS[:used] |
159 ]).varbinds.map( &:value ) |
160 ] |
|
161 |
|
162 paths = snmp.walk( oid: oids[0] ).each_with_object( [] ) do |(_, value), acc| |
|
163 acc << value |
|
164 end |
|
165 types = snmp.walk( oid: oids[1] ).each_with_object( [] ) do |(_, value), acc| |
|
166 acc << WINDOWS_DEVICES.include?( value ) |
|
167 end |
|
168 totals = snmp.walk( oid: oids[2] ).each_with_object( [] ) do |(_, value), acc| |
|
169 acc << value |
|
170 end |
|
171 used = snmp.walk( oid: oids[3] ).each_with_object( [] ) do |(_, value), acc| |
|
172 acc << value |
|
173 end |
160 |
174 |
161 disks = {} |
175 disks = {} |
162 raw.each_slice( 4 ) do |device| |
176 paths.each_with_index do |path, idx| |
163 next unless device[1].respond_to?( :oid ) && WINDOWS_DEVICES.include?( device[1].oid ) |
177 next if totals[ idx ].zero? |
164 next if device[2].zero? |
178 next unless types[ idx ] |
165 disks[ device[0] ] = (( device[3].to_f / device[2] ) * 100).round( 1 ) |
179 disks[ path ] ||= {} |
|
180 disks[ path ] = (( used[idx].to_f / totals[idx] ) * 100).round( 1 ) |
166 end |
181 end |
167 |
182 |
168 return disks |
183 return disks |
169 end |
184 end |
170 |
185 |
171 |
186 |
172 ### Fetch information for Unix/MacOS systems. |
187 ### Fetch information for Unix/MacOS systems. |
173 ### |
188 ### |
174 def unix_disks( snmp ) |
189 def unix_disks( snmp ) |
175 raw = snmp.get_bulk([ |
190 oids = [ STORAGE_NET_SNMP[:path], STORAGE_NET_SNMP[:percent] ] |
176 STORAGE_NET_SNMP[:path], |
191 paths = snmp.walk( oid: oids.first ).each_with_object( [] ) do |(_, value), acc| |
177 STORAGE_NET_SNMP[:percent] ]).varbinds.map( &:value ) |
192 acc << value |
178 |
193 end |
179 return Hash[ *raw ] |
194 capacities = snmp.walk( oid: oids.last ).each_with_object( [] ) do |(_, value), acc| |
|
195 acc << value |
|
196 end |
|
197 |
|
198 pairs = paths.zip( capacities ) |
|
199 return Hash[ *pairs.flatten ] |
180 end |
200 end |
181 |
201 |
182 end # class Arborist::Monitor::SNMP::Disk |
202 end # class Arborist::Monitor::SNMP::Disk |
183 |
203 |