author | Mahlon E. Smith <mahlon@laika.com> |
Wed, 04 Apr 2018 13:25:00 -0700 | |
changeset 12 | 17400a52624b |
parent 8 | e0b7c95a154f |
child 14 | d5cb8bd33170 |
permissions | -rw-r--r-- |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1 |
# -*- ruby -*- |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2 |
# vim: set noet nosta sw=4 ts=4 : |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4 |
require 'arborist/monitor/snmp' unless defined?( Arborist::Monitor::SNMP ) |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
6 |
# Disk capacity checks. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
7 |
# |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
8 |
# Sets all configured mounts with their current usage percentage |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
9 |
# in an attribute named "mounts". |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
10 |
# |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
11 |
class Arborist::Monitor::SNMP::Disk |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
12 |
include Arborist::Monitor::SNMP |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
13 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
14 |
extend Configurability, Loggability |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
15 |
log_to :arborist_snmp |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
16 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
17 |
# OIDS required to pull disk information from net-snmp. |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
18 |
# |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
19 |
STORAGE_NET_SNMP = { |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
20 |
path: '1.3.6.1.4.1.2021.9.1.2', |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
21 |
percent: '1.3.6.1.4.1.2021.9.1.9', |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
22 |
type: '1.3.6.1.2.1.25.3.8.1.4' |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
23 |
} |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
24 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
25 |
# The OID that matches a local windows hard disk. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
26 |
# |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
27 |
WINDOWS_DEVICES = [ |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
28 |
'1.3.6.1.2.1.25.2.1.4', # local disk |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
29 |
'1.3.6.1.2.1.25.2.1.7' # removables, but we have to include them for iscsi mounts |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
30 |
] |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
31 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
32 |
# OIDS required to pull disk information from Windows. |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
33 |
# |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
34 |
STORAGE_WINDOWS = { |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
35 |
type: '1.3.6.1.2.1.25.2.3.1.2', |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
36 |
path: '1.3.6.1.2.1.25.2.3.1.3', |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
37 |
total: '1.3.6.1.2.1.25.2.3.1.5', |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
38 |
used: '1.3.6.1.2.1.25.2.3.1.6' |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
39 |
} |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
40 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
41 |
# The fallback warning capacity. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
42 |
WARN_AT = 90 |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
43 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
44 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
45 |
# Configurability API |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
46 |
# |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
47 |
configurability( 'arborist.snmp.disk' ) do |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
48 |
# What percentage qualifies as a warning |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
49 |
setting :warn_at, default: WARN_AT |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
50 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
51 |
# If non-empty, only these paths are included in checks. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
52 |
# |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
53 |
setting :include do |val| |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
54 |
if val |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
55 |
mounts = Array( val ).map{|m| Regexp.new(m) } |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
56 |
Regexp.union( mounts ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
57 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
58 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
59 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
60 |
# Paths to exclude from checks |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
61 |
# |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
62 |
setting :exclude, |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
63 |
default: [ '^/dev(/.+)?$', '^/net(/.+)?$', '^/proc$', '^/run$', '^/sys/' ] do |val| |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
64 |
mounts = Array( val ).map{|m| Regexp.new(m) } |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
65 |
Regexp.union( mounts ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
66 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
67 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
68 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
69 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
70 |
### Return the properties used by this monitor. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
71 |
### |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
72 |
def self::node_properties |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
73 |
return USED_PROPERTIES |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
74 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
75 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
76 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
77 |
### Class #run creates a new instance and immediately runs it. |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
78 |
### |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
79 |
def self::run( nodes ) |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
80 |
return new.run( nodes ) |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
81 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
82 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
83 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
84 |
### Perform the monitoring checks. |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
85 |
### |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
86 |
def run( nodes ) |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
87 |
super do |host, snmp| |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
88 |
self.gather_disks( host, snmp ) |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
89 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
90 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
91 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
92 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
93 |
######### |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
94 |
protected |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
95 |
######### |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
96 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
97 |
### Collect mount point usage for +host+ from an existing (and open) |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
98 |
### +snmp+ connection. |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
99 |
### |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
100 |
def gather_disks( host, snmp ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
101 |
mounts = self.system =~ /windows\s+/i ? self.windows_disks( snmp ) : self.unix_disks( snmp ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
102 |
config = self.identifiers[ host ].last || {} |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
103 |
warn_at = config[ 'warn_at' ] || self.class.warn_at |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
104 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
105 |
includes = self.format_mounts( config, 'include' ) || self.class.include |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
106 |
excludes = self.format_mounts( config, 'exclude' ) || self.class.exclude |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
107 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
108 |
mounts.reject! do |path, percentage| |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
109 |
excludes.match( path ) || ( includes && ! includes.match( path ) ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
110 |
end |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
111 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
112 |
errors = [] |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
113 |
warnings = [] |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
114 |
mounts.each_pair do |path, percentage| |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
115 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
116 |
warn = begin |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
117 |
if warn_at.is_a?( Hash ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
118 |
warn_at[ path ] || WARN_AT |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
119 |
else |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
120 |
warn_at |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
121 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
122 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
123 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
124 |
self.log.debug "%s:%s -> at %d, warn at %d" % [ host, path, percentage, warn ] |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
125 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
126 |
if percentage >= warn.to_i |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
127 |
if percentage >= 100 |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
128 |
errors << "%s at %d%% capacity" % [ path, percentage ] |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
129 |
else |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
130 |
warnings << "%s at %d%% capacity" % [ path, percentage ] |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
131 |
end |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
132 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
133 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
134 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
135 |
self.results[ host ] = { mounts: mounts } |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
136 |
self.results[ host ][ :error ] = errors.join(', ') unless errors.empty? |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
137 |
self.results[ host ][ :warning ] = warnings.join(', ') unless warnings.empty? |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
138 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
139 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
140 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
141 |
### Return a single regexp for the 'include' or 'exclude' section of |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
142 |
### resource node's +config+, or nil if nonexistent. |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
143 |
### |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
144 |
def format_mounts( config, section ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
145 |
list = config[ section ] || return |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
146 |
mounts = Array( list ).map{|m| Regexp.new(m) } |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
147 |
return Regexp.union( mounts ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
148 |
end |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
149 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
150 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
151 |
### Fetch information for Windows systems. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
152 |
### |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
153 |
def windows_disks( snmp ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
154 |
raw = snmp.get_bulk([ |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
155 |
STORAGE_WINDOWS[:path], |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
156 |
STORAGE_WINDOWS[:type], |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
157 |
STORAGE_WINDOWS[:total], |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
158 |
STORAGE_WINDOWS[:used] |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
159 |
]).varbinds.map( &:value ) |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
160 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
161 |
disks = {} |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
162 |
raw.each_slice( 4 ) do |device| |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
163 |
next unless device[1].respond_to?( :oid ) && WINDOWS_DEVICES.include?( device[1].oid ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
164 |
next if device[2].zero? |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
165 |
disks[ device[0] ] = (( device[3].to_f / device[2] ) * 100).round( 1 ) |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
166 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
167 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
168 |
return disks |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
169 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
170 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
171 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
172 |
### Fetch information for Unix/MacOS systems. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
173 |
### |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
174 |
def unix_disks( snmp ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
175 |
raw = snmp.get_bulk([ |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
176 |
STORAGE_NET_SNMP[:path], |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
177 |
STORAGE_NET_SNMP[:percent] ]).varbinds.map( &:value ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
178 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
179 |
return Hash[ *raw ] |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
180 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
181 |
|
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
182 |
end # class Arborist::Monitor::SNMP::Disk |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
183 |