sensu-plugins-filesystem-checks 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6d07d28e2588407416ad9be1e97af24b52657f24
4
+ data.tar.gz: b821073eb5a2959de9669162836d19704d8f42f9
5
+ SHA512:
6
+ metadata.gz: 344b14c766ebd2265d1bf5cbffb473cb98400d8999bcf3a217a8b98582ee31c4fdfa63941b64b3c1b502fb48f5e0cf28cc32b8b26018991919f95dbb5b5734c5
7
+ data.tar.gz: 45e08076ba50bc0fcc8bab91efd0d03a25e3846688972d3a3a0c158f18938c303e16d2e3335660e16f541a6880a161c6d83bb7e8e590f605160f1ceb3dbf28de
checksums.yaml.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ ,�o�V��Ͳ�:���.+�� ޶ʯ ��-��|��U �<S��c��)%�F����C�pb�҉%�/ں���{ �Տ K:��! .ER|$z���BA��Y˹]����QM�^ �Ċ�I�V$�J��<@g�%�a��W�|���ӂ���T��!D��!(H^� ����Vt���vhڬ@x�5���>
2
+ U� Qsй�l��EƦz ~��U��$�ExUXF>��{�&��/����E��P6
data.tar.gz.sig ADDED
Binary file
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
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][unreleased]
7
+
8
+ ### Added
9
+ - initial release
10
+
11
+ ## 0.0.1 - 2015-04-30
12
+
13
+ ### Added
14
+ - initial release
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sensu-Plugins
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.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ ## Sensu-Plugins-filesystem-checks
2
+
3
+ [![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-filesystem-checks.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-filesystem-checks)
4
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugins-filesystem-checks.svg)](http://badge.fury.io/rb/sensu-plugins-filesystem-checks)
5
+ [![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-filesystem-checks/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-filesystem-checks)
6
+ [![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-filesystem-checks/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-filesystem-checks)
7
+ [![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-filesystem-checks.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-filesystem-checks)
8
+ [ ![Codeship Status for sensu-plugins/sensu-plugins-filesystem-checks](https://codeship.com/projects/4b97d0a0-db4c-0132-445b-5ad94843e341/status?branch=master)](https://codeship.com/projects/79592)
9
+
10
+ ## Functionality
11
+
12
+ ## Files
13
+ * bin/check-dir-count.rb
14
+ * bin/check-checksums.rb
15
+ * bin/check-file-exists.rb
16
+ * bin/check-fs-writable.rb
17
+ * bin/check-mtime.rb
18
+ * bin/check-tail.rb
19
+ * bin/metric-dirsize.rb
20
+ * bin/metric-filesize.rb
21
+
22
+ ## Usage
23
+
24
+ ## Installation
25
+
26
+ [Installation and Setup](https://github.com/sensu-plugins/documentation/blob/master/user_docs/installation_instructions.md)
27
+
28
+ ## Notes
@@ -0,0 +1,77 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-checksums
4
+ #
5
+ # DESCRIPTION:
6
+ # Check the file against its checksum
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux, BSD
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ #
17
+ # USAGE:
18
+ # #YELLOW
19
+ #
20
+ # NOTES:
21
+ #
22
+ # LICENSE:
23
+ # AJ Bourg <aj@ajbourg.com>
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
25
+ # for details.
26
+ #
27
+
28
+ require 'sensu-plugin/check/cli'
29
+ require 'digest'
30
+
31
+ class Checksum < Sensu::Plugin::Check::CLI
32
+ option :files,
33
+ description: 'Comma separated list of files to check.',
34
+ short: '-f FILES',
35
+ long: '--files FILES',
36
+ required: true
37
+
38
+ option :hash,
39
+ description: 'The hash these files must hash as. If unspecified the files will be compared to the first file.',
40
+ short: '-h SHA2HASH',
41
+ long: '--hash SHA2HASH'
42
+
43
+ option :warn_only,
44
+ description: "Warn instead of critical if they don't match",
45
+ short: '-w',
46
+ long: '--warn-only',
47
+ boolean: true
48
+
49
+ def run
50
+ files = config[:files].split(',')
51
+
52
+ if files.length == 1 && !config[:hash]
53
+ unknown 'We have nothing to compare this file with.'
54
+ end
55
+
56
+ hash = config[:hash] || Digest::SHA2.file(files.first).hexdigest
57
+
58
+ errors = []
59
+
60
+ files.each do |file|
61
+ if File.exist?(file)
62
+ file_hash = Digest::SHA2.file(file).hexdigest
63
+ errors << "#{file} does not match" if file_hash != hash
64
+ else
65
+ errors << "#{file} does not exist"
66
+ end
67
+ end
68
+
69
+ if errors.length > 0 && config[:warn_only]
70
+ warning errors.join("\n")
71
+ elsif errors.length > 0
72
+ critical errors.join("\n")
73
+ else
74
+ ok 'Files match.'
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,66 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-dir-count
4
+ #
5
+ # DESCRIPTION:
6
+ # Checks the number of files in a directory
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux, BSD
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ #
17
+ # USAGE:
18
+ # #YELLOW
19
+ #
20
+ # NOTES:
21
+ #
22
+ # LICENSE:
23
+ # Copyright 2014 Sonian, Inc. and contributors. <support@sensuapp.org>
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
25
+ # for details.
26
+ #
27
+
28
+ require 'sensu-plugin/check/cli'
29
+ require 'fileutils'
30
+
31
+ class DirCount < Sensu::Plugin::Check::CLI
32
+ option :directory,
33
+ description: 'Directory to count files in',
34
+ short: '-d DIR',
35
+ long: '--dir DIR',
36
+ required: true
37
+
38
+ option :warning_num,
39
+ description: 'Warn if count of files is greater than provided number',
40
+ short: '-w NUM',
41
+ long: '--warning NUM',
42
+ required: true
43
+
44
+ option :critical_num,
45
+ description: 'Critical if count of files is greater than provided number',
46
+ short: '-c NUM',
47
+ long: '--critical NUM',
48
+ required: true
49
+
50
+ def run
51
+ begin
52
+ # Subtract two for '.' and '..'
53
+ num_files = Dir.entries(config[:directory]).count - 2
54
+ rescue
55
+ unknown "Error listing files in #{config[:directory]}"
56
+ end
57
+
58
+ if num_files >= config[:critical_num].to_i
59
+ critical "#{config[:directory]} has #{num_files} files (threshold: #{config[:critical_num]})"
60
+ elsif num_files >= config[:warning_num].to_i
61
+ warning "#{config[:directory]} has #{num_files} files (threshold: #{config[:warning_num]})"
62
+ else
63
+ ok "#{config[:directory]} has #{num_files} files"
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,67 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-file-exists
4
+ #
5
+ # DESCRIPTION:
6
+ # Sometimes you just need a simple way to test if your alerting is functioning
7
+ # as you've designed it. This test plugin accomplishes just that. But it can
8
+ # also be set to check for the existance of any file (provided you have
9
+ # read-level permissions for it)
10
+ #
11
+ # By default it looks in your /tmp folder and looks for the files CRITICAL,
12
+ # WARNING or UNKNOWN. If it sees that any of those exists it fires off the
13
+ # corresponding status to sensu. Otherwise it fires off an "ok".
14
+ #
15
+ # This allows you to fire off an alert by doing something as simple as:
16
+ # touch /tmp/CRITICAL
17
+ #
18
+ # And then set it ok again with:
19
+ # rm /tmp/CRITICAL
20
+ #
21
+ # OUTPUT:
22
+ # plain text
23
+ #
24
+ # PLATFORMS:
25
+ # Linux, BSD
26
+ #
27
+ # DEPENDENCIES:
28
+ # gem: sensu-plugin
29
+ #
30
+ # USAGE:
31
+ # #YELLOW
32
+ #
33
+ # NOTES:
34
+ #
35
+ # LICENSE:
36
+ # Copyright 2013 Mike Skovgaard <mikesk@gmail.com>
37
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
38
+ # for details.
39
+ #
40
+
41
+ require 'sensu-plugin/check/cli'
42
+
43
+ class CheckFileExists < Sensu::Plugin::Check::CLI
44
+ option :critical,
45
+ short: '-c CRITICAL_FILE',
46
+ default: '/tmp/CRITICAL'
47
+
48
+ option :warning,
49
+ short: '-w WARNING_FILE',
50
+ default: '/tmp/WARNING'
51
+
52
+ option :unknown,
53
+ short: '-u UNKNOWN_FILE',
54
+ default: '/tmp/UNKNOWN'
55
+
56
+ def run
57
+ if config[:critical] && File.exist?(config[:critical])
58
+ critical "#{config[:critical]} exists!"
59
+ elsif config[:warning] && File.exist?(config[:warning])
60
+ warning "#{config[:warning]} exists!"
61
+ elsif config[:unknown] && File.exist?(config[:unknown])
62
+ unknown "#{config[:unknown]} exists!"
63
+ else
64
+ ok 'No test files exist'
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,143 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-fs-writable
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks that a filesystem is writable. Useful for checking for stale NFS mounts.
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: rubysl-tempfile
17
+ #
18
+ # USAGE:
19
+ # ./check-fs-writable.rb --auto (check all volgroups in fstab)
20
+ # ./check-fs-writable.rb --dir /,/var,/usr,/home (check a defined list of directories)
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Copyright 2014 Yieldbot, Inc <Sensu-Plugins>
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugin/check/cli'
31
+ require 'tempfile'
32
+
33
+ #
34
+ # Check Filesystem Writable
35
+ #
36
+ class CheckFSWritable < Sensu::Plugin::Check::CLI
37
+ option :dir,
38
+ description: 'Directory to check for writability',
39
+ short: '-d DIRECTORY',
40
+ long: '--directory DIRECTORY',
41
+ proc: proc { |a| a.split(',') }
42
+
43
+ option :auto,
44
+ description: 'Auto discover mount points via fstab',
45
+ short: '-a',
46
+ long: '--auto-discover'
47
+
48
+ option :debug,
49
+ description: 'Print debug statements',
50
+ long: '--debug'
51
+
52
+ # Setup variables
53
+ #
54
+ def initialize
55
+ super
56
+ @crit_pt_proc = []
57
+ @crit_pt_test = []
58
+ end
59
+
60
+ # Generate output
61
+ #
62
+ def usage_summary
63
+ if @crit_pt_test.empty? && @crit_pt_proc.empty?
64
+ ok 'All filesystems are writable'
65
+ elsif @crit_pt_test || @crit_pt_proc
66
+ critical "The following file systems are not writeable: #{ @crit_pt_test }, #{@crit_pt_proc}"
67
+ end
68
+ end
69
+
70
+ # Get the mount points from the self namespace
71
+ #
72
+ def acquire_mnt_pts
73
+ `grep VolGroup /proc/self/mounts | awk '{print $2, $4}' | awk -F, '{print $1}' | awk '{print $1, $2}'`
74
+ end
75
+
76
+ # Does proc list the mount point as rw
77
+ #
78
+ def rw_in_proc?(mount_info)
79
+ mount_info.each do |pt|
80
+ @crit_pt_proc << "#{ pt.split[0] }" if pt.split[1] != 'rw'
81
+ end
82
+ end
83
+
84
+ # Create a tempfile at each mount point and attempt to write a line to it
85
+ # If it can't write the line, or the mount point does not exist it will
86
+ # generate a critical error
87
+ #
88
+ def rw_test?(mount_info)
89
+ mount_info.each do |pt|
90
+ (Dir.exist? pt.split[0]) || (@crit_pt_test << "#{ pt.split[0] }")
91
+ file = Tempfile.new('.sensu', pt.split[0])
92
+ puts "The temp file we are writing to is: #{ file.path }" if config[:debug]
93
+ # #YELLOW
94
+ # need to add a check here to validate permissions, if none it pukes
95
+ file.write('mops') || @crit_pt_test << "#{ pt.split[0] }"
96
+ file.read || @crit_pt_test << "#{ pt.split[0] }"
97
+ file.close
98
+ file.unlink
99
+ end
100
+ end
101
+
102
+ # Auto-generate a list of mount points to check based upon the self
103
+ # namespace in proc
104
+ #
105
+ def auto_discover
106
+ # #YELLOW
107
+ # this will only work for a single namespace as of now
108
+ mount_info = acquire_mnt_pts.split("\n")
109
+ warning 'No mount points found' if mount_info.length == 0
110
+ # #YELLOW
111
+ # I want to map this at some point to make it pretty and eaiser to read for large filesystems
112
+ puts 'This is a list of mount_pts and their current status: ', mount_info if config[:debug]
113
+ rw_in_proc?(mount_info)
114
+ rw_test?(mount_info)
115
+ puts "The critical mount points according to proc are: #{ @crit_pt_proc }" if config[:debug]
116
+ puts "The critical mount points according to actual testing are: #{ @crit_pt_test }" if config[:debug]
117
+ end
118
+
119
+ # Create a tempfile as each mount point and attempt to write a line to it
120
+ # If it can't write the line, or the mount point does not exist it will
121
+ # generate a critical error
122
+ #
123
+ def manual_test
124
+ config[:dir].each do |d|
125
+ (Dir.exist? d) || (@crit_pt_test << "#{ d }")
126
+ file = Tempfile.new('.sensu', d)
127
+ puts "The temp file we are writing to is: #{ file.path }" if config[:debug]
128
+ # #YELLOW
129
+ # need to add a check here to validate permissions, if none it pukes
130
+ file.write('mops') || @crit_pt_test << "#{ d }"
131
+ file.read || @crit_pt_test << "#{ d }"
132
+ file.close
133
+ file.unlink
134
+ end
135
+ end
136
+
137
+ # Main function
138
+ #
139
+ def run
140
+ (auto_discover if config[:auto]) || (manual_test if config[:dir]) || (warning 'No directorties to check')
141
+ usage_summary
142
+ end
143
+ end
@@ -0,0 +1,93 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-mtime
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks a given file's modified time.
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux, BSD
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: <?>
17
+ #
18
+ # USAGE:
19
+ # #YELLOW
20
+ #
21
+ # NOTES:
22
+ #
23
+ # LICENSE:
24
+ # Copyright 2014 Sonian, Inc. and contributors. <support@sensuapp.org>
25
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
26
+ # for details.
27
+ #
28
+
29
+ require 'sensu-plugin/check/cli'
30
+ require 'fileutils'
31
+
32
+ class Mtime < Sensu::Plugin::Check::CLI
33
+ option :file,
34
+ description: 'File to check last modified time',
35
+ short: '-f FILE',
36
+ long: '--file FILE'
37
+
38
+ option :warning_age,
39
+ description: 'Warn if mtime greater than provided age in seconds',
40
+ short: '-w SECONDS',
41
+ long: '--warning SECONDS'
42
+
43
+ option :critical_age,
44
+ description: 'Critical if mtime greater than provided age in seconds',
45
+ short: '-c SECONDS',
46
+ long: '--critical SECONDS'
47
+
48
+ option :ok_no_exist,
49
+ description: 'OK if file does not exist',
50
+ short: '-o',
51
+ long: '--ok-no-exist',
52
+ boolean: true,
53
+ default: false
54
+
55
+ option :ok_zero_size,
56
+ description: 'OK if file has zero size',
57
+ short: '-z',
58
+ long: '--ok-zero-size',
59
+ boolean: true,
60
+ default: false
61
+
62
+ def run_check(type, age)
63
+ to_check = config["#{type}_age".to_sym].to_i
64
+ # #YELLOW
65
+ if to_check > 0 && age >= to_check # rubocop:disable GuardClause
66
+ send(type, "file is #{age - to_check} seconds past #{type}")
67
+ end
68
+ end
69
+
70
+ def run
71
+ unknown 'No file specified' unless config[:file]
72
+ unknown 'No warn or critical age specified' unless config[:warning_age] || config[:critical_age]
73
+ if File.exist?(config[:file])
74
+ if File.size?(config[:file]).nil? && !config[:ok_zero_size]
75
+ critical 'file has zero size'
76
+ end
77
+ end
78
+ f = Dir.glob(config[:file]).first
79
+ if f
80
+ if File.size?(f).nil? && !config[:ok_zero_size]
81
+ critical 'file has zero size'
82
+ end
83
+ age = Time.now.to_i - File.mtime(f).to_i
84
+ run_check(:critical, age) || run_check(:warning, age) || ok("file is #{age} seconds old")
85
+ else
86
+ if config[:ok_no_exist]
87
+ ok 'file does not exist'
88
+ else
89
+ critical 'file not found'
90
+ end
91
+ end
92
+ end
93
+ end
data/bin/check-tail.rb ADDED
@@ -0,0 +1,100 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-tail
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks the tail of a file for a given patten and sends
7
+ # critical (or optionally warning) message if found. Alternatively,
8
+ # failure can be triggered when the pattern is not found by passing
9
+ # the 'absent' flag.
10
+ #
11
+ # OUTPUT:
12
+ # plain text
13
+ #
14
+ # PLATFORMS:
15
+ # Linux, BSD
16
+ #
17
+ # DEPENDENCIES:
18
+ # gem: sensu-plugin
19
+ #
20
+ # USAGE:
21
+ # #YELLOW
22
+ #
23
+ # NOTES:
24
+ #
25
+ # LICENSE:
26
+ # Copyright 2014 Sonian, Inc. and contributors. <support@sensuapp.org>
27
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
28
+ # for details.
29
+ #
30
+
31
+ require 'sensu-plugin/check/cli'
32
+ require 'fileutils'
33
+
34
+ class Tail < Sensu::Plugin::Check::CLI
35
+ option :file,
36
+ description: 'Path to file',
37
+ short: '-f FILE',
38
+ long: '--file FILE'
39
+
40
+ option :pattern,
41
+ description: 'Pattern to search for',
42
+ short: '-P PAT',
43
+ long: '--pattern PAT'
44
+
45
+ option :absent,
46
+ description: 'Fail if pattern is absent',
47
+ short: '-a',
48
+ long: '--absent',
49
+ boolean: true
50
+
51
+ option :lines,
52
+ description: 'Number of lines to tail',
53
+ short: '-l LINES',
54
+ long: '--lines LINES'
55
+
56
+ option :warn_only,
57
+ description: 'Warn instead of critical on match',
58
+ short: '-w',
59
+ long: '--warn-only',
60
+ boolean: true
61
+
62
+ def tail_file
63
+ `tail #{config[:file]} -n #{config[:lines] || 1}`
64
+ end
65
+
66
+ def pattern_match?
67
+ # #YELLOW
68
+ !!tail_file.match(config[:pattern]) # rubocop:disable Style/DoubleNegation
69
+ end
70
+
71
+ def run
72
+ unknown 'No log file specified' unless config[:file]
73
+ unknown 'No pattern specified' unless config[:pattern]
74
+ if File.exist?(config[:file])
75
+ if !config[:absent]
76
+ if pattern_match?
77
+ send(
78
+ # #YELLOW
79
+ config[:warn_only] ? :warning : :critical, # rubocop:disable BlockNesting
80
+ "Pattern matched: #{config[:pattern]}"
81
+ )
82
+ else
83
+ ok 'No matches found'
84
+ end
85
+ else
86
+ if pattern_match?
87
+ ok 'Match found'
88
+ else
89
+ send(
90
+ # #YELLOW
91
+ config[:warn_only] ? :warning : :critical, # rubocop:disable BlockNesting
92
+ "Pattern not found: #{config[:pattern]}"
93
+ )
94
+ end
95
+ end
96
+ else
97
+ critical 'File not found'
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,91 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # metric-dirsize
4
+ #
5
+ # DESCRIPTION:
6
+ # Simple wrapper around `du` for getting directory size stats,
7
+ # in real size, apparent size and inodes (when supported).
8
+ #
9
+ # Check `du --help` to guess the meaning of real and apparent size.
10
+ #
11
+ # OUTPUT:
12
+ # metric data
13
+ #
14
+ # PLATFORMS:
15
+ # Linux
16
+ #
17
+ # DEPENDENCIES:
18
+ # gem: sensu-plugin
19
+ # gem: socket
20
+ #
21
+ # USAGE:
22
+ # metric-dirsize.rb --dir /var/backups/postgres/ --real
23
+ #
24
+ # NOTES:
25
+ #
26
+ # LICENSE:
27
+ # Copyright 2014 Pablo Figue
28
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
29
+ # for details.
30
+ #
31
+
32
+ require 'socket'
33
+ require 'sensu-plugin/metric/cli'
34
+
35
+ class DirsizeMetrics < Sensu::Plugin::Metric::CLI::Graphite
36
+ option :dirpath,
37
+ short: '-d PATH',
38
+ long: '--dir PATH',
39
+ description: 'Absolute path to directory to measure',
40
+ required: true
41
+
42
+ option :real_size,
43
+ short: '-r',
44
+ long: '--real',
45
+ description: 'Report real size (bytes)',
46
+ required: true,
47
+ default: false
48
+
49
+ option :apparent_size,
50
+ short: '-a',
51
+ long: '--apparent',
52
+ description: 'Report apparent size (bytes)',
53
+ required: true,
54
+ default: false
55
+
56
+ option :inodes,
57
+ short: '-i',
58
+ long: '--inodes',
59
+ description: 'Report inodes used instead of bytes. Not all Linux distributions support this.',
60
+ required: true,
61
+ default: false
62
+
63
+ option :scheme,
64
+ description: 'Metric naming scheme, text to prepend to metric',
65
+ short: '-s SCHEME',
66
+ long: '--scheme SCHEME',
67
+ required: true,
68
+ default: "#{Socket.gethostname}.dirsize"
69
+
70
+ def run
71
+ if config[:real_size]
72
+ options = ''
73
+ suffix = 'bytes'
74
+ end
75
+ if config[:apparent_size]
76
+ options = '--bytes'
77
+ suffix = 'bytes'
78
+ end
79
+ if config[:inodes]
80
+ options = '--inodes'
81
+ suffix = 'inodes'
82
+ end
83
+
84
+ cmd = "/usr/bin/du #{config[:dirpath]} --summarize #{options} | /usr/bin/awk '{ printf \"%s\",$1 }'"
85
+ figure = `#{cmd}`
86
+
87
+ output "#{config[:scheme]}.#{config[:dirpath]}.#{suffix}", figure
88
+
89
+ ok
90
+ end
91
+ end
@@ -0,0 +1,76 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # metric-filesize
4
+ #
5
+ # DESCRIPTION:
6
+ # Simple wrapper around `stat` for getting file size stats,
7
+ # in both, bytes and blocks.
8
+ #
9
+ # OUTPUT:
10
+ # metric data
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ # gem: socket
18
+ #
19
+ # USAGE:
20
+ # #YELLOW
21
+ #
22
+ # NOTES:
23
+ # Based on: Curl HTTP Timings metric (Sensu Community Plugins) by Joe Miller
24
+ #
25
+ # LICENSE:
26
+ # Copyright 2014 Pablo Figue
27
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
28
+ # for details.
29
+ #
30
+
31
+ require 'socket'
32
+ require 'sensu-plugin/metric/cli'
33
+
34
+ class FilesizeMetrics < Sensu::Plugin::Metric::CLI::Graphite
35
+ option :filepath,
36
+ short: '-f PATH',
37
+ long: '--file PATH',
38
+ description: 'Absolute path to file to measure',
39
+ required: true
40
+
41
+ option :omitblocks,
42
+ short: '-o',
43
+ long: '--blocksno',
44
+ description: 'Don\'t report size in blocks',
45
+ required: true,
46
+ default: false
47
+
48
+ option :omitbytes,
49
+ short: '-b',
50
+ long: '--bytesno',
51
+ description: 'Don\'t report size in bytes',
52
+ required: true,
53
+ default: false
54
+
55
+ option :scheme,
56
+ description: 'Metric naming scheme, text to prepend to metric',
57
+ short: '-s SCHEME',
58
+ long: '--scheme SCHEME',
59
+ required: true,
60
+ default: "#{Socket.gethostname}.filesize"
61
+
62
+ def run
63
+ cmd = "/usr/bin/stat --format=\"%s,%b,\" #{config[:filepath]}"
64
+ output = `#{cmd}`
65
+
66
+ (bytes, blocks) = output.split(',')
67
+ unless config[:omitbytes]
68
+ output "#{config[:scheme]}.#{config[:filepath]}.bytes", bytes
69
+ end
70
+ unless config[:omitblocks]
71
+ output "#{config[:scheme]}.#{config[:filepath]}.blocks", blocks
72
+ end
73
+
74
+ ok
75
+ end
76
+ end
@@ -0,0 +1,14 @@
1
+ require 'sensu-plugins-filesystem-checks/version'
2
+
3
+ # Load the defaults
4
+
5
+ #
6
+ # Default class
7
+ #
8
+ module SensuPluginsFilesystemChecks
9
+ class << self
10
+ end
11
+
12
+ class << self
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ require 'json'
2
+
3
+ # encoding: utf-8
4
+ module SensuPluginsFilesystemChecks
5
+ # This defines the version of the gem
6
+ module Version
7
+ MAJOR = 0
8
+ MINOR = 0
9
+ PATCH = 1
10
+
11
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
12
+
13
+ NAME = 'sensu-plugins-filesystem-checks'
14
+ BANNER = "#{NAME} v%s"
15
+
16
+ module_function
17
+
18
+ def version
19
+ format(BANNER, VER_STRING)
20
+ end
21
+
22
+ def json_version
23
+ {
24
+ 'version' => VER_STRING
25
+ }.to_json
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,252 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-filesystem-checks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sensu-Plugins and contributors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDgDCCAmigAwIBAgIBATANBgkqhkiG9w0BAQUFADBDMRIwEAYDVQQDDAltYXR0
14
+ am9uZXMxGDAWBgoJkiaJk/IsZAEZFgh5aWVsZGJvdDETMBEGCgmSJomT8ixkARkW
15
+ A2NvbTAeFw0xNTAxMjgyMTAyNTFaFw0xNjAxMjgyMTAyNTFaMEMxEjAQBgNVBAMM
16
+ CW1hdHRqb25lczEYMBYGCgmSJomT8ixkARkWCHlpZWxkYm90MRMwEQYKCZImiZPy
17
+ LGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyTSzVYnO
18
+ CLgyrIyT1mBQakArQyW8xhi6MlDqyzXHJGeERT790U6EgoBVeS4XoK0ptFZNR8Tf
19
+ zko0w+Nv47TarSCgkPOaxY+mxWnAVR10dOmfeLr7huiMyps+YD56/EF2FqQ3jf/+
20
+ qohENfKD91qy1ieEy+Fn7Pf74ltbNKUdkb9a9eFXQ0DQ4ip5vik7DzjQkUTj4lca
21
+ k6ArwnmHX4YDhZoYtrQJ8jVktN0/+NtA40M5qkCYHNe5tUW25b/tKVYuioxG6b2Z
22
+ oIzaZxRLxf6HVAWpCVRT/F5+/yjigkX4u++eYacfLGleXQzoK7BL65vHGMJygWEE
23
+ 0TKGqFOrl/L0AQIDAQABo38wfTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
24
+ HQ4EFgQUEf6a8Td7MrSZc8ImbLFZAENPbz0wIQYDVR0RBBowGIEWbWF0dGpvbmVz
25
+ QHlpZWxkYm90LmNvbTAhBgNVHRIEGjAYgRZtYXR0am9uZXNAeWllbGRib3QuY29t
26
+ MA0GCSqGSIb3DQEBBQUAA4IBAQBbzXAYA3BVGw8DZ0YYoY1VHPNEcH5qPIApmHO8
27
+ rvSmuUT0yMEi7u00H/5uHRFf4LleGT/+sTdyXKsNPGT9kdRuQEgwi+vf7Zfvd8aX
28
+ UF/+4VkEYf/8rV8Ere6u2QaWPgApdMV6JjKr1fAwCTd8AuGXNaWItiPPMseSQzLJ
29
+ JKP4hVvbc1d+oS925B1lcBiqn2aYvElbyNAVmQPywNNqkWmvtlqj9ZVJfV5HQLdu
30
+ 8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
31
+ HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
32
+ -----END CERTIFICATE-----
33
+ date: 2015-05-22 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: sensu-plugin
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.1.0
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 1.1.0
49
+ - !ruby/object:Gem::Dependency
50
+ name: digest
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 0.0.1
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '='
61
+ - !ruby/object:Gem::Version
62
+ version: 0.0.1
63
+ - !ruby/object:Gem::Dependency
64
+ name: fileutils
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: '0.7'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '='
75
+ - !ruby/object:Gem::Version
76
+ version: '0.7'
77
+ - !ruby/object:Gem::Dependency
78
+ name: codeclimate-test-reporter
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0.4'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '0.4'
91
+ - !ruby/object:Gem::Dependency
92
+ name: rubocop
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0.30'
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '0.30'
105
+ - !ruby/object:Gem::Dependency
106
+ name: rspec
107
+ requirement: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '3.1'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '3.1'
119
+ - !ruby/object:Gem::Dependency
120
+ name: bundler
121
+ requirement: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '1.7'
126
+ type: :development
127
+ prerelease: false
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '1.7'
133
+ - !ruby/object:Gem::Dependency
134
+ name: rake
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '10.0'
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '10.0'
147
+ - !ruby/object:Gem::Dependency
148
+ name: github-markup
149
+ requirement: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '1.3'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '1.3'
161
+ - !ruby/object:Gem::Dependency
162
+ name: redcarpet
163
+ requirement: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '3.2'
168
+ type: :development
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: '3.2'
175
+ - !ruby/object:Gem::Dependency
176
+ name: yard
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '0.8'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: '0.8'
189
+ - !ruby/object:Gem::Dependency
190
+ name: pry
191
+ requirement: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - "~>"
194
+ - !ruby/object:Gem::Version
195
+ version: '0.10'
196
+ type: :development
197
+ prerelease: false
198
+ version_requirements: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - "~>"
201
+ - !ruby/object:Gem::Version
202
+ version: '0.10'
203
+ description: Sensu plugins for filesystems
204
+ email: "<sensu-users@googlegroups.com>"
205
+ executables: []
206
+ extensions: []
207
+ extra_rdoc_files: []
208
+ files:
209
+ - CHANGELOG.md
210
+ - LICENSE
211
+ - README.md
212
+ - bin/check-checksums.rb
213
+ - bin/check-dir-count.rb
214
+ - bin/check-file-exists.rb
215
+ - bin/check-fs-writable.rb
216
+ - bin/check-mtime.rb
217
+ - bin/check-tail.rb
218
+ - bin/metric-dirsize.rb
219
+ - bin/metric-filesize.rb
220
+ - lib/sensu-plugins-filesystem-checks.rb
221
+ - lib/sensu-plugins-filesystem-checks/version.rb
222
+ homepage: https://github.com/sensu-plugins/sensu-plugins-filesystem-checks
223
+ licenses:
224
+ - MIT
225
+ metadata:
226
+ maintainer: ''
227
+ development_status: unmaintained
228
+ production_status: unstable - testing recommended
229
+ release_draft: 'false'
230
+ release_prerelease: 'false'
231
+ post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
232
+ in /etc/default/sensu
233
+ rdoc_options: []
234
+ require_paths:
235
+ - lib
236
+ required_ruby_version: !ruby/object:Gem::Requirement
237
+ requirements:
238
+ - - ">="
239
+ - !ruby/object:Gem::Version
240
+ version: 1.9.3
241
+ required_rubygems_version: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - ">="
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ requirements: []
247
+ rubyforge_project:
248
+ rubygems_version: 2.4.6
249
+ signing_key:
250
+ specification_version: 4
251
+ summary: Sensu plugins for filesystems
252
+ test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ Oj|��/k?p�� ����\�L�F�q�ޚ$� �X �na,���&S�њ0��5aZ0|V��H��❁2�duf�}�6.΄�~��%���(r�#j��
2
+ ����ؤ,���Ҥrx˭)r�F�}.bc��zuL~$��0����a�����B-
3
+ ���@hU����X��h���Ч�������bӈa���Ė�Ʋ��SJ�)��E0���kn��(�E\�X�Y�Wj���5��k��e��>X�k