critimonlib-ruby 1.0.0.1
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 +7 -0
- data/critimonlib-ruby.gemspec +16 -0
- data/lib/critimonlib-ruby.rb +292 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f0fee2ca87a29ceee19e104cf0b9ddb5412b2b4783c2deae6c63d79fa4551371
|
4
|
+
data.tar.gz: e9b5e2cd721e6ec0745bc949920b04eaf88217e8c4f65b7a400d75ffc2ae8d73
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29ba373ab150d4458cab0baf954e11d82e1552ab5c939187f3dc3f1a1fee182ec1dc8b79d5bc123d9a81adbd5a811007db1cc218c433792673ccd573661906f3
|
7
|
+
data.tar.gz: f26d2211393d81e0a0fef6eb3e1350a373c916d6e4a568be0265a163600c05440672d307a276721b33a92608eccb519f28096b45d2be3d171d4b3f372fdc536e
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{critimonlib-ruby}
|
5
|
+
s.version = "1.0.0.1"
|
6
|
+
s.date = %q{2019-11-02}
|
7
|
+
s.summary = %q{CritiMon Library for Ruby}
|
8
|
+
s.authors = "Chris Board - Boardies IT Solutions"
|
9
|
+
s.homepage = "https://critimon.com"
|
10
|
+
s.license = "Apache-2.0"
|
11
|
+
s.files = [
|
12
|
+
"critimonlib-ruby.gemspec",
|
13
|
+
"lib/critimonlib-ruby.rb"
|
14
|
+
]
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
end
|
@@ -0,0 +1,292 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
require 'uri'
|
6
|
+
require 'json'
|
7
|
+
require 'os'
|
8
|
+
module CritiMonLib
|
9
|
+
module Severity
|
10
|
+
Low = 'Low'
|
11
|
+
Medium = 'Medium'
|
12
|
+
Major = 'Major'
|
13
|
+
Critical = 'Critical'
|
14
|
+
end
|
15
|
+
|
16
|
+
class CritiMon
|
17
|
+
|
18
|
+
@@critimon_initialised = false
|
19
|
+
@@critimon_url = 'https://staging-engine.critimon.com/'
|
20
|
+
@@session_id = ''
|
21
|
+
@@do_lb = ''
|
22
|
+
@@api_key = ''
|
23
|
+
@@app_id = ''
|
24
|
+
@@app_version = ''
|
25
|
+
@@pending_crashes = []
|
26
|
+
@@device_id = ''
|
27
|
+
|
28
|
+
def self.critimon_initialised
|
29
|
+
@@critimon_initialised
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.critimon_initialised=(value)
|
33
|
+
@@critimon_initialised = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.critimon_url
|
37
|
+
@@critimon_url
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.critimon_url=(value)
|
41
|
+
@@critimon_url = value
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.session_id
|
45
|
+
@@session_id
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.session_id=(value)
|
49
|
+
@@session_id = value
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.do_lb
|
53
|
+
@@do_lb
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.do_lb=(value)
|
57
|
+
@@do_lb = value
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.api_key
|
61
|
+
@@api_key
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.api_key=(value)
|
65
|
+
@@api_key = value
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.app_id
|
69
|
+
@@app_id
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.app_id=(value)
|
73
|
+
@@app_id = value
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.app_version
|
77
|
+
@@app_version
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.app_version=(value)
|
81
|
+
@@app_version = value
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.device_id
|
85
|
+
@@device_id
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.device_id=(value)
|
89
|
+
@@device_id = value
|
90
|
+
end
|
91
|
+
|
92
|
+
def initialise(api_key, app_id, app_version)
|
93
|
+
|
94
|
+
self.class.api_key = api_key
|
95
|
+
self.class.app_id = app_id
|
96
|
+
self.class.app_version = app_version
|
97
|
+
|
98
|
+
if File.file?('critimon.tmp')
|
99
|
+
file = File.open('critimon.tmp')
|
100
|
+
@@device_id = file.read
|
101
|
+
file.close
|
102
|
+
else
|
103
|
+
file = File.open('critimon.tmp', 'w')
|
104
|
+
o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten
|
105
|
+
@@device_id = (0...10).map { o[rand(o.length)] }.join
|
106
|
+
file.write(@@device_id)
|
107
|
+
file.close
|
108
|
+
end
|
109
|
+
|
110
|
+
post_url = self.class.critimon_url + 'initialise'
|
111
|
+
|
112
|
+
uri = URI.parse(post_url)
|
113
|
+
data = {
|
114
|
+
ApplicationID: app_id,
|
115
|
+
DeviceID: @@device_id,
|
116
|
+
AppVersion: app_version
|
117
|
+
}
|
118
|
+
|
119
|
+
headers = {
|
120
|
+
"authorisation-token": api_key
|
121
|
+
}
|
122
|
+
|
123
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
124
|
+
if uri.port == 443
|
125
|
+
http.use_ssl = true
|
126
|
+
end
|
127
|
+
|
128
|
+
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
129
|
+
request.set_form_data(data)
|
130
|
+
|
131
|
+
response = http.request(request)
|
132
|
+
|
133
|
+
if response.code == '200'
|
134
|
+
|
135
|
+
json = JSON.parse(response.body)
|
136
|
+
|
137
|
+
if json['result'] == 0
|
138
|
+
self.class.critimon_initialised = true
|
139
|
+
cookies = response.header['set-cookie'].split(',')
|
140
|
+
|
141
|
+
cookies.each do |item|
|
142
|
+
|
143
|
+
cookie = item.split('=')
|
144
|
+
|
145
|
+
if cookie[0].strip == 'SESSIONID'
|
146
|
+
session_data = cookie[1].strip.split(';')
|
147
|
+
self.class.session_id = session_data[0].strip
|
148
|
+
elsif cookie[0].strip == 'DO-LB'
|
149
|
+
dolb_data = cookie[1].strip.split(';')
|
150
|
+
self.class.do_lb = dolb_data[0].strip
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# Process anything in the queue
|
155
|
+
@@pending_crashes.each do |d|
|
156
|
+
sendCrashRequest(d)
|
157
|
+
end
|
158
|
+
@@pending_crashes.clear
|
159
|
+
elsif json['result'] == 5
|
160
|
+
sleep(1)
|
161
|
+
self.initialise(self.class.api_key, self.class.app_id, self.class.app_version)
|
162
|
+
end
|
163
|
+
else
|
164
|
+
puts('Received HTTP Status Code: ' + response.code)
|
165
|
+
puts(response.body)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def SendCrash(e, severity, customProperties = {})
|
170
|
+
exceptionDetails = processStacktrace(e.backtrace)
|
171
|
+
|
172
|
+
postData = returnPostData(e, severity, exceptionDetails, customProperties)
|
173
|
+
|
174
|
+
sendCrashRequest(postData)
|
175
|
+
end
|
176
|
+
|
177
|
+
private
|
178
|
+
|
179
|
+
def sendCrashRequest(postData)
|
180
|
+
headers = {
|
181
|
+
"authorisation-token": self.class.api_key,
|
182
|
+
"cookie": 'SESSIONID=' + self.class.session_id
|
183
|
+
}
|
184
|
+
|
185
|
+
if self.class.do_lb != ''
|
186
|
+
headers['cookie'] = headers[:cookie] + '; DO-LB=' + self.class.do_lb
|
187
|
+
end
|
188
|
+
|
189
|
+
post_url = self.class.critimon_url + 'crash'
|
190
|
+
|
191
|
+
uri = URI.parse(post_url)
|
192
|
+
|
193
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
194
|
+
if uri.port == 443
|
195
|
+
http.use_ssl = true
|
196
|
+
end
|
197
|
+
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
198
|
+
request.set_form_data(postData)
|
199
|
+
|
200
|
+
response = http.request(request)
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
if response.code != '200'
|
205
|
+
@@pending_crashes.push(postData)
|
206
|
+
if @@critimon_initialised
|
207
|
+
self.initialise(@@api_key, @@app_id, @@app_version)
|
208
|
+
end
|
209
|
+
else
|
210
|
+
if response.body != ''
|
211
|
+
json = JSON.parse(response.body)
|
212
|
+
if json['result'] == 5
|
213
|
+
self.initialise(@@api_key, @@app_id, @@app_version)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
private
|
220
|
+
|
221
|
+
def returnPostData(e, severity, exceptionDetails, customProperties = {})
|
222
|
+
postData = {}
|
223
|
+
postData['ExceptionType'] = e.class.to_s
|
224
|
+
postData['DeviceID'] = @@device_id
|
225
|
+
postData['Stacktrace'] = exceptionDetails[:stacktrace]
|
226
|
+
postData['Severity'] = severity
|
227
|
+
postData['CrashType'] = 'Handled'
|
228
|
+
postData['DeviceType'] = 'Ruby'
|
229
|
+
postData['AppID'] = self.class.app_id
|
230
|
+
postData['VersionName'] = @@app_version
|
231
|
+
postData['ExceptionMessage'] = e.message
|
232
|
+
postData['File'] = exceptionDetails[:file]
|
233
|
+
postData['LineNo'] = exceptionDetails[:lineNo]
|
234
|
+
postData['OSName'] = returnOSName
|
235
|
+
postData['Architecture'] = 'x' + OS.bits.to_s
|
236
|
+
postData['RubyVersion'] = RUBY_VERSION
|
237
|
+
if customProperties != {}
|
238
|
+
postData['CustomProperty'] = customProperties.to_json
|
239
|
+
else
|
240
|
+
postData['CustomProperty'] = ''
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
postData
|
245
|
+
end
|
246
|
+
|
247
|
+
private
|
248
|
+
|
249
|
+
def returnOSName
|
250
|
+
if OS.windows?
|
251
|
+
'Windows'
|
252
|
+
elsif OS.linux?
|
253
|
+
'Linux'
|
254
|
+
elsif OS.mac?
|
255
|
+
'Mac'
|
256
|
+
else
|
257
|
+
'Unknown'
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
private
|
262
|
+
|
263
|
+
def processStacktrace(backtrace)
|
264
|
+
# The first line contains the crash point
|
265
|
+
line = backtrace[0]
|
266
|
+
lineDetails = line.split(':')
|
267
|
+
|
268
|
+
sectionCount = 0
|
269
|
+
file = ''
|
270
|
+
if lineDetails.count > 1
|
271
|
+
# We're most likely on Windows so there are extra colons (:) so make sure the full path is still included
|
272
|
+
file = lineDetails[0]
|
273
|
+
file = file + ':' + lineDetails[1]
|
274
|
+
sectionCount += 2
|
275
|
+
end
|
276
|
+
lineNo = lineDetails[sectionCount]
|
277
|
+
sectionCount += 1
|
278
|
+
|
279
|
+
# Create the full stack trace as a string
|
280
|
+
stacktrace = ''
|
281
|
+
backtrace.each do |line|
|
282
|
+
stacktrace += line + "\n"
|
283
|
+
end
|
284
|
+
|
285
|
+
{
|
286
|
+
file: file,
|
287
|
+
lineNo: lineNo,
|
288
|
+
stacktrace: stacktrace
|
289
|
+
}
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: critimonlib-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Board - Boardies IT Solutions
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- critimonlib-ruby.gemspec
|
20
|
+
- lib/critimonlib-ruby.rb
|
21
|
+
homepage: https://critimon.com
|
22
|
+
licenses:
|
23
|
+
- Apache-2.0
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.0.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: CritiMon Library for Ruby
|
44
|
+
test_files: []
|