syswatch 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+
20
+ *.swp
21
+ *.swo
22
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in syswatch.gemspec
4
+ gemspec
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ syswatch (0.0.1)
5
+ pony
6
+ sys-filesystem
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (3.2.12)
12
+ i18n (~> 0.6)
13
+ multi_json (~> 1.0)
14
+ daemons (1.1.9)
15
+ diff-lcs (1.2.4)
16
+ eventmachine (1.0.3)
17
+ ffi (1.8.1)
18
+ haml (4.0.2)
19
+ tilt
20
+ i18n (0.6.4)
21
+ mail (2.5.3)
22
+ i18n (>= 0.4.0)
23
+ mime-types (~> 1.16)
24
+ treetop (~> 1.4.8)
25
+ mailcatcher (0.5.11)
26
+ activesupport (~> 3.0)
27
+ eventmachine (~> 1.0.0)
28
+ haml (>= 3.1, < 5)
29
+ mail (~> 2.3)
30
+ sinatra (~> 1.2)
31
+ skinny (~> 0.2.3)
32
+ sqlite3 (~> 1.3)
33
+ thin (~> 1.5.0)
34
+ mime-types (1.23)
35
+ multi_json (1.7.3)
36
+ polyglot (0.3.3)
37
+ pony (1.4.1)
38
+ mail (> 2.0)
39
+ rack (1.5.2)
40
+ rack-protection (1.5.0)
41
+ rack
42
+ rake (10.0.4)
43
+ rspec (2.13.0)
44
+ rspec-core (~> 2.13.0)
45
+ rspec-expectations (~> 2.13.0)
46
+ rspec-mocks (~> 2.13.0)
47
+ rspec-core (2.13.1)
48
+ rspec-expectations (2.13.0)
49
+ diff-lcs (>= 1.1.3, < 2.0)
50
+ rspec-mocks (2.13.1)
51
+ simplecov (0.7.1)
52
+ multi_json (~> 1.0)
53
+ simplecov-html (~> 0.7.1)
54
+ simplecov-html (0.7.1)
55
+ sinatra (1.4.2)
56
+ rack (~> 1.5, >= 1.5.2)
57
+ rack-protection (~> 1.4)
58
+ tilt (~> 1.3, >= 1.3.4)
59
+ skinny (0.2.3)
60
+ eventmachine (~> 1.0.0)
61
+ thin (~> 1.5.0)
62
+ sqlite3 (1.3.7)
63
+ sys-filesystem (1.1.0)
64
+ ffi
65
+ thin (1.5.1)
66
+ daemons (>= 1.0.9)
67
+ eventmachine (>= 0.12.6)
68
+ rack (>= 1.0.0)
69
+ tilt (1.4.0)
70
+ treetop (1.4.12)
71
+ polyglot
72
+ polyglot (>= 0.3.1)
73
+ yard (0.8.6.1)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ mailcatcher
80
+ rake
81
+ rspec (~> 2.10)
82
+ simplecov
83
+ syswatch!
84
+ yard
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Łukasz Jachymczyk
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.
@@ -0,0 +1,4 @@
1
+ syswatch
2
+ ========
3
+
4
+ Simple system monitoring tool with e-mail alerting
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :test => :spec
8
+ task :default => :spec
9
+
10
+ require 'yard'
11
+ YARD::Rake::YardocTask.new
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'syswatch'
4
+
5
+ SysWatch::CLI.new(ARGV, ENV)
@@ -0,0 +1,17 @@
1
+ # SysWatch config file
2
+
3
+ :label: Monitored Site
4
+ :mountpoints:
5
+ - /
6
+ - /home
7
+ :treshold: 10 #percent
8
+ :delay: 3600 #seconds
9
+ :mail:
10
+ :to: 'you@example.com'
11
+ :from: 'you@example.com'
12
+ :via: :smtp
13
+ :via_options:
14
+ :address: 'localhost'
15
+ :port: '1025'
16
+ :authentication: :plain
17
+ :domain: "localhost.localdomain"
@@ -0,0 +1,9 @@
1
+ require "syswatch/version"
2
+ require "syswatch/runner"
3
+ require "syswatch/cli"
4
+
5
+ module SysWatch
6
+ DEFAULTS = {
7
+ :config => "/etc/syswatch.yml"
8
+ }
9
+ end
@@ -0,0 +1,43 @@
1
+ require "optparse"
2
+
3
+ module SysWatch
4
+
5
+ # Handles command line interface
6
+ class CLI
7
+
8
+ # Initialize a new system watcher
9
+ #
10
+ # @param argv [Hash] the command line parameters hash (usually `ARGV`).
11
+ # @param env [Hash] the environment variables hash (usually `ENV`).
12
+ def initialize(argv, env)
13
+ parse_options! argv
14
+
15
+ @runner = Runner.new @options
16
+ end
17
+
18
+ # Parse the command line options
19
+ def parse_options!(args)
20
+ @options = {}
21
+ opts = ::OptionParser.new do |opts|
22
+ opts.banner = "Usage: syswatch [options]\n\n Options:"
23
+
24
+ opts.on("-f", "--foreground", "Do not daemonize, just run in foreground.") do |f|
25
+ @options[:foreground] = f
26
+ end
27
+
28
+ opts.on("-v", "--verbose", "Be verbose, print out some messages.") do |v|
29
+ @options[:verbose] = v
30
+ end
31
+
32
+ opts.on("-t", "--test", "Test notifications.") do |t|
33
+ @options[:test] = t
34
+ end
35
+
36
+ opts.on("-c", "--config [FILE]", "Use a specific config file, instead of `#{SysWatch::DEFAULTS[:config]}`") do |config|
37
+ @options[:config] = config
38
+ end
39
+ end
40
+ opts.parse! args
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,54 @@
1
+ require 'sys/filesystem'
2
+ require 'pony'
3
+ require "yaml"
4
+
5
+ module SysWatch
6
+ class Runner
7
+ def initialize options
8
+ @options = {
9
+ :foreground => false,
10
+ :verbose => false,
11
+ :config => SysWatch::DEFAULTS[:config]
12
+ }.merge!(options)
13
+
14
+ if read_config
15
+ Process.daemon unless @options[:foreground]
16
+
17
+ if @options[:test]
18
+ notify "/foo", 0.1
19
+ return
20
+ end
21
+
22
+ begin
23
+ @configuration[:mountpoints].each do |mp|
24
+ examine mp
25
+ end
26
+ end while sleep(@configuration[:delay])
27
+ end
28
+ end
29
+
30
+ def examine mountpoint
31
+ stat = Sys::Filesystem.stat(mountpoint)
32
+ percent_left = stat.blocks_available.to_f / stat.blocks.to_f
33
+ puts percent_left
34
+ if percent_left < @configuration[:treshold]/100.0
35
+ notify mountpoint, percent_left
36
+ end
37
+ end
38
+
39
+ def notify mountpoint, percent_left
40
+ mail = {
41
+ :subject => "[SysWatch - #{@configuration[:label]}] Alert",
42
+ :body => ("Mountpoint %s has only %d%% space left!" % [mountpoint, percent_left*100])
43
+ }
44
+ Pony.mail(mail.merge(@configuration[:mail]))
45
+ end
46
+
47
+ def read_config
48
+ @configuration = YAML.load_file(@options[:config])
49
+ rescue
50
+ $stderr.puts "Unable to open config file #{@options[:config]}. Exiting."
51
+ false
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module SysWatch
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/syswatch/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Łukasz Jachymczyk"]
6
+ gem.email = ["lukasz.jachymczyk@sology.pl"]
7
+ gem.description = %q{Simple system monitoring tool with e-mail alerting.}
8
+ gem.summary = %q{Simple system monitoring tool with e-mail alerting.}
9
+ gem.homepage = "https://github.com/Sology/syswatch"
10
+
11
+ gem.name = "syswatch"
12
+ gem.license = "MIT"
13
+ gem.version = SysWatch::VERSION
14
+ gem.required_ruby_version = '>= 1.9'
15
+
16
+ gem.files = `git ls-files`.split($\)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency 'sys-filesystem'
22
+ gem.add_dependency 'pony'
23
+
24
+ gem.add_development_dependency 'rake'
25
+ gem.add_development_dependency 'rspec', '~> 2.10'
26
+ gem.add_development_dependency 'simplecov'
27
+ gem.add_development_dependency 'yard'
28
+ gem.add_development_dependency 'mailcatcher'
29
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: syswatch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Łukasz Jachymczyk
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sys-filesystem
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: pony
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.10'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.10'
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: yard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: mailcatcher
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Simple system monitoring tool with e-mail alerting.
127
+ email:
128
+ - lukasz.jachymczyk@sology.pl
129
+ executables:
130
+ - syswatch
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - LICENSE
138
+ - README.md
139
+ - Rakefile
140
+ - bin/syswatch
141
+ - examples/syswatch.yml
142
+ - lib/syswatch.rb
143
+ - lib/syswatch/cli.rb
144
+ - lib/syswatch/runner.rb
145
+ - lib/syswatch/version.rb
146
+ - syswatch.gemspec
147
+ homepage: https://github.com/Sology/syswatch
148
+ licenses:
149
+ - MIT
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '1.9'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 1.8.24
169
+ signing_key:
170
+ specification_version: 3
171
+ summary: Simple system monitoring tool with e-mail alerting.
172
+ test_files: []
173
+ has_rdoc: