-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-mountpoint.rb
executable file
·66 lines (61 loc) · 1.27 KB
/
check-mountpoint.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! /usr/bin/env ruby
#
# check-mountpoints
#
# DESCRIPTION:
# Check if the provided dirpaths are mountpoints of just simple folders
#
# OUTPUT:
# plain text
#
# PLATFORMS:
# Linux
#
# DEPENDENCIES:
# gem: sensu-plugin
# gem: pathname
#
# USAGE:
# ./check-mountpoints -p <path>[,<path>]
#
# NOTES:
#
# LICENSE:
# Marcos Martínez <frommelmak@gmail.com>
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
#
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-plugin/check/cli'
require 'pathname'
class CheckMountPoints < Sensu::Plugin::Check::CLI
option :paths,
description: 'Mountpoint directory paths to check, comma-separated',
short: '-p PATHS',
long: '--path PATHS',
proc: proc { |a| a.split(',') },
required: true
def check_mount_points
@bad_mp = Array.new
for path in config[:paths]
pn = Pathname.new(path)
mp = pn.mountpoint?()
if mp == false
@bad_mp.push(path)
end
end
if @bad_mp.count() > 0
return false
else
return true
fi
end
end
def run
if !check_mount_points
critical "Mountpoint(s) #{@bad_mp.join(',')} not mounted!"
else
ok 'All paths are mountpoints'
end
end
end