sensu-plugins-filesize 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/bin/check-filesize.rb +87 -0
- data/lib/sensu/plugins/filesize/version.rb +7 -0
- data/lib/sensu/plugins/filesize.rb +1 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d69f8b472894862e5d8bc10b3617ffff2a549fed
|
4
|
+
data.tar.gz: 7683aaee0b47661f511d94f17adeac303cefd4d0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 08f7c634673a61d268fa5353c03b930f92e82f86176eec8ea583bdd88ade1596bcbdf4be58c1c04dca304338278d8e6518cbc7d5f23ff67a58cabfbe7424bfed
|
7
|
+
data.tar.gz: 3d6b1c67a037e77ceee436fa9e96693ef949af76f2698e84e67465a03e4ed5666cc3b4fe86922c4ab979e35f53b7bf277ad53139cb6cb0bcdac55cd673a4919e
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 thomis
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# sensu-plugins-filesize
|
2
|
+
|
3
|
+
Sensu plugin to search files based on size.
|
4
|
+
|
5
|
+
## Files
|
6
|
+
* bin/check-filesize.rb
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
```
|
11
|
+
-- check for files greater than 100M in home folder including subfolders
|
12
|
+
check-filesize.rb -f ~ -s +100M
|
13
|
+
|
14
|
+
-- check for files smaller than 100M in home folder including subfolders
|
15
|
+
check-filesize.rb -f ~ -s -100M
|
16
|
+
|
17
|
+
-- check for files exactly of size 50 kb in /apps folder including subfolders
|
18
|
+
check-filesize.rb -f /apps -s 50c
|
19
|
+
```
|
20
|
+
|
21
|
+
## About the -s or -size option
|
22
|
+
|
23
|
+
The size option is transparently passed to the find command. More details can be found in the man pages of the find command (> man find).
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
@@ -0,0 +1,87 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-filesize
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
#
|
7
|
+
# This plugin allows to search for files based o file size
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# plain text
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
#
|
18
|
+
# USAGE:
|
19
|
+
# ./check-filesize.rb -f FOLDER -s SIZE
|
20
|
+
#
|
21
|
+
# NOTES:
|
22
|
+
#
|
23
|
+
# LICENSE:
|
24
|
+
# Copyright (c) 2016 Thomas Steiner
|
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
|
+
|
31
|
+
class CheckFilesize < Sensu::Plugin::Check::CLI
|
32
|
+
option :foldername,
|
33
|
+
description: 'Name of folder (defaut: ~)',
|
34
|
+
short: '-f FOLDERNAME',
|
35
|
+
long: '--folder FOLDERNAME',
|
36
|
+
default: '~' # home folder
|
37
|
+
|
38
|
+
option :filesize,
|
39
|
+
description: 'Size of file',
|
40
|
+
short: '-s FILESIZE',
|
41
|
+
long: '--size FILESIZE',
|
42
|
+
required: true
|
43
|
+
|
44
|
+
def run
|
45
|
+
|
46
|
+
raw = `find #{config[:foldername]} -type f -size #{config[:filesize]}`
|
47
|
+
|
48
|
+
warning('Passed options seems not correct. Please verify.') if $?.exitstatus > 0
|
49
|
+
|
50
|
+
files_found = raw.strip.lines
|
51
|
+
if files_found.size == 0
|
52
|
+
return ok
|
53
|
+
else
|
54
|
+
buffer = ["Files found: #{files_found.size}"]
|
55
|
+
buffer << nil
|
56
|
+
|
57
|
+
files_found.each do |file|
|
58
|
+
file.strip!
|
59
|
+
size = File.size(file)
|
60
|
+
buffer << "#{file} > #{format_size(size)}"
|
61
|
+
end
|
62
|
+
|
63
|
+
warning(buffer.join("\n"))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def format_size(size)
|
70
|
+
conv = [ 'b', 'kb', 'mb', 'gb', 'tb', 'pb', 'eb' ];
|
71
|
+
scale = 1024;
|
72
|
+
|
73
|
+
ndx=1
|
74
|
+
if( size < 2*(scale**ndx) ) then
|
75
|
+
return "#{(size)} #{conv[ndx-1]}"
|
76
|
+
end
|
77
|
+
size=size.to_f
|
78
|
+
[2,3,4,5,6,7].each do |ndx|
|
79
|
+
if( size < 2*(scale**ndx) ) then
|
80
|
+
return "#{'%.3f' % (size/(scale**(ndx-1)))} #{conv[ndx-1]}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
ndx=7
|
84
|
+
return "#{'%.3f' % (size/(scale**(ndx-1)))} #{conv[ndx-1]}"
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "sensu/plugins/filesize/version"
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-plugins-filesize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sensu-Plugins and contributors
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-14 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.4.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.4.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '11.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '11.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.5'
|
69
|
+
description: Sensu plugin to search files based on size
|
70
|
+
email:
|
71
|
+
- thomas.steiner@ikey.ch
|
72
|
+
executables:
|
73
|
+
- check-filesize.rb
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- CHANGELOG.md
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- bin/check-filesize.rb
|
81
|
+
- lib/sensu/plugins/filesize.rb
|
82
|
+
- lib/sensu/plugins/filesize/version.rb
|
83
|
+
homepage: https://github.com/thomis/sensu-plugins-filesize
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata:
|
87
|
+
maintainer: thomis
|
88
|
+
development_status: active
|
89
|
+
production_status: unstable - testing recommended
|
90
|
+
release_draft: 'false'
|
91
|
+
release_prerelease: 'false'
|
92
|
+
post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
|
93
|
+
in /etc/default/sensu
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.9.3
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Sensu plugin to search files based on size
|
113
|
+
test_files: []
|