whoopsy 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Whoopsy
2
2
 
3
- TODO: Write a gem description
3
+ Whoppsy provides an awesome CLI Interface to Whoops Logger (http://www.whoopsapp.com/whoops-logger/).
4
+
5
+ Consult the whoopsy_logger gem http://www.whoopsapp.com/whoops-logger/) for more detailed information. This Gem is a simple wrapper for that library.
4
6
 
5
7
  ## Installation
6
8
 
@@ -18,8 +20,55 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ Make sure you have installed your whoops_server first! http://www.whoopsapp.com/whoops-server/
24
+
25
+ Once installed the minimum options to connect to the whoops_server are:
26
+
27
+ * --host fqdn
28
+ * --port 80
29
+
30
+ These options can be specified in a configuration file or on the command line. The configuration files supported in order of priority are:
31
+
32
+ * /etc/whoopsy.yml
33
+ * $HOME/.whoopsy.yml
34
+ * $WHOOPSY_CONFIG (full path to file)
35
+
36
+ The following connection parameters are supported:
37
+
38
+ * --host
39
+ * --http_open_timeout
40
+ * --http_read_timeout
41
+ * --port
42
+ * --protocol
43
+ * --proxy_host
44
+ * --proxy_pass
45
+ * --proxy_port
46
+ * --proxy_user
47
+ * --secure
48
+
49
+ (These options come directly from the whoopsy_logger gem http://www.whoopsapp.com/whoops-logger/)
50
+
51
+ A sample config file might look like:
52
+ ```yaml
53
+ :host: localhost
54
+ :port: 3000
55
+ ```
56
+
57
+ Note that the command line options will override any options specified in the configuration files.
58
+
59
+ You must specify the additional required paramters to send a message to the whoops_server:
60
+
61
+ * --event-type
62
+ * --service
63
+ * --environment
64
+ * --message
65
+ * --event-group-identifier
66
+
67
+ Here is an example command line:
22
68
 
69
+ ```bash
70
+ whoopsy --host whoops.example.com --port 80 --event-type "warning" --service "my script" --environment "development" --message "working ok today" --event-group-identifier "group7"
71
+ ```
23
72
  ## Contributing
24
73
 
25
74
  1. Fork it
data/bin/whoopsy ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'whoopsy'
4
+
5
+ Whoopsy::Logger.new(ARGV)
data/bin/whoopsy.rb ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'whoopsy'
4
+
5
+ Whoopsy::Logger.new(ARGV)
@@ -0,0 +1,74 @@
1
+ require 'yaml'
2
+ require 'logger'
3
+
4
+ module Whoopsy
5
+ CONFIG_OPTIONS = [:host,
6
+ :http_open_timeout,
7
+ :http_read_timeout,
8
+ :port,
9
+ :protocol,
10
+ :proxy_host,
11
+ :proxy_pass,
12
+ :proxy_port,
13
+ :proxy_user,
14
+ :secure,
15
+ :event_type,
16
+ :service,
17
+ :environment,
18
+ :message,
19
+ :event_group_identifier,
20
+ :details]
21
+
22
+ class Config
23
+
24
+ CONFIG_OPTIONS.each do |var|
25
+ class_eval { attr_accessor var }
26
+ end
27
+
28
+ def initialize
29
+
30
+ @config = {}
31
+
32
+ @file_name = 'whoopsy.yml'
33
+ @global_config_file = "/etc/#{@file_name}"
34
+ @local_config_file = "#{File.join(ENV['HOME'], ".#{@file_name}")}"
35
+ @environment_file = ENV['WHOOPSY_CONFIG']
36
+
37
+ # Load in order of priority
38
+ load_file @global_config_file
39
+ load_file @local_config_file
40
+ load_file @environment_file if @environment_file
41
+
42
+ CONFIG_OPTIONS.each do |var|
43
+ eval("self.#{var} = \"#{@config[var]}\"")
44
+ end
45
+
46
+ end
47
+
48
+ # Return a hash of config options for the whoops_logger, making sure the "type" is correct
49
+ def config_hash
50
+ h = {}
51
+
52
+ [:host, :protocol, :proxy_host, :proxy_pass, :proxy_port, :proxy_user, :secure].each do |var|
53
+ eval("h[:#{var}] = @#{var} unless @#{var}.empty?")
54
+ end
55
+
56
+ [:http_open_timeout, :http_read_timeout, :port].each do |var|
57
+ eval("h[:#{var}] = @#{var}.to_i if @#{var}.to_i > 0")
58
+ end
59
+
60
+ h
61
+ end
62
+
63
+ private
64
+
65
+ def load_file(file_name)
66
+ begin
67
+ @config.merge! YAML::load_file(file_name)
68
+ rescue Errno::ENOENT
69
+ $stderr.puts "WARNING: #{file_name} does not exist"
70
+ end
71
+ end
72
+
73
+ end
74
+ end
@@ -1,3 +1,10 @@
1
1
  module Whoopsy
2
- VERSION = "0.0.1"
3
- end
2
+ VERSION = '0.1.0'
3
+ AUTHORS = ['Jon Gillies']
4
+ EMAIL = %w(supercoder@gmail.com)
5
+ DESCRIPTION = %q{Log to Whoops Logger in your scripts'}
6
+ SUMMARY = %q{Awesome CLI Interface to Whoops Logger (http://www.whoopsapp.com/whoops-logger/)}
7
+ HOMEPAGE = 'https://github.com/jongillies/whoopsy'
8
+ VERSION_BANNER = "#{self.name} #{self::VERSION} #{self::SUMMARY} (c) 2013 #{self::AUTHORS.join(', ')}"
9
+ HELP_TEXT = "Use this program to send messages to your Whoops logger.\n\nUsage:"
10
+ end
data/lib/whoopsy.rb CHANGED
@@ -1,21 +1,80 @@
1
1
  require 'whoopsy/version'
2
+ require 'whoopsy/config'
2
3
  require 'trollop'
3
- require 'shellwords'
4
+ require 'whoops_logger'
4
5
 
5
6
  module Whoopsy
6
- class GemName
7
- attr_reader :cli_arg
8
- def initialize(args={}, version_text='', banner_text='')
7
+
8
+ REQUIRED_ARGS = [:host, :port, :event_type, :service, :environment, :event_group_identifier]
9
+
10
+ class Logger
11
+
12
+ def initialize(args={})
13
+
9
14
  opts = Trollop::options(args) do
10
- banner = banner_text
11
- version = version_text
15
+
16
+ banner "#{Whoopsy::VERSION_BANNER}\n\n#{Whoopsy::HELP_TEXT}"
17
+ version Whoopsy::VERSION_BANNER
12
18
  opt :verbose, 'Verbose output.', short: 'v'
13
19
  opt :debug, 'Display additional debugging information.'
20
+
21
+ opt :host, 'Whoops Logger hostname', type: String
22
+ opt :http_open_timeout, 'HTTP open timeout', type: Integer
23
+ opt :http_read_timeout, 'HTTP read timeout', type: Integer
24
+ opt :port, 'Whoops Logger port', type: Integer
25
+ opt :protocol, 'Whoops Logger Protocol', type: String
26
+ opt :proxy_host, 'Proxy Host', type: String
27
+ opt :proxy_pass, 'Proxy Password', type: String
28
+ opt :proxy_port, 'Proxy Port', type: Integer
29
+ opt :proxy_user, 'Proxy Username', type: String
30
+ opt :secure, 'Secure?'
31
+
32
+ opt :event_type, 'your_event_type', type: String
33
+ opt :service, 'my_service_name', type: String
34
+ opt :environment, 'development', type: String
35
+ opt :message, 'String to Show in Whoops Event List', type: String
36
+ opt :event_group_identifier, 'String used to assign related events to a group', type: String
37
+ opt :details, 'A string, hash, or array of arbitrary data', type: String
38
+
39
+ end
40
+
41
+ @config = Whoopsy::Config.new
42
+
43
+ # Set the @config attributes based on the opts hash
44
+ Whoopsy::CONFIG_OPTIONS.each do |option|
45
+ eval("@config.#{option} = \"#{opts[option]}\"") if opts["#{option}_given".to_sym]
14
46
  end
15
- unless @cli_arg = args[0]
16
- Trollop::die "ERROR: You must specify something on the command line."
47
+
48
+ check_required_args
49
+
50
+ send_message
51
+ end
52
+
53
+ private
54
+
55
+ def send_message
56
+
57
+ WhoopsLogger.config.set(@config.config_hash)
58
+
59
+ WhoopsLogger.log('default::basic', {
60
+ event_type: @config.event_type,
61
+ service: @config.service,
62
+ environment: @config.environment,
63
+ message: @config.message,
64
+ event_group_identifier: @config.message,
65
+ details: @config.details
66
+ })
67
+
68
+ end
69
+
70
+ def check_required_args
71
+ Whoopsy::REQUIRED_ARGS.each do |arg|
72
+ value = eval("@config.#{arg}.to_s.empty?") # This will render a string, if value nil will render ""
73
+ Trollop::die "Must have the following parameters: [#{Whoopsy::REQUIRED_ARGS.join(', ')}], #{arg} is missing." if value
17
74
  end
18
- opts
19
75
  end
76
+
20
77
  end
21
78
  end
79
+
80
+
data/spec/cli_spec.rb CHANGED
@@ -4,12 +4,29 @@ require 'shellwords'
4
4
  require 'yaml'
5
5
 
6
6
  describe 'Different Command Line Options' do
7
+
7
8
  it 'should fail with no options' do
8
- expect { Whoopsy::GemName.new({}) }.to raise_error
9
+ expect { Whoopsy::Logger.new({}) }.to raise_error
9
10
  end
10
- #
11
- it 'should succeed with minimum arguments' do
12
- args = 'my-argument'
13
- expect { Whoopsy::GemName.new(args.shellsplit, "banner", "version") }.not_to raise_error
11
+
12
+ it 'should succeed with required arguments' do
13
+ args = "--event-type 'warning' --service 'my script' --environment 'development' --message 'working ok today' --event-group-identifier 'whats this'"
14
+ expect { Whoopsy::Logger.new(args.shellsplit) }.not_to raise_error
14
15
  end
15
- end
16
+
17
+ it 'should fail missing --environment' do
18
+ args = "--event-type 'warning' --service 'my script' --message 'working ok today' --event-group-identifier 'whats this'"
19
+ expect { Whoopsy::Logger.new(args.shellsplit) }.to raise_error
20
+ end
21
+
22
+ it 'should spit out help' do
23
+ args = '--help'
24
+ expect { Whoopsy::Logger.new(args.shellsplit) }.to raise_error
25
+ end
26
+
27
+ it 'should spit out version' do
28
+ args = '--version'
29
+ expect { Whoopsy::Logger.new(args.shellsplit) }.to raise_error
30
+ end
31
+
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whoopsy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-29 00:00:00.000000000 Z
12
+ date: 2013-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: ruby-lint
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: trollop
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -43,21 +59,41 @@ dependencies:
43
59
  - - ! '>='
44
60
  - !ruby/object:Gem::Version
45
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: whoops_logger
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
46
78
  description: Log to Whoops Logger in your scripts'
47
79
  email:
48
80
  - supercoder@gmail.com
49
- executables: []
81
+ executables:
82
+ - whoopsy
83
+ - whoopsy.rb
50
84
  extensions: []
51
85
  extra_rdoc_files: []
52
86
  files:
53
87
  - Rakefile
54
88
  - Gemfile
89
+ - bin/whoopsy
90
+ - bin/whoopsy.rb
91
+ - lib/whoopsy/config.rb
55
92
  - lib/whoopsy/version.rb
56
93
  - lib/whoopsy.rb
57
94
  - spec/cli_spec.rb
58
95
  - spec/spec_helper.rb
59
96
  - README.md
60
- - LICENSE
61
97
  - LICENSE.txt
62
98
  homepage: https://github.com/jongillies/whoopsy
63
99
  licenses: []
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2013 jongillies
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- 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, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.