whoopsy 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Whoopsy
2
2
 
3
- Whoppsy provides an awesome CLI Interface to Whoops Logger (http://www.whoopsapp.com/whoops-logger/).
3
+ [![Build Status](https://secure.travis-ci.org/jongillies/whoopsy.png?branch=master)](https://github.com/jongillies/whoopsy)
4
+ [![Gem Version](https://badge.fury.io/rb/whoopsy.png)](https://badge.fury.io/rb/whoopsy)
5
+ [![Dependency Status](https://gemnasium.com/jongillies/whoopsy.png)](https://gemnasium.com/jongillies/whoopsy)
6
+
7
+ Whoppsy provides an CLI Interface to Whoops Logger (http://www.whoopsapp.com/whoops-logger/).
4
8
 
5
9
  Consult the whoopsy_logger gem http://www.whoopsapp.com/whoops-logger/) for more detailed information. This Gem is a simple wrapper for that library.
6
10
 
@@ -67,8 +71,27 @@ You must specify the additional required paramters to send a message to the whoo
67
71
  Here is an example command line:
68
72
 
69
73
  ```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"
74
+ whoopsy --host whoops.example.com --port 80 --event-type "warning" --service "my script" \
75
+ --environment "development" --message "working ok today" --event-group-identifier "group7"
71
76
  ```
77
+
78
+ ## Version History
79
+
80
+ * 0.1.2
81
+ * Renamed internall Logger class to Log to avoid naming conflict with Logger::Logger
82
+ * Sent WhoopsLooger a "logger" object to get back status, will set log level to DEBUG if --debug is passed
83
+ * Noticed that if you setup a "Notification Subscription" on your WhoopsServer and you don't have email configured, you get an internal server error and the message will be lost.
84
+ * 0.1.1
85
+ * Supressed warnings for config files missing
86
+ * Noticed --details was not really working because it needs to be a data structure?
87
+ * Added CI information to the README.MD
88
+ * 0.1.0
89
+ * Initial release.
90
+
91
+ ## MongoDB Tips
92
+
93
+ 1. mongo whoops --eval "db.dropDatabase()"
94
+
72
95
  ## Contributing
73
96
 
74
97
  1. Fork it
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
- require "bundler/gem_tasks"
1
+
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'whoopsy'
4
4
 
5
- Whoopsy::Logger.new(ARGV)
5
+ Whoopsy::Log.new(ARGV)
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'whoopsy'
4
4
 
5
- Whoopsy::Logger.new(ARGV)
5
+ Whoopsy::Log.new(ARGV)
@@ -2,15 +2,19 @@ require 'whoopsy/version'
2
2
  require 'whoopsy/config'
3
3
  require 'trollop'
4
4
  require 'whoops_logger'
5
+ require 'crack'
6
+ require 'logger'
5
7
 
6
8
  module Whoopsy
7
9
 
8
10
  REQUIRED_ARGS = [:host, :port, :event_type, :service, :environment, :event_group_identifier]
9
11
 
10
- class Logger
12
+ class Log
11
13
 
12
14
  def initialize(args={})
13
15
 
16
+ @debug
17
+
14
18
  opts = Trollop::options(args) do
15
19
 
16
20
  banner "#{Whoopsy::VERSION_BANNER}\n\n#{Whoopsy::HELP_TEXT}"
@@ -34,17 +38,32 @@ module Whoopsy
34
38
  opt :environment, 'development', type: String
35
39
  opt :message, 'String to Show in Whoops Event List', type: String
36
40
  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
41
+ opt :details, 'A JSON string, or @filename which contains JSON', type: String
38
42
 
39
43
  end
40
44
 
45
+ @debug = opts[:debug_given] == true
46
+
41
47
  @config = Whoopsy::Config.new
42
48
 
43
49
  # Set the @config attributes based on the opts hash
44
50
  Whoopsy::CONFIG_OPTIONS.each do |option|
51
+ next if option == :details
45
52
  eval("@config.#{option} = \"#{opts[option]}\"") if opts["#{option}_given".to_sym]
46
53
  end
47
54
 
55
+ if opts[:details_given]
56
+ if opts[:details].to_s.start_with? '@'
57
+ @config.details = Crack::JSON.parse(File.open(opts[:details].to_s[1..-1], 'r').read)
58
+ else
59
+ @config.details = Crack::JSON.parse(opts[:details])
60
+ end
61
+ end
62
+
63
+ if @config.details == false
64
+ @config.details = "{\"error\":\"unable to parse JSON data from #{opts[:details]}\"}"
65
+ end
66
+
48
67
  check_required_args
49
68
 
50
69
  send_message
@@ -54,17 +73,27 @@ module Whoopsy
54
73
 
55
74
  def send_message
56
75
 
76
+
57
77
  WhoopsLogger.config.set(@config.config_hash)
58
78
 
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
- })
79
+ log = Logger.new(STDOUT)
80
+ @debug ? log.level = Logger::DEBUG : log.level = Logger::INFO
81
+
82
+ WhoopsLogger.config.logger = log
67
83
 
84
+ begin
85
+ WhoopsLogger.log('default::basic', {
86
+ event_type: @config.event_type,
87
+ service: @config.service,
88
+ environment: @config.environment,
89
+ message: @config.message,
90
+ event_group_identifier: @config.message,
91
+ details: @config.details
92
+ })
93
+
94
+ rescue SocketError => e
95
+ log.fatal "#{e.message}. Is it the correct hostname?"
96
+ end
68
97
  end
69
98
 
70
99
  def check_required_args
@@ -66,7 +66,7 @@ module Whoopsy
66
66
  begin
67
67
  @config.merge! YAML::load_file(file_name)
68
68
  rescue Errno::ENOENT
69
- $stderr.puts "WARNING: #{file_name} does not exist"
69
+ ; # No problem here, but catch this specific error
70
70
  end
71
71
  end
72
72
 
@@ -1,5 +1,5 @@
1
1
  module Whoopsy
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.2'
3
3
  AUTHORS = ['Jon Gillies']
4
4
  EMAIL = %w(supercoder@gmail.com)
5
5
  DESCRIPTION = %q{Log to Whoops Logger in your scripts'}
@@ -6,27 +6,64 @@ require 'yaml'
6
6
  describe 'Different Command Line Options' do
7
7
 
8
8
  it 'should fail with no options' do
9
- expect { Whoopsy::Logger.new({}) }.to raise_error
9
+ expect { Whoopsy::Log.new({}) }.to raise_error
10
10
  end
11
11
 
12
12
  it 'should succeed with required arguments' do
13
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
+ expect { Whoopsy::Log.new(args.shellsplit) }.not_to raise_error
15
15
  end
16
16
 
17
17
  it 'should fail missing --environment' do
18
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
19
+ expect { Whoopsy::Log.new(args.shellsplit) }.to raise_error
20
20
  end
21
21
 
22
22
  it 'should spit out help' do
23
23
  args = '--help'
24
- expect { Whoopsy::Logger.new(args.shellsplit) }.to raise_error
24
+ expect { Whoopsy::Log.new(args.shellsplit) }.to raise_error
25
25
  end
26
26
 
27
27
  it 'should spit out version' do
28
28
  args = '--version'
29
- expect { Whoopsy::Logger.new(args.shellsplit) }.to raise_error
29
+ expect { Whoopsy::Log.new(args.shellsplit) }.to raise_error
30
30
  end
31
31
 
32
- end
32
+ end
33
+
34
+ #describe 'Handling --details' do
35
+ #
36
+ # it 'should parse --details from the command line' do
37
+ #
38
+ # details = { first_name: 'Scooby', last_name: 'Doo', age: 7, friends: %w(Fred Daphne Velma Shaggy) }
39
+ #
40
+ # args = "--event-type \"warning\" --service \"my script\" --environment \"development\" --message \"working ok today\" --event-group-identifier \"whats this\" --details \"#{details.to_json}\""
41
+ #
42
+ # expect { Whoopsy::Log.new(args.shellsplit)}.not_to raise_error
43
+ # end
44
+ #
45
+ # #it 'should parse --details from a file' do
46
+ # #
47
+ # # file = 'spec/data/good.json'
48
+ # # args = "--event-type \"warning\" --service \"my script\" --environment \"development\" --message \"working ok today\" --event-group-identifier \"whats this\" --details @#{file}"
49
+ # #
50
+ # # expect { Whoopsy::Log.new(args.shellsplit)}.not_to raise_error
51
+ # #end
52
+ # #
53
+ # #it 'should fail if --details cannot be cracked' do
54
+ # #
55
+ # # file = 'spec/data/bad.json'
56
+ # # args = "--event-type \"warning\" --service \"my script\" --environment \"development\" --message \"working ok today\" --event-group-identifier \"whats this\" --details @#{file}"
57
+ # #
58
+ # # expect { Whoopsy::Log.new(args.shellsplit)}.not_to raise_error
59
+ # #end
60
+ # #
61
+ # #it 'should fail if --details file is empty' do
62
+ # #
63
+ # # file = 'spec/data/empty.json'
64
+ # # args = "--event-type \"warning\" --service \"my script\" --environment \"development\" --message \"working ok today\" --event-group-identifier \"whats this\" --details @#{file}"
65
+ # #
66
+ # # expect { Whoopsy::Log.new(args.shellsplit)}.not_to raise_error
67
+ # #end
68
+ #
69
+ #end
@@ -0,0 +1,12 @@
1
+
2
+ {
3
+ "ipAddress":"10.16.100.109",
4
+ "fqdn":"0050563fe4f5.devapollogrp.edu",
5
+ "id":1
6
+ },
7
+
8
+ "ipAddress":"10.16.100.193",
9
+ "fqdn":"0050563fc8d5.devapollogrp.edu",
10
+ "id":2
11
+ }
12
+ ]
File without changes
@@ -0,0 +1,12 @@
1
+ [
2
+ {
3
+ "ipAddress": "10.16.100.109",
4
+ "fqdn": "0050563fe4f5.devapollogrp.edu",
5
+ "id": 1
6
+ },
7
+ {
8
+ "ipAddress": "10.16.100.193",
9
+ "fqdn": "0050563fc8d5.devapollogrp.edu",
10
+ "id": 2
11
+ }
12
+ ]
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.1.0
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-31 00:00:00.000000000 Z
12
+ date: 2013-08-02 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: rspec
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +91,22 @@ dependencies:
75
91
  - - ! '>='
76
92
  - !ruby/object:Gem::Version
77
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: crack
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
78
110
  description: Log to Whoops Logger in your scripts'
79
111
  email:
80
112
  - supercoder@gmail.com
@@ -92,6 +124,9 @@ files:
92
124
  - lib/whoopsy/version.rb
93
125
  - lib/whoopsy.rb
94
126
  - spec/cli_spec.rb
127
+ - spec/data/bad.json
128
+ - spec/data/empty.json
129
+ - spec/data/good.json
95
130
  - spec/spec_helper.rb
96
131
  - README.md
97
132
  - LICENSE.txt