eye-patch 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a904d9ab31e2dc78e874ff356a9c63b35da0d41
4
+ data.tar.gz: 40bc46108198bd4a9f430e646a3a7d7c9d8df63f
5
+ SHA512:
6
+ metadata.gz: 32a289481244b7276564d46e4b035d8a214a8fc6873238ee0ecb8704110808b8437662028d2efa03b5bd9f2cfd5cd246e0c64186157ff31e2daf6e1489d77068
7
+ data.tar.gz: 577b74325ae1560c616c92b9af23720d50d9ac9a1ea8d7a5b77656e58ee4dcafc0a7eb76ad16626202c6ea82f05d889668ec8dc06c4b26c1115ddb388a703b12
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .ruby-version
6
+ .ruby-gemset
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eye-patch.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Table XI
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,29 @@
1
+ # Eye::Patch
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'eye-patch'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install eye-patch
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ task default: :test
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.pattern = "test/**/*_test.rb"
9
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib]))
4
+ require "eye/patch"
5
+
6
+ Eye::Cli.start
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "eye/patch/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "eye-patch"
8
+ spec.version = Eye::Patch::VERSION
9
+ spec.authors = ["Andrew Horner"]
10
+ spec.email = ["andrew@tablexi.com"]
11
+ spec.description = "Easily load your eye configuration from a YAML file."
12
+ spec.summary = %q[
13
+ Eye::Patch abstracts out the Eye DSL to allow you to load your configuration
14
+ from a structured YAML file, rather than relying on Eye's built-in DSL.
15
+ ]
16
+ spec.homepage = "https://github.com/tablexi/eye-patch"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files`.split($/)
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^test/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+
27
+ spec.add_dependency "eye"
28
+ spec.add_dependency "chronic_duration"
29
+ end
@@ -0,0 +1,22 @@
1
+ require "celluloid"
2
+ require "aws/ses"
3
+
4
+ class Eye::Notify::SES < Eye::Notify::Custom
5
+
6
+ param :access_key_id, String, true
7
+ param :secret_access_key, String, true
8
+ param :from, String, true
9
+
10
+ def execute
11
+ AWS::SES::Base.new(
12
+ access_key_id: access_key_id,
13
+ secret_access_key: secret_access_key ).send_email(message)
14
+ end
15
+
16
+ def message
17
+ { to: contact,
18
+ from: from,
19
+ subject: message_subject,
20
+ text_body: message_body }
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ require "eye"
2
+
3
+ module Eye::Patch
4
+
5
+ require "eye/patch/settings"
6
+ require "eye/patch/config"
7
+ require "eye/patch/application"
8
+ require "eye/patch/version"
9
+
10
+ def self.parse(filename)
11
+ settings = Eye::Patch::Settings.new(filename)
12
+
13
+ config = Eye::Config.new(
14
+ Eye::Patch::Config.new(settings),
15
+ Eye::Patch::Application.new(settings))
16
+ config.validate!
17
+
18
+ config
19
+ end
20
+ end
21
+
22
+ module Eye::Controller::Load
23
+
24
+ private
25
+
26
+ def parse_config(filename)
27
+ Eye::Patch.parse(filename)
28
+ end
29
+ end
@@ -0,0 +1,64 @@
1
+ class Eye::Patch::Application < Hash
2
+
3
+ def initialize(settings)
4
+ super()
5
+ self[settings[:name].to_s] = parse(settings)
6
+ end
7
+
8
+ private
9
+
10
+ def parse(settings)
11
+ @config = {}
12
+
13
+ parse_application(settings)
14
+ parse_notifications(settings)
15
+ parse_triggers(settings)
16
+ parse_processes(settings)
17
+
18
+ @config
19
+ end
20
+
21
+ def parse_application(settings)
22
+ @config.merge!(settings[:application] || {})
23
+ end
24
+
25
+ def parse_notifications(settings)
26
+ @config[:notify] = {}
27
+
28
+ Array(settings[:notifications]).each do |monitor|
29
+ @config[:notify][monitor[:name].to_s] = monitor[:level].to_sym
30
+ end
31
+ end
32
+
33
+ def parse_triggers(settings)
34
+ @config[:triggers] = {}
35
+
36
+ Array(settings[:triggers]).each do |item|
37
+ trigger_data = Eye::Trigger.name_and_class(item[:name].to_sym)
38
+ @config[:triggers][trigger_data[:name]] = item[:config].merge(type: trigger_data[:type])
39
+ end
40
+ end
41
+
42
+ def parse_processes(settings)
43
+ @config[:groups] = {}
44
+
45
+ Array(settings[:processes]).group_by{ |item| item[:group] }.each do |group_name, items|
46
+ if group_name
47
+ parse_group(group_name, items)
48
+ else
49
+ @config[:processes] = parse_process_list(items)
50
+ end
51
+ end
52
+ end
53
+
54
+ def parse_group(name, processes)
55
+ @config[:groups][name.to_s] = {}
56
+ @config[:groups][name.to_s][:processes] = parse_process_list(processes)
57
+ end
58
+
59
+ def parse_process_list(processes)
60
+ processes.each_with_object({}) do |process, process_map|
61
+ process_map[process[:name].to_s] = process[:config]
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,35 @@
1
+ class Eye::Patch::Config < Hash
2
+
3
+ def initialize(settings)
4
+ super()
5
+ self.merge!(parse(settings))
6
+ end
7
+
8
+ private
9
+
10
+ def parse(settings)
11
+ return @config if @config
12
+ @config = {}
13
+
14
+ parse_config(settings)
15
+ parse_contacts(settings)
16
+
17
+ @config
18
+ end
19
+
20
+ def parse_config(settings)
21
+ @config.merge!(settings[:config] || {})
22
+ end
23
+
24
+ def parse_contacts(settings)
25
+ @config[:contacts] = {}
26
+ Array(settings[:notifications]).each do |notify|
27
+ @config[notify[:type].to_sym] = notify[:config]
28
+ @config[:contacts][notify[:name].to_s] = {
29
+ name: notify[:name].to_s,
30
+ type: notify[:type].to_sym,
31
+ contact: notify[:contact].to_s,
32
+ opts: {} }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,34 @@
1
+ require "chronic_duration"
2
+
3
+ class Eye::Patch::Settings
4
+
5
+ def initialize(filename)
6
+ @settings = YAML.load(File.open(filename))
7
+ end
8
+
9
+ def [](value)
10
+ parsed[value]
11
+ end
12
+
13
+ private
14
+
15
+ def parsed
16
+ @parsed ||= parse(@settings)
17
+ end
18
+
19
+ def parse(item)
20
+ case item
21
+ when Hash
22
+ item.each_with_object({}) do |(key, val), result|
23
+ result[key.to_sym] = parse(val)
24
+ end
25
+ when Array
26
+ item.map { |val| parse(val) }
27
+ when String
28
+ # Assume that we should parse any time-like values
29
+ item =~ /\b(hour|second|minute)s?\b/ ? ChronicDuration.parse(item) : item
30
+ else
31
+ item
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Eye
2
+ module Patch
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eye-patch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Horner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: eye
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: chronic_duration
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Easily load your eye configuration from a YAML file.
70
+ email:
71
+ - andrew@tablexi.com
72
+ executables:
73
+ - eye-patch
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/eye-patch
83
+ - eye-patch.gemspec
84
+ - lib/eye/notify/ses.rb
85
+ - lib/eye/patch.rb
86
+ - lib/eye/patch/application.rb
87
+ - lib/eye/patch/config.rb
88
+ - lib/eye/patch/settings.rb
89
+ - lib/eye/patch/version.rb
90
+ - test/test_helper.rb
91
+ homepage: https://github.com/tablexi/eye-patch
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.1.11
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Eye::Patch abstracts out the Eye DSL to allow you to load your configuration
115
+ from a structured YAML file, rather than relying on Eye's built-in DSL.
116
+ test_files:
117
+ - test/test_helper.rb