sensu-plugins-filesystem-checks 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8b2d4536660ff48b5bfee4924bd9667e7b20618
4
- data.tar.gz: 89370d418c72978f110fbf7744385c49b62c79dc
3
+ metadata.gz: bf30978522e96e61fd63a7207cd9fd8af9b9f4c4
4
+ data.tar.gz: e58cdfc8263fff11f0d25ea34cb39a5bae1546b7
5
5
  SHA512:
6
- metadata.gz: 545c0abd600e0d0eea6635d185a45e0c472159e32ccb6d2bb0229f39fd3e5110bdf8190760495ebd5b6962570138cbd44c56f6e4ca7193f7ba1e01f34ddd6f7d
7
- data.tar.gz: ed5d910ef7976af8bd6b43f41469865cf7a0b6bd368171c56055caa0ecf98a4e4e449808569e211504b5e0ef06c148b05d577630d0ba52db75515401de4d3bc9
6
+ metadata.gz: beb4b58f755e8c9c4b9c51233899b4f656fc97121c1b0cdf096aabdfe98437406d876cdf22ec6867d87ee2307fe344d091069c97ad8fa49212b540ed4d50bc8d
7
+ data.tar.gz: f581c11eb41b5cb660ac615b5cf9eeb074473f28d81796db8ad03bbf6b0a144f80b186e643c787577bd9a932387e07955355597f0a8f71b794580ff04567cf1e
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -3,7 +3,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3
3
 
4
4
  This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
5
 
6
- ## Unreleased][unreleased]
6
+ ## [Unreleased][unreleased]
7
+ - nothing
8
+
9
+ ## [0.0.4] - 2015-08-04
10
+ ### Changed
11
+ - Added 'check-dir-size.rb' for checking the total size of a directory
12
+ - Recommited 'check-file-size.rb' from previous repo, with a couple of updates
13
+ - general gem cleanup
7
14
 
8
15
  ## [0.0.3] - 2015-07-14
9
16
  ### Changed
@@ -11,10 +18,7 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
11
18
 
12
19
  ### Added
13
20
  - can now use multi volgroups with autodiscovery
14
-
15
- ## [0.0.3] - [2015-07-07]
16
- ### Added
17
- - the ability to feed a file containing a hash into check-checksums.rb
21
+ - the ability to feed a file containing a hash into check-checksums.rb
18
22
 
19
23
  ## [0.0.2] - [2015-06-02]
20
24
  ### Fixed
@@ -26,4 +30,3 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
26
30
  ## 0.0.1 - [2015-04-30]
27
31
  ### Added
28
32
  - initial release
29
-
data/README.md CHANGED
@@ -23,6 +23,6 @@
23
23
 
24
24
  ## Installation
25
25
 
26
- [Installation and Setup](https://github.com/sensu-plugins/documentation/blob/master/user_docs/installation_instructions.md)
26
+ [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
27
27
 
28
28
  ## Notes
@@ -0,0 +1,114 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-dir-size
4
+ #
5
+ # DESCRIPTION:
6
+ # Checks the size of a directory using 'du'
7
+ # Optional command line parameter to ignore a missing directory
8
+ #
9
+ # WARNING: When using this with a directory with a lot of files, there will be
10
+ # some lag as 'du' recursively goes through the directory
11
+ #
12
+ # OUTPUT:
13
+ # plain text
14
+ #
15
+ # PLATFORMS:
16
+ # Linux, BSD
17
+ #
18
+ # DEPENDENCIES:
19
+ # gem: sensu-plugin
20
+ # binary: du (default location: /usr/bin/du, alternate location can be set)
21
+ #
22
+ # USAGE:
23
+ # check-dir-size.rb [-d|--directory] </path/to/directory>
24
+ # [-w|--warn] <size, in bytes, to warn on>
25
+ # [-c|--critical] <size, in bytes, to go CRITICAL on>
26
+ # [-p|--du-path] <path/to/du>
27
+ # [--ignore_missing]
28
+ #
29
+ # EXAMPLE:
30
+ # check-dir-size.rb /var/spool/example_dir -w 1500000 -c 2000000
31
+ # This will warn at 1.5MB and go critical at 2.0MB for /var/spool/example_dir
32
+ #
33
+ # LICENSE:
34
+ # Copyright 2015 Jayson Sperling (jayson.sperling@sendgrid.com)
35
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
36
+ # for details.
37
+ #
38
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
39
+ require 'sensu-plugin/check/cli'
40
+
41
+ class CheckDirSize < Sensu::Plugin::Check::CLI
42
+ option :directory,
43
+ description: 'Directory to stat (full path not including trailing slash)',
44
+ short: '-d /path/to/directory',
45
+ long: '--directory /path/to/directory',
46
+ required: true
47
+
48
+ option :warn,
49
+ description: 'The size (in bytes) of the directory where WARNING is raised',
50
+ short: '-w SIZE_IN_BYTES',
51
+ long: '--warn SIZE_IN_BYTES',
52
+ default: 3_500_000,
53
+ required: false
54
+
55
+ option :crit,
56
+ description: 'The size (in bytes) of the directory where CRITICAL is raised',
57
+ short: '-c SIZE_IN_BYTES',
58
+ long: '--critical SIZE_IN_BYTES',
59
+ default: 4_000_000,
60
+ required: false
61
+
62
+ option :ignore_missing,
63
+ description: 'Do not throw CRITICAL if the directory is missing',
64
+ long: '--ignore-missing',
65
+ boolean: true,
66
+ default: false,
67
+ required: false
68
+
69
+ option :du_path,
70
+ description: 'The path to the `du` command',
71
+ long: '--du-path /path/to/du',
72
+ short: '-p /path/to/du',
73
+ default: '/usr/bin/du',
74
+ required: false
75
+
76
+ # Even though most everything should have 'du' installed by default, let's do a quick sanity check
77
+ def check_external_dependency
78
+ critical "This system does not have 'du' at #{config[:du_path]}!" unless File.exist? config[:du_path]
79
+ end
80
+
81
+ def du_directory
82
+ if Dir.exist? config[:directory]
83
+ cmd = "#{config[:du_path]} #{config[:directory]} --bytes --summarize | /usr/bin/awk '{ printf \"%s\",$1 }'"
84
+ @dir_size = `#{cmd}`
85
+ else
86
+ if config[:ignore_missing] == true
87
+ ok "Directory #{config[:directory]} does not exist (--ignore-missing was set)"
88
+ else
89
+ critical "Directory #{config[:directory]} does not exist!"
90
+ end
91
+ end
92
+ end
93
+
94
+ def compare_size
95
+ if @dir_size.to_i >= config[:crit].to_i
96
+ critical "Directory #{config[:directory]} is greater than #{format_bytes(config[:crit].to_i)} bytes [actual size: #{format_bytes(@dir_size.to_i)} bytes]"
97
+ elsif @dir_size.to_i >= config[:warn].to_i
98
+ warning "Directory #{config[:directory]} is greater than #{format_bytes(config[:warn].to_i)} bytes [actual size: #{format_bytes(@dir_size.to_i)} bytes]"
99
+ else
100
+ ok "Directory #{config[:directory]} is within size limit"
101
+ end
102
+ end
103
+
104
+ def run
105
+ check_external_dependency
106
+ du_directory
107
+ compare_size
108
+ end
109
+
110
+ # Helper functions
111
+ def format_bytes(number)
112
+ number.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
113
+ end
114
+ end
@@ -0,0 +1,100 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-file-size
4
+ #
5
+ # DESCRIPTION:
6
+ # Checks the file size of a given file.
7
+ # Optional command line parameters to ignore missing files
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux, BSD
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ # check-file-size.rb --file <filename>
20
+ # [--warn <size, in bytes, to warn on>]
21
+ # [--critical <size, in bytes, to go CRITICAL on>]
22
+ # [--ignore_missing]
23
+ # [--debug]
24
+ #
25
+ # LICENSE:
26
+ # Copyright 2015 Jayson Sperling (jayson.sperling@sendgrid.com)
27
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
28
+ # for details.
29
+ #
30
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
31
+ require 'sensu-plugin/check/cli'
32
+
33
+ class CheckFileSize < Sensu::Plugin::Check::CLI
34
+ option :file,
35
+ description: 'file to stat (full path)',
36
+ short: '-f',
37
+ long: '--file FILENAME',
38
+ required: true
39
+
40
+ option :warn,
41
+ description: 'The size (in bytes) of the file where WARNING is raised',
42
+ short: '-w SIZE',
43
+ long: '--warn SIZE',
44
+ proc: proc(&:to_i),
45
+ default: 2_000_000
46
+
47
+ option :crit,
48
+ description: 'The size (in bytes) of the file where CRITICAL is raised',
49
+ short: '-c SIZE',
50
+ long: '--critical SIZE',
51
+ proc: proc(&:to_i),
52
+ default: 3_000_000
53
+
54
+ option :ignore_missing,
55
+ short: '-i',
56
+ long: '--ignore-missing',
57
+ description: 'Do not throw CRITICAL if the file is missing',
58
+ boolean: true,
59
+ default: false
60
+
61
+ option :debug,
62
+ short: '-d',
63
+ long: '--debug',
64
+ description: 'Output list of included filesystems',
65
+ boolean: true,
66
+ default: false
67
+
68
+ def stat_file
69
+ if File.exist? config[:file]
70
+ stat = File.stat(config[:file])
71
+ $stdout.puts stat.inspect if config[:debug] == true
72
+ @file_size = stat.size
73
+ else
74
+ if config[:ignore_missing] == true
75
+ ok "#{config[:file]} does not exist (--ignore-missing was set)"
76
+ else
77
+ critical "#{config[:file]} does not exist"
78
+ end
79
+ end
80
+ end
81
+
82
+ def compare_size
83
+ if @file_size >= config[:crit].to_i
84
+ critical "#{config[:file]} is greater than #{format_bytes(config[:crit].to_i)} bytes! [actual size: #{format_bytes(@file_size)} bytes]"
85
+ elsif @file_size >= config[:warn].to_i
86
+ warning "#{config[:file]} is greater than #{format_bytes(config[:warn].to_i)} bytes! [actual size: #{format_bytes(@file_size)} bytes]"
87
+ else
88
+ ok "#{config[:file]} is within size limit"
89
+ end
90
+ end
91
+
92
+ def run
93
+ stat_file
94
+ compare_size
95
+ end
96
+
97
+ def format_bytes(number)
98
+ number.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
99
+ end
100
+ end
@@ -62,7 +62,7 @@ class CheckFSWritable < Sensu::Plugin::Check::CLI
62
62
  if @crit_pt_test.empty? && @crit_pt_proc.empty?
63
63
  ok 'All filesystems are writable'
64
64
  elsif @crit_pt_test || @crit_pt_proc
65
- critical "The following file systems are not writeable: #{ @crit_pt_test }, #{@crit_pt_proc}"
65
+ critical "The following file systems are not writeable: #{@crit_pt_test}, #{@crit_pt_proc}"
66
66
  end
67
67
  end
68
68
 
@@ -89,7 +89,7 @@ class CheckFSWritable < Sensu::Plugin::Check::CLI
89
89
  #
90
90
  def rw_in_proc?(mount_info)
91
91
  mount_info.each do |pt|
92
- @crit_pt_proc << "#{ pt.split[0] }" if pt.split[1] != 'rw'
92
+ @crit_pt_proc << "#{pt.split[0]}" if pt.split[1] != 'rw'
93
93
  end
94
94
  end
95
95
 
@@ -99,13 +99,13 @@ class CheckFSWritable < Sensu::Plugin::Check::CLI
99
99
  #
100
100
  def rw_test?(mount_info)
101
101
  mount_info.each do |pt|
102
- (Dir.exist? pt.split[0]) || (@crit_pt_test << "#{ pt.split[0] }")
102
+ (Dir.exist? pt.split[0]) || (@crit_pt_test << "#{pt.split[0]}")
103
103
  file = Tempfile.new('.sensu', pt.split[0])
104
- puts "The temp file we are writing to is: #{ file.path }" if config[:debug]
104
+ puts "The temp file we are writing to is: #{file.path}" if config[:debug]
105
105
  # #YELLOW
106
106
  # need to add a check here to validate permissions, if none it pukes
107
- file.write('mops') || @crit_pt_test << "#{ pt.split[0] }"
108
- file.read || @crit_pt_test << "#{ pt.split[0] }"
107
+ file.write('mops') || @crit_pt_test << "#{pt.split[0]}"
108
+ file.read || @crit_pt_test << "#{pt.split[0]}"
109
109
  file.close
110
110
  file.unlink
111
111
  end
@@ -122,8 +122,8 @@ class CheckFSWritable < Sensu::Plugin::Check::CLI
122
122
  puts 'This is a list of mount_pts and their current status: ', mount_info if config[:debug]
123
123
  rw_in_proc?(mount_info)
124
124
  rw_test?(mount_info)
125
- puts "The critical mount points according to proc are: #{ @crit_pt_proc }" if config[:debug]
126
- puts "The critical mount points according to actual testing are: #{ @crit_pt_test }" if config[:debug]
125
+ puts "The critical mount points according to proc are: #{@crit_pt_proc}" if config[:debug]
126
+ puts "The critical mount points according to actual testing are: #{@crit_pt_test}" if config[:debug]
127
127
  true
128
128
  end
129
129
 
@@ -133,13 +133,13 @@ class CheckFSWritable < Sensu::Plugin::Check::CLI
133
133
  #
134
134
  def manual_test
135
135
  config[:dir].each do |d|
136
- (Dir.exist? d) || (@crit_pt_test << "#{ d }")
136
+ (Dir.exist? d) || (@crit_pt_test << "#{d}")
137
137
  file = Tempfile.new('.sensu', d)
138
- puts "The temp file we are writing to is: #{ file.path }" if config[:debug]
138
+ puts "The temp file we are writing to is: #{file.path}" if config[:debug]
139
139
  # #YELLOW
140
140
  # need to add a check here to validate permissions, if none it pukes
141
- file.write('mops') || @crit_pt_test << "#{ d }"
142
- file.read || @crit_pt_test << "#{ d }"
141
+ file.write('mops') || @crit_pt_test << "#{d}"
142
+ file.read || @crit_pt_test << "#{d}"
143
143
  file.close
144
144
  file.unlink
145
145
  end
@@ -2,7 +2,7 @@ module SensuPluginsFilesystemChecks
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 3
5
+ PATCH = 4
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-filesystem-checks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
@@ -30,7 +30,7 @@ cert_chain:
30
30
  8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
31
31
  HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
32
32
  -----END CERTIFICATE-----
33
- date: 2015-07-14 00:00:00.000000000 Z
33
+ date: 2015-08-05 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: sensu-plugin
@@ -47,61 +47,61 @@ dependencies:
47
47
  - !ruby/object:Gem::Version
48
48
  version: 1.2.0
49
49
  - !ruby/object:Gem::Dependency
50
- name: codeclimate-test-reporter
50
+ name: bundler
51
51
  requirement: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0.4'
55
+ version: '1.7'
56
56
  type: :development
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '0.4'
62
+ version: '1.7'
63
63
  - !ruby/object:Gem::Dependency
64
- name: rubocop
64
+ name: codeclimate-test-reporter
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '='
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '0.30'
69
+ version: '0.4'
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - '='
74
+ - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '0.30'
76
+ version: '0.4'
77
77
  - !ruby/object:Gem::Dependency
78
- name: rspec
78
+ name: github-markup
79
79
  requirement: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '3.1'
83
+ version: '1.3'
84
84
  type: :development
85
85
  prerelease: false
86
86
  version_requirements: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '3.1'
90
+ version: '1.3'
91
91
  - !ruby/object:Gem::Dependency
92
- name: bundler
92
+ name: pry
93
93
  requirement: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '1.7'
97
+ version: '0.10'
98
98
  type: :development
99
99
  prerelease: false
100
100
  version_requirements: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '1.7'
104
+ version: '0.10'
105
105
  - !ruby/object:Gem::Dependency
106
106
  name: rake
107
107
  requirement: !ruby/object:Gem::Requirement
@@ -117,61 +117,61 @@ dependencies:
117
117
  - !ruby/object:Gem::Version
118
118
  version: '10.0'
119
119
  - !ruby/object:Gem::Dependency
120
- name: github-markup
120
+ name: redcarpet
121
121
  requirement: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '1.3'
125
+ version: '3.2'
126
126
  type: :development
127
127
  prerelease: false
128
128
  version_requirements: !ruby/object:Gem::Requirement
129
129
  requirements:
130
130
  - - "~>"
131
131
  - !ruby/object:Gem::Version
132
- version: '1.3'
132
+ version: '3.2'
133
133
  - !ruby/object:Gem::Dependency
134
- name: redcarpet
134
+ name: rspec
135
135
  requirement: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - "~>"
138
138
  - !ruby/object:Gem::Version
139
- version: '3.2'
139
+ version: '3.1'
140
140
  type: :development
141
141
  prerelease: false
142
142
  version_requirements: !ruby/object:Gem::Requirement
143
143
  requirements:
144
144
  - - "~>"
145
145
  - !ruby/object:Gem::Version
146
- version: '3.2'
146
+ version: '3.1'
147
147
  - !ruby/object:Gem::Dependency
148
- name: yard
148
+ name: rubocop
149
149
  requirement: !ruby/object:Gem::Requirement
150
150
  requirements:
151
- - - "~>"
151
+ - - '='
152
152
  - !ruby/object:Gem::Version
153
- version: '0.8'
153
+ version: 0.32.1
154
154
  type: :development
155
155
  prerelease: false
156
156
  version_requirements: !ruby/object:Gem::Requirement
157
157
  requirements:
158
- - - "~>"
158
+ - - '='
159
159
  - !ruby/object:Gem::Version
160
- version: '0.8'
160
+ version: 0.32.1
161
161
  - !ruby/object:Gem::Dependency
162
- name: pry
162
+ name: yard
163
163
  requirement: !ruby/object:Gem::Requirement
164
164
  requirements:
165
165
  - - "~>"
166
166
  - !ruby/object:Gem::Version
167
- version: '0.10'
167
+ version: '0.8'
168
168
  type: :development
169
169
  prerelease: false
170
170
  version_requirements: !ruby/object:Gem::Requirement
171
171
  requirements:
172
172
  - - "~>"
173
173
  - !ruby/object:Gem::Version
174
- version: '0.10'
174
+ version: '0.8'
175
175
  description: Sensu plugins for filesystems
176
176
  email: "<sensu-users@googlegroups.com>"
177
177
  executables:
@@ -180,7 +180,9 @@ executables:
180
180
  - check-tail.rb
181
181
  - check-mtime.rb
182
182
  - check-fs-writable.rb
183
+ - check-file-size.rb
183
184
  - check-file-exists.rb
185
+ - check-dir-size.rb
184
186
  - check-dir-count.rb
185
187
  - check-checksums.rb
186
188
  extensions: []
@@ -191,7 +193,9 @@ files:
191
193
  - README.md
192
194
  - bin/check-checksums.rb
193
195
  - bin/check-dir-count.rb
196
+ - bin/check-dir-size.rb
194
197
  - bin/check-file-exists.rb
198
+ - bin/check-file-size.rb
195
199
  - bin/check-fs-writable.rb
196
200
  - bin/check-mtime.rb
197
201
  - bin/check-tail.rb
@@ -225,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
229
  version: '0'
226
230
  requirements: []
227
231
  rubyforge_project:
228
- rubygems_version: 2.4.6
232
+ rubygems_version: 2.4.8
229
233
  signing_key:
230
234
  specification_version: 4
231
235
  summary: Sensu plugins for filesystems
metadata.gz.sig CHANGED
Binary file