author | Mahlon E. Smith <mahlon@martini.nu> |
Sat, 01 Aug 2020 14:17:50 -0700 | |
changeset 30 | 4fe00f5f71d9 |
parent 29 | 40bcd1565627 |
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 = { |
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
20 |
path: '1.3.6.1.4.1.2021.9.1.2', |
8
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', |
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
22 |
type: '1.3.6.1.2.1.25.3.8.1.4', |
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
23 |
access: '1.3.6.1.2.1.25.3.8.1.5' |
8
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 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
26 |
# 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
|
27 |
# |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
28 |
WINDOWS_DEVICES = [ |
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.4', # local disk |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
30 |
'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
|
31 |
] |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
32 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
33 |
# 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
|
34 |
# |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
35 |
STORAGE_WINDOWS = { |
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
36 |
type: '1.3.6.1.2.1.25.2.3.1.2', |
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
37 |
path: '1.3.6.1.2.1.25.2.3.1.3', |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
38 |
total: '1.3.6.1.2.1.25.2.3.1.5', |
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
39 |
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
|
40 |
} |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
41 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
42 |
# The fallback warning capacity. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
43 |
WARN_AT = 90 |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
44 |
|
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
45 |
# Don't alert if a mount is readonly by default. |
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
46 |
ALERT_READONLY = false |
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
47 |
|
27
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
48 |
# Access mode meanings |
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
49 |
ACCESS_READWRITE = 1 |
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
50 |
ACCESS_READONLY = 2 |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
51 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
52 |
# Configurability API |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
53 |
# |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
54 |
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
|
55 |
# 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
|
56 |
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
|
57 |
|
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
58 |
# Set down if the mounts are readonly? |
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
59 |
setting :alert_readonly, default: ALERT_READONLY |
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
60 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
61 |
# 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
|
62 |
# |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
63 |
setting :include do |val| |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
64 |
if val |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
65 |
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
|
66 |
Regexp.union( mounts ) |
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 |
end |
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 |
# 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
|
71 |
# |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
72 |
setting :exclude, |
17
e4f0fd44734d
Fix up the docs, make the default disk exclusion list more useful.
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
73 |
default: [ '^/dev(/.+)?$', '/dev$', '^/net(/.+)?$', '/proc$', '^/run$', '^/sys/', '/sys$' ] do |val| |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
74 |
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
|
75 |
Regexp.union( mounts ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
76 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
77 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
78 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
79 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
80 |
### 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
|
81 |
### |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
82 |
def self::node_properties |
26
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
diff
changeset
|
83 |
used_properties = USED_PROPERTIES.dup |
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
diff
changeset
|
84 |
used_properties << :mounts |
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
diff
changeset
|
85 |
return used_properties |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
86 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
87 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
88 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
89 |
### 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
|
90 |
### |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
91 |
def self::run( nodes ) |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
92 |
return new.run( nodes ) |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
93 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
94 |
|
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 |
### Perform the monitoring checks. |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
97 |
### |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
98 |
def run( nodes ) |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
99 |
super do |host, snmp| |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
100 |
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
|
101 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
102 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
103 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
104 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
105 |
######### |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
106 |
protected |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
107 |
######### |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
108 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
109 |
### 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
|
110 |
### +snmp+ connection. |
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 |
def gather_disks( host, snmp ) |
26
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
diff
changeset
|
113 |
current_mounts = self.system =~ /windows\s+/i ? self.windows_disks( snmp ) : self.unix_disks( snmp ) |
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
diff
changeset
|
114 |
config = self.identifiers[ host ].last['config'] || {} |
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
diff
changeset
|
115 |
warn_at = config[ 'warn_at' ] || self.class.warn_at |
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
116 |
alert_readonly = config[ 'alert_readonly' ] || self.class.alert_readonly |
26
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
diff
changeset
|
117 |
|
27
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
118 |
self.log.debug self.identifiers[ host ] |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
119 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
120 |
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
|
121 |
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
|
122 |
|
27
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
123 |
current_mounts.reject! do |path, data| |
14
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
124 |
path = path.to_s |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
125 |
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
|
126 |
end |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
127 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
128 |
errors = [] |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
129 |
warnings = [] |
27
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
130 |
current_mounts.each_pair do |path, data| |
17
e4f0fd44734d
Fix up the docs, make the default disk exclusion list more useful.
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
131 |
warn = if warn_at.is_a?( Hash ) |
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
132 |
warn_at[ path ] || self.class.warn_at |
17
e4f0fd44734d
Fix up the docs, make the default disk exclusion list more useful.
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
133 |
else |
e4f0fd44734d
Fix up the docs, make the default disk exclusion list more useful.
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
134 |
warn_at |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
135 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
136 |
|
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
137 |
readonly = alert_readonly.is_a?( Hash ) ? alert_readonly[ path ] : alert_readonly |
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
138 |
|
27
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
139 |
self.log.debug "%s:%s -> %p, warn at %d" % [ host, path, data, warn ] |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
140 |
|
27
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
141 |
if data[ :capacity ] >= warn.to_i |
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
142 |
if data[ :capacity ] >= 100 |
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
143 |
errors << "%s at %d%% capacity" % [ path, data[ :capacity ] ] |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
144 |
else |
27
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
145 |
warnings << "%s at %d%% capacity" % [ path, data[ :capacity ] ] |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
146 |
end |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
147 |
end |
27
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
148 |
|
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
149 |
if readonly && data[ :accessmode ] == ACCESS_READONLY |
27
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
150 |
errors << "%s is mounted read-only." % [ path ] |
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
151 |
end |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
152 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
153 |
|
26
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
diff
changeset
|
154 |
# Remove any past mounts that configuration exclusions should |
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
diff
changeset
|
155 |
# now omit. |
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
diff
changeset
|
156 |
mounts = self.identifiers[ host ].last[ 'mounts' ] || {} |
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
diff
changeset
|
157 |
mounts.keys.each{|k| mounts[k] = nil } |
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
diff
changeset
|
158 |
|
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
diff
changeset
|
159 |
mounts.merge!( current_mounts ) |
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
17
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 |
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
|
162 |
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
|
163 |
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
|
164 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
165 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
166 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
167 |
### 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
|
168 |
### 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
|
169 |
### |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
170 |
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
|
171 |
list = config[ section ] || return |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
172 |
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
|
173 |
return Regexp.union( mounts ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
174 |
end |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
175 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
176 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
177 |
### 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
|
178 |
### |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
179 |
def windows_disks( snmp ) |
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
180 |
paths = snmp.walk( oid: STORAGE_WINDOWS[:path] ).each_with_object( [] ) do |(_, value), acc| |
14
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
181 |
acc << value |
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
182 |
end |
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
183 |
types = snmp.walk( oid: STORAGE_WINDOWS[:type] ).each_with_object( [] ) do |(_, value), acc| |
14
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
184 |
acc << WINDOWS_DEVICES.include?( value ) |
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
185 |
end |
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
186 |
totals = snmp.walk( oid: STORAGE_WINDOWS[:total] ).each_with_object( [] ) do |(_, value), acc| |
14
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
187 |
acc << value |
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
188 |
end |
29
40bcd1565627
Alterations for consistency, add documentation. Version bump.
Mahlon E. Smith <mahlon@martini.nu>
parents:
27
diff
changeset
|
189 |
used = snmp.walk( oid: STORAGE_WINDOWS[:used] ).each_with_object( [] ) do |(_, value), acc| |
14
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
190 |
acc << value |
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
191 |
end |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
192 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
193 |
disks = {} |
14
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
194 |
paths.each_with_index do |path, idx| |
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
195 |
next if totals[ idx ].zero? |
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
196 |
next unless types[ idx ] |
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
197 |
disks[ path ] ||= {} |
27
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
198 |
disks[ path ][ :capacity ] = (( used[idx].to_f / totals[idx] ) * 100).round( 1 ) |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
199 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
200 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
201 |
return disks |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
202 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
203 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
204 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
205 |
### 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
|
206 |
### |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
207 |
def unix_disks( snmp ) |
27
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
208 |
paths = snmp.walk( oid: STORAGE_NET_SNMP[:path] ).each_with_object( [] ) do |(_, value), acc| |
14
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
209 |
acc << value |
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
210 |
end |
27
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
211 |
capacities = snmp.walk( oid: STORAGE_NET_SNMP[:percent] ).each_with_object( [] ) do |(_, value), acc| |
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
212 |
acc << value |
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
213 |
end |
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
214 |
accessmodes = snmp.walk( oid: STORAGE_NET_SNMP[:access] ).each_with_object( [] ) do |(_, value), acc| |
14
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
215 |
acc << value |
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
216 |
end |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
217 |
|
27
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
218 |
pairs = paths.each_with_object( {} ).with_index do |(p, acc), idx| |
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
219 |
acc[p] = { capacity: capacities[idx], accessmode: accessmodes[idx] } |
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
220 |
end |
02b8e772e0c5
check for readonly filesystems in SNMP::Disk
Katelyn Schiesser <katelyn.schiesser@gmail.com>
parents:
26
diff
changeset
|
221 |
return pairs |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
222 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
223 |
|
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
224 |
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
|
225 |