sensu-plugins-fsmounts 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 142690832f3a193c3724334ff4d8b1820d4b668d
4
+ data.tar.gz: d84b25fba93332847c82b17e70a699db2f150d77
5
+ SHA512:
6
+ metadata.gz: 20f9df903c18182b6179299d7ce62e761641230ff88c0a491e5257f3815fa39742e170299642c3f039419189213a8bbac5c54cb5c93d3b9d659c61977b9e88b4
7
+ data.tar.gz: e9bc17b5197a64aae998620a0e4aa9e43cb6ad49c500af344f1c219de1462c4906bff77ef67c01a4b89d37d3d3c88a58e67ac05b125b941e3e626ede1add40fa
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Change Log
2
+ This project adheres to [Semantic Versioning](http://semver.org/).
3
+
4
+ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
+
6
+ ## Unreleased
7
+
8
+ ## [0.0.1] - 2015-12-29
9
+ ### Added
10
+ - Initial release
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2015 Matteo Cerutti
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Sensu plugin for monitoring mount points
2
+
3
+ A sensu plugin to monitor whether entries listed in /etc/fstab are mounted and the other way around, as in currently mounted volumes have an entry in /etc/fstab.
4
+
5
+ The plugin generates multiple OK/WARN/CRIT/UNKNOWN events via the sensu client socket (https://sensuapp.org/docs/latest/clients#client-socket-input)
6
+ so that you do not miss state changes when monitoring multiple mountpoints.
7
+
8
+ ## Usage
9
+
10
+ The plugin accepts the following command line options:
11
+
12
+ ```
13
+ Usage: check-fsmounts.rb (options)
14
+ --fstype <TYPE> Comma separated list of file system type(s) (default: all)
15
+ --ignore-fstype <TYPE> Comma separated list of file system type(s) to ignore
16
+ --ignore-mount <MOUNTPOINT> Comma separated list of mount point(s) to ignore
17
+ --ignore-mount-regex <MOUNTPOINT>
18
+ Comma separated list of mount point(s) to ignore (regex)
19
+ --mount <MOUNTPOINT> Comma separated list of mount point(s) (default: all)
20
+ --mount-regex <MOUNTPOINT> Comma separated list of mount point(s) (regex)
21
+ -w, --warn Warn instead of throwing a critical failure
22
+ ```
23
+
24
+ ## Author
25
+ Matteo Cerutti - <matteo.cerutti@hotmail.co.uk>
@@ -0,0 +1,265 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # check-fsmounts.rb
4
+ #
5
+ # Author: Matteo Cerutti <matteo.cerutti@hotmail.co.uk>
6
+ #
7
+
8
+ require 'sensu-plugin/check/cli'
9
+ require 'json'
10
+ require 'socket'
11
+ require 'sys/filesystem'
12
+ require 'fstab'
13
+
14
+ class CheckFsMounts < Sensu::Plugin::Check::CLI
15
+ option :fstype,
16
+ :description => "Comma separated list of file system type(s) (default: all)",
17
+ :long => "--fstype <TYPE>",
18
+ :proc => proc { |a| a.split(',') },
19
+ :default => []
20
+
21
+ option :ignore_fstype,
22
+ :description => "Comma separated list of file system type(s) to ignore",
23
+ :long => "--ignore-fstype <TYPE>",
24
+ :proc => proc { |a| a.split(',') },
25
+ :default => []
26
+
27
+ option :mount,
28
+ :description => "Comma separated list of mount point(s) (default: all)",
29
+ :long => "--mount <MOUNTPOINT>",
30
+ :proc => proc { |a| a.split(',') },
31
+ :default => []
32
+
33
+ option :mount_regex,
34
+ :description => "Comma separated list of mount point(s) (regex)",
35
+ :long => "--mount-regex <MOUNTPOINT>",
36
+ :proc => proc { |a| a.split(',') },
37
+ :default => []
38
+
39
+ option :ignore_mount,
40
+ :description => "Comma separated list of mount point(s) to ignore",
41
+ :long => "--ignore-mount <MOUNTPOINT>",
42
+ :proc => proc { |a| a.split(',') },
43
+ :default => []
44
+
45
+ option :ignore_mount_regex,
46
+ :description => "Comma separated list of mount point(s) to ignore (regex)",
47
+ :long => "--ignore-mount-regex <MOUNTPOINT>",
48
+ :proc => proc { |a| a.split(',') },
49
+ :default => []
50
+
51
+ option :warn,
52
+ :description => "Warn instead of throwing a critical failure",
53
+ :short => "-w",
54
+ :long => "--warn",
55
+ :boolean => false
56
+
57
+ option :dryrun,
58
+ :description => "Do not send events to sensu client socket",
59
+ :long => "--dryrun",
60
+ :boolean => true,
61
+ :default => false
62
+
63
+ def initialize()
64
+ super
65
+
66
+ # retrieve all entries in the system fstab
67
+ @fstab_entries = get_fstab_entries()
68
+
69
+ # discover currently mounted filesystems
70
+ @mounted_filesystems = get_mounted_filesystems()
71
+ end
72
+
73
+ def get_fstab_entries()
74
+ entries = {}
75
+
76
+ fstab = Fstab.new("/etc/fstab")
77
+ fstab.entries.each do |device, entry|
78
+ if config[:ignore_fstype].size > 0
79
+ next if config[:ignore_fstype].include?(entry[:type])
80
+ end
81
+
82
+ if config[:fstype].size > 0
83
+ next unless config[:fstype].include?(entry[:type])
84
+ end
85
+
86
+ if config[:ignore_mount].size > 0
87
+ next if config[:ignore_mount].include?(entry[:mount_point])
88
+ end
89
+
90
+ if config[:ignore_mount_regex].size > 0
91
+ b = false
92
+ config[:ignore_mount_regex].each do |mnt|
93
+ if entry[:mount_point] =~ Regexp.new(mnt)
94
+ b = true
95
+ break
96
+ end
97
+ end
98
+ next if b
99
+ end
100
+
101
+ if config[:mount].size > 0
102
+ next unless config[:mount].include?(entry[:mount_type])
103
+ end
104
+
105
+ if config[:mount_regex].size > 0
106
+ b = true
107
+ config[:mount_regex].each do |mnt|
108
+ if entry[:mount_point] =~ Regexp.new(mnt)
109
+ b = false
110
+ break
111
+ end
112
+ end
113
+ next if b
114
+ end
115
+
116
+ entries[device] = {
117
+ :mount_point => entry[:mount_point]
118
+ }
119
+ end
120
+
121
+ entries
122
+ end
123
+
124
+ def get_mounted_filesystems()
125
+ mounts = {}
126
+
127
+ Sys::Filesystem.mounts.each do |fs|
128
+ # always ignore the following mount types
129
+ #next if ["rootfs", "proc", "sysfs", "devtmpfs", "devpts", "securityfs", "autofs", "pstore"].include?(fs.mount_type)
130
+
131
+ if config[:ignore_fstype].size > 0
132
+ next if config[:ignore_fstype].include?(fs.mount_type)
133
+ end
134
+
135
+ if config[:fstype].size > 0
136
+ next unless config[:fstype].include?(fs.mount_type)
137
+ end
138
+
139
+ if config[:ignore_mount].size > 0
140
+ next if config[:ignore_mount].include?(fs.mount_type)
141
+ end
142
+
143
+ if config[:ignore_mount_regex].size > 0
144
+ b = false
145
+ config[:ignore_mount_regex].each do |mnt|
146
+ if fs.mount_point =~ Regexp.new(mnt)
147
+ b = true
148
+ break
149
+ end
150
+ end
151
+ next if b
152
+ end
153
+
154
+ if config[:mount].size > 0
155
+ next unless config[:mount].include?(fs.mount_type)
156
+ end
157
+
158
+ if config[:mount_regex].size > 0
159
+ b = true
160
+ config[:mount_regex].each do |mnt|
161
+ if fs.mount_point =~ Regexp.new(mnt)
162
+ b = false
163
+ break
164
+ end
165
+ end
166
+ next if b
167
+ end
168
+
169
+ mounts[fs.name] = {
170
+ :mount_point => fs.mount_point
171
+ }
172
+ end
173
+
174
+ mounts
175
+ end
176
+
177
+ def send_client_socket(data)
178
+ if config[:dryrun]
179
+ puts data.inspect
180
+ else
181
+ sock = UDPSocket.new
182
+ sock.send(data + "\n", 0, "127.0.0.1", 3030)
183
+ end
184
+ end
185
+
186
+ def send_ok(check_name, msg)
187
+ event = {"name" => check_name, "status" => 0, "output" => "OK: #{msg}", "handler" => config[:handler]}
188
+ send_client_socket(event.to_json)
189
+ end
190
+
191
+ def send_warning(check_name, msg)
192
+ event = {"name" => check_name, "status" => 1, "output" => "WARNING: #{msg}", "handler" => config[:handler]}
193
+ send_client_socket(event.to_json)
194
+ end
195
+
196
+ def send_critical(check_name, msg)
197
+ event = {"name" => check_name, "status" => 2, "output" => "CRITICAL: #{msg}", "handler" => config[:handler]}
198
+ send_client_socket(event.to_json)
199
+ end
200
+
201
+ def send_unknown(check_name, msg)
202
+ event = {"name" => check_name, "status" => 3, "output" => "UNKNOWN: #{msg}", "handler" => config[:handler]}
203
+ send_client_socket(event.to_json)
204
+ end
205
+
206
+ def run
207
+ problems = 0
208
+
209
+ # check if currently mounted filesystems have an entry in fstab
210
+ @mounted_filesystems.each do |device, mount|
211
+ check_name = "fsmounts-#{mount[:mount_point].gsub('/', '_')}"
212
+
213
+ if @fstab_entries.has_key?(device)
214
+ if @fstab_entries[device][:mount_point] == mount[:mount_point]
215
+ send_ok(check_name, "Device #{device} mounted at #{mount[:mount_point]} found in /etc/fstab")
216
+ else
217
+ msg = "Device #{device} found in /etc/fstab but mountpoints do not match!"
218
+
219
+ if config[:warn]
220
+ send_warning(check_name, msg)
221
+ else
222
+ send_critical(check_name, msg)
223
+ end
224
+
225
+ problems += 1
226
+ end
227
+ else
228
+ msg = "Device #{device} mounted at #{mount[:mount_point]} not found in /etc/fstab"
229
+
230
+ if config[:warn]
231
+ send_warning(check_name, msg)
232
+ else
233
+ send_critical(check_name, msg)
234
+ end
235
+
236
+ problems += 1
237
+ end
238
+ end
239
+
240
+ # now check if fstab entries are mounted
241
+ @fstab_entries.each do |device, entry|
242
+ check_name = "fsmounts-#{entry[:mount_point].gsub('/', '_')}"
243
+
244
+ unless @mounted_filesystems.has_key?(device)
245
+ msg = "Fstab entry with device #{device} and mountpoint #{entry[:mount_point]} is not mounted"
246
+
247
+ if config[:warn]
248
+ send_warning(check_name, msg)
249
+ else
250
+ send_critical(check_name, msg)
251
+ end
252
+
253
+ problems += 1
254
+ end
255
+ end
256
+
257
+ if problems > 0
258
+ message("Found #{problems} problems")
259
+ warning if config[:warn]
260
+ critical
261
+ else
262
+ ok("All mountpoints are OK")
263
+ end
264
+ end
265
+ end
@@ -0,0 +1,9 @@
1
+ module SensuPluginsFsMounts
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 1
6
+
7
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ require 'sensu-plugins-fsmounts/version'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-fsmounts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matteo Cerutti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sensu-plugin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sys-filesystem
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: fstab
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.1
55
+ description: This plugin provides facilities for monitoring mount points
56
+ email: "<matteo.cerutti@hotmail.co.uk>"
57
+ executables:
58
+ - check-fsmounts.rb
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - LICENSE
64
+ - README.md
65
+ - bin/check-fsmounts.rb
66
+ - lib/sensu-plugins-fsmounts.rb
67
+ - lib/sensu-plugins-fsmounts/version.rb
68
+ homepage: https://github.com/m4ce/sensu-plugins-fsmounts
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ maintainer: "@m4ce"
73
+ development_status: active
74
+ production_status: stable
75
+ release_draft: 'false'
76
+ release_prerelease: 'false'
77
+ post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
78
+ in /etc/default/sensu
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 1.9.3
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.5.1
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Sensu plugins for monitoring mount points
98
+ test_files: []