appmonitor 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/appmonitor/event_notification.rb +1 -1
- data/lib/appmonitor/event_notifier.rb +31 -16
- data/lib/appmonitor/github/issue.rb +58 -0
- data/lib/appmonitor/github_api.rb +54 -0
- data/lib/appmonitor/rake_patch.rb +1 -1
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6debb44002babbb29bde93485cbd0cad0a85f31
|
4
|
+
data.tar.gz: 03221a29f484f97d17d82fb1ac94de839437fc57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7154004a16f786a5823accb95dab8e3f27e97777267623255176e7022e7ff818f0bd65e840caf066f413ef0b32a1085570b0bcb2c172252bb294af92e83b876
|
7
|
+
data.tar.gz: ef493748f89fbfd480d33553755e2d2aaca05cd49651eb0f692ce40280acb9d8201d2be33e585e503f9fb2635360ab69daa576705faeca9d987b4895f335d711
|
@@ -19,7 +19,7 @@ module AppMonitor
|
|
19
19
|
rake_called_name = options[:rake_command_line].split(":", 2)
|
20
20
|
rake_namespace = rake_called_name.first
|
21
21
|
{method: options[:rake_command_line], time: Time.now.to_i.to_s, message: exception.message.inspect, stack_trace:
|
22
|
-
|
22
|
+
exception.backtrace.join("\n"), klass: rake_namespace, environment: Rails.env || ''}
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
@@ -3,6 +3,7 @@ require 'net/http'
|
|
3
3
|
require 'active_support/core_ext'
|
4
4
|
require 'action_dispatch'
|
5
5
|
require 'appmonitor/event_notification'
|
6
|
+
require 'appmonitor/github_api'
|
6
7
|
|
7
8
|
module AppMonitor
|
8
9
|
class EventNotifier
|
@@ -13,10 +14,14 @@ module AppMonitor
|
|
13
14
|
@app = app
|
14
15
|
configure
|
15
16
|
@config[:ignore_exceptions] ||= self.class.default_ignore_exceptions
|
17
|
+
@github = GithubApi.new(token: @config[:github_oauth_token], repo: @config[:github_repo_url]) if @config[:github_oauth_token] && @config[:github_repo_url]
|
18
|
+
|
16
19
|
end
|
17
20
|
|
18
21
|
def configure(opts = {})
|
19
22
|
@config = {
|
23
|
+
github_oauth_token: '',
|
24
|
+
github_repo_url: '',
|
20
25
|
api_key: '',
|
21
26
|
project_id: '',
|
22
27
|
monitoring: {development: '', staging: '', production: ''}
|
@@ -62,19 +67,21 @@ module AppMonitor
|
|
62
67
|
end
|
63
68
|
|
64
69
|
def send_exception(exception)
|
70
|
+
type = 'Error'
|
65
71
|
unless ignored_exception(@config[:ignore_exceptions], exception)
|
66
72
|
event = EventNotification.build_exception_hash(exception, @request)
|
67
|
-
@event = event.
|
68
|
-
notify_on_event(
|
73
|
+
@event = event.merge(type: type)
|
74
|
+
notify_on_event(type)
|
69
75
|
end
|
70
76
|
end
|
71
77
|
|
72
78
|
def send_rake_event(exception, options = {})
|
79
|
+
type = 'RakeError'
|
73
80
|
configure
|
74
|
-
unless (ignored_exception(@config[:ignore_exceptions], exception) ||
|
81
|
+
unless (ignored_exception(@config[:ignore_exceptions], exception) || !@config[:monitoring]["#{Rails.env.to_s.downcase}"])
|
75
82
|
event = EventNotification.build_rake_event(exception, options)
|
76
|
-
@event = event.
|
77
|
-
notify_on_event(
|
83
|
+
@event = event.merge(type: type)
|
84
|
+
notify_on_event(type)
|
78
85
|
end
|
79
86
|
end
|
80
87
|
|
@@ -84,6 +91,20 @@ module AppMonitor
|
|
84
91
|
end
|
85
92
|
|
86
93
|
def notify_on_event(type)
|
94
|
+
response = send_request(type)
|
95
|
+
Rails.logger.debug ("Appmonitor: Event has been sent")
|
96
|
+
|
97
|
+
unless response.kind_of? Net::HTTPSuccess
|
98
|
+
Rails.logger.warn('Appmonitor WARNING: Something went wrong, please check your config')
|
99
|
+
Rails.logger.warn("AppMonitor WARNING: Response ''#{response.code}: #{response.message}''")
|
100
|
+
puts 'Appmonitor WARNING: Something went wrong, please check your config'
|
101
|
+
puts "AppMonitor WARNING: Response #{response.inspect}"
|
102
|
+
end
|
103
|
+
|
104
|
+
send_to_github if @github
|
105
|
+
end
|
106
|
+
|
107
|
+
def send_request(type)
|
87
108
|
uri = URI.parse(API_MESSAGE_URL)
|
88
109
|
https = Net::HTTP.new(uri.host, uri.port)
|
89
110
|
https.use_ssl = false
|
@@ -92,19 +113,13 @@ module AppMonitor
|
|
92
113
|
'appm_projectId' => @config[:project_id],
|
93
114
|
'appm_type' => type}
|
94
115
|
)
|
116
|
+
request.body = @event.to_json
|
117
|
+
https.request(request)
|
95
118
|
|
96
|
-
|
97
|
-
response = https.request(request)
|
98
|
-
|
99
|
-
Rails.logger.debug ("Appmonitor: Event has been sent")
|
100
|
-
puts 'Appmonitor: Event has been sent'
|
119
|
+
end
|
101
120
|
|
102
|
-
|
103
|
-
|
104
|
-
Rails.logger.warn("AppMonitor WARNING: Response ''#{response.code}: #{response.message}''")
|
105
|
-
puts 'Appmonitor WARNING: Something went wrong, please check your config'
|
106
|
-
puts "AppMonitor WARNING: Response #{response.inspect}"
|
107
|
-
end
|
121
|
+
def send_to_github
|
122
|
+
@github.handle_event(@event)
|
108
123
|
end
|
109
124
|
|
110
125
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module AppMonitor
|
2
|
+
module Github
|
3
|
+
class Issue
|
4
|
+
|
5
|
+
RUBY_OBJECT_REGEX = /\#\<.*\>/
|
6
|
+
|
7
|
+
def initialize(event)
|
8
|
+
@event=event
|
9
|
+
end
|
10
|
+
|
11
|
+
def title
|
12
|
+
"#{@event[:klass]}/#{@event[:method]}: #{@event[:message]}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def type
|
16
|
+
@event[:type]
|
17
|
+
end
|
18
|
+
|
19
|
+
def error_request_details
|
20
|
+
content = "**URL**: #{@event[:url]}\n"
|
21
|
+
content << "**Parameters**: #{@event[:params]}\n"
|
22
|
+
content << "**IP address**: #{@event[:ip_address]}\n"
|
23
|
+
content << "**Session:** #{@event[:session]}\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
def body
|
27
|
+
content = "### First occurrence of this #{@event[:type]}\n"
|
28
|
+
content << "**Action:** #{@event[:klass]}/#{@event[:method]}\n"
|
29
|
+
content << "**Message**: #{@event[:message]}\n"
|
30
|
+
content << "**Environment:** #{@event[:environment]}\n"
|
31
|
+
content << "**Timestamp:** #{@event[:time]}\n"
|
32
|
+
content << "**Human time:** #{Time.at(@event[:time].to_i).strftime("Occurred on %d/%m/%Y at %H:%M:%S")}\n"
|
33
|
+
if type == 'Error'
|
34
|
+
content << error_request_details
|
35
|
+
end
|
36
|
+
content << "**Stacktrace:** \n```ruby\n#{@event[:stack_trace]}\n```"
|
37
|
+
end
|
38
|
+
|
39
|
+
def additional_occurrence_comment
|
40
|
+
content = "### Another occurrence of this #{@event[:type]}\n"
|
41
|
+
content << "**Environment:** #{@event[:environment]}\n"
|
42
|
+
content << "**Timestamp:** #{@event[:time]}\n"
|
43
|
+
content << "**Human time:** #{Time.at(@event[:time].to_i).strftime("Occurred on %d/%m/%Y at %H:%M:%S")}\n"
|
44
|
+
if type == 'Error'
|
45
|
+
content << error_request_details
|
46
|
+
end
|
47
|
+
content
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.compare_issues(existing, new)
|
51
|
+
existing_title = existing.title.gsub(RUBY_OBJECT_REGEX, '')
|
52
|
+
new_title = new.title.gsub(RUBY_OBJECT_REGEX, '')
|
53
|
+
existing_title == new_title
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
require 'appmonitor/github/issue'
|
3
|
+
|
4
|
+
module AppMonitor
|
5
|
+
class GithubApi
|
6
|
+
attr_accessor :client, :repo
|
7
|
+
|
8
|
+
GITHUB_API_ISSUED_CLOSED_STATE = 'closed'
|
9
|
+
|
10
|
+
def initialize(args)
|
11
|
+
@client = Octokit::Client.new(:access_token => args[:token])
|
12
|
+
@repo = args[:repo]
|
13
|
+
end
|
14
|
+
|
15
|
+
def issues
|
16
|
+
@client.issues(@repo, state: 'all')
|
17
|
+
end
|
18
|
+
|
19
|
+
def handle_event(event)
|
20
|
+
begin
|
21
|
+
@issue = AppMonitor::Github::Issue.new(event)
|
22
|
+
existing_issue = find_issue(issues)
|
23
|
+
if existing_issue
|
24
|
+
reopen_issue(existing_issue[:number])
|
25
|
+
else
|
26
|
+
create_issue
|
27
|
+
end
|
28
|
+
rescue Octokit::Unauthorized
|
29
|
+
Rails.logger.warn('Appmonitor WARNING: Wrong Github credentials')
|
30
|
+
puts ('Appmonitor WARNING: Wrong Github credentials')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_issue(issues)
|
35
|
+
issues.select { |x| AppMonitor::Github::Issue.compare_issues(x, @issue) }.first
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_issue
|
39
|
+
|
40
|
+
@client.create_issue(@repo, @issue.title, @issue.body, labels: ['bug', @issue.type])
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def reopen_issue(number)
|
45
|
+
@client.reopen_issue(@repo, number)
|
46
|
+
add_comment_to_an_issue(number, @issue.additional_occurrence_comment)
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_comment_to_an_issue(number, comment)
|
50
|
+
@client.add_comment(@repo, number, comment)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -13,7 +13,7 @@ module AppMonitor
|
|
13
13
|
def display_error_message_with_notifications(ex)
|
14
14
|
display_error_message_without_notifications(ex)
|
15
15
|
en = AppMonitor::EventNotifier.new(nil)
|
16
|
-
en.send_rake_event(ex
|
16
|
+
en.send_rake_event(ex, :rake_command_line => reconstruct_command_line)
|
17
17
|
end
|
18
18
|
|
19
19
|
def reconstruct_command_line
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appmonitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Team Gappers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -38,7 +38,21 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: octokit
|
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
|
+
description: AppMonitor agent for ruby language. We provide GIthub Integration - issues.
|
42
56
|
email: gappers-tip-fiit@googlegroups.com
|
43
57
|
executables: []
|
44
58
|
extensions: []
|
@@ -47,6 +61,8 @@ files:
|
|
47
61
|
- lib/appmonitor.rb
|
48
62
|
- lib/appmonitor/event_notification.rb
|
49
63
|
- lib/appmonitor/event_notifier.rb
|
64
|
+
- lib/appmonitor/github/issue.rb
|
65
|
+
- lib/appmonitor/github_api.rb
|
50
66
|
- lib/appmonitor/rake_patch.rb
|
51
67
|
homepage: http://rubygems.org/gems/appmonitor
|
52
68
|
licenses:
|
@@ -68,9 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
84
|
version: '0'
|
69
85
|
requirements: []
|
70
86
|
rubyforge_project:
|
71
|
-
rubygems_version: 2.
|
87
|
+
rubygems_version: 2.4.5
|
72
88
|
signing_key:
|
73
89
|
specification_version: 4
|
74
90
|
summary: AppMonitor agent for ruby language
|
75
91
|
test_files: []
|
76
|
-
has_rdoc:
|