cronitor 5.1.0 → 5.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -11
- data/lib/cronitor/config.rb +5 -3
- data/lib/cronitor/monitor.rb +19 -10
- data/lib/cronitor/version.rb +1 -1
- data/lib/cronitor.rb +0 -3
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 256202e94ab78e773be9c52bfd101ba23fb12d33140be4035e03488918db4a09
|
4
|
+
data.tar.gz: 285d0414d43c71968b11b57be219bd8a8bc5f31b49a66b254124677efcc42869
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc5ffa239b51b869fc73b11fd83900340823e63fe46a82609a96e2c45f13148c1b6514844e1315a7a584927400a5cbb85381c7fa995940d938bfc1528403e7d3
|
7
|
+
data.tar.gz: 4666eea5d6f1cf5631fb9fcccadfa6e11d074a560af1a7a411b6dd8f7720dd8667576752337216ee4bca9c2a2dd6e718ecbc14d0b1656b6a6be642657b9fca51
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Cronitor Ruby Library
|
2
2
|
|
3
|
-
![
|
3
|
+
![Tests](https://github.com/cronitorio/cronitor-ruby/workflows/Test/badge.svg)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/cronitor.svg)](https://badge.fury.io/rb/cronitor)
|
5
5
|
|
6
6
|
|
@@ -62,6 +62,8 @@ monitor.ping(state: 'complete', metrics: {count: 1000, error_count: 17})
|
|
62
62
|
|
63
63
|
## Configuring Monitors
|
64
64
|
|
65
|
+
### Using a YAML configuration file
|
66
|
+
|
65
67
|
You can configure all of your monitors using a single YAML file. This can be version controlled and synced to Cronitor as part of
|
66
68
|
a deployment or build process. For details on all of the attributes that can be set, see the [Monitor API](https://cronitor.io/docs/monitor-api) documentation.
|
67
69
|
|
@@ -127,38 +129,65 @@ heartbeats:
|
|
127
129
|
|
128
130
|
```
|
129
131
|
|
130
|
-
|
132
|
+
### Using `Cronitor::Monitor.put`
|
133
|
+
|
134
|
+
You can also create and update monitors by calling `Cronitor::Monitor.put`. This method can handle multiple monitors at once and supports various configurations and options.
|
135
|
+
|
131
136
|
|
137
|
+
#### Usage
|
132
138
|
```ruby
|
133
139
|
require 'cronitor'
|
134
140
|
|
141
|
+
# Define monitors as an array of hashes
|
135
142
|
monitors = [
|
136
143
|
{
|
137
144
|
type: 'job',
|
138
145
|
key: 'send-customer-invoices',
|
139
146
|
schedule: '0 0 * * *',
|
140
|
-
assertions: [
|
141
|
-
'metric.duration < 5 min'
|
142
|
-
],
|
147
|
+
assertions: ['metric.duration < 5 min'],
|
143
148
|
notify: ['devops-alerts-slack']
|
144
149
|
},
|
145
150
|
{
|
146
151
|
type: 'check',
|
147
152
|
key: 'Cronitor Homepage',
|
148
|
-
request: {
|
149
|
-
url: 'https://cronitor.io'
|
150
|
-
},
|
153
|
+
request: { url: 'https://cronitor.io' },
|
151
154
|
schedule: 'every 60 seconds',
|
152
155
|
assertions: [
|
153
|
-
|
154
|
-
|
156
|
+
'response.code = 200',
|
157
|
+
'response.time < 600ms'
|
155
158
|
]
|
156
159
|
}
|
157
160
|
]
|
158
161
|
|
159
|
-
|
162
|
+
# Options hash with monitors array
|
163
|
+
options = {
|
164
|
+
monitors: monitors,
|
165
|
+
format: 'json', # Optional, can be 'json' or 'yaml'
|
166
|
+
rollback: false, # Optional, default is false
|
167
|
+
timeout: 10 # Optional, specify request timeout in seconds
|
168
|
+
}
|
169
|
+
|
170
|
+
# Create or update monitors
|
171
|
+
Cronitor::Monitor.put(options)
|
160
172
|
```
|
161
173
|
|
174
|
+
#### Parameters
|
175
|
+
- `monitors`: An array of monitor configuration hashes.
|
176
|
+
- `options`: A hash containing:
|
177
|
+
- `:monitors`: An array of monitor hashes (required).
|
178
|
+
- `:format`: String, format of the request ('json' or 'yaml'). Default is 'json'.
|
179
|
+
- `:rollback`: Boolean, indicates whether to rollback on failure. Default is `false`.
|
180
|
+
- `:timeout`: Integer, request timeout in seconds. Falls back to `Cronitor.timeout` if not specified.
|
181
|
+
|
182
|
+
#### Return Value
|
183
|
+
Depending on the `:format` option, this method returns:
|
184
|
+
- For JSON: An array of `Cronitor::Monitor` instances or a single instance if only one monitor is provided.
|
185
|
+
- For YAML: The parsed response body.
|
186
|
+
|
187
|
+
#### Error Handling
|
188
|
+
- `ValidationError`: Raised when the API returns a 400 status code, indicating invalid monitor configurations.
|
189
|
+
- `Error`: Raised for other non-successful responses, indicating issues with connecting to the Cronitor API.
|
190
|
+
|
162
191
|
### Pause, Reset, Delete
|
163
192
|
|
164
193
|
```ruby
|
data/lib/cronitor/config.rb
CHANGED
@@ -9,20 +9,22 @@ module Cronitor
|
|
9
9
|
YAML_KEYS = MONITOR_TYPES.map { |t| "#{t}s" }
|
10
10
|
|
11
11
|
class << self
|
12
|
-
attr_accessor :api_key, :api_version, :environment, :logger, :config, :timeout, :ping_timeout, :auto_discover_sidekiq
|
12
|
+
attr_accessor :api_key, :api_version, :environment, :logger, :config, :timeout, :ping_timeout, :auto_discover_sidekiq, :telemetry_domain
|
13
13
|
|
14
14
|
def configure(&block)
|
15
15
|
block.call(self)
|
16
16
|
end
|
17
|
+
|
17
18
|
end
|
18
19
|
|
19
20
|
self.api_key = ENV.fetch('CRONITOR_API_KEY', nil)
|
20
21
|
self.api_version = ENV.fetch('CRONITOR_API_VERSION', nil)
|
21
22
|
self.environment = ENV.fetch('CRONITOR_ENVIRONMENT', nil)
|
22
|
-
self.timeout = ENV.fetch('CRONITOR_TIMEOUT',
|
23
|
-
self.ping_timeout = ENV.fetch('CRONITOR_PING_TIMEOUT',
|
23
|
+
self.timeout = ENV.fetch('CRONITOR_TIMEOUT', 10)
|
24
|
+
self.ping_timeout = ENV.fetch('CRONITOR_PING_TIMEOUT', 5)
|
24
25
|
self.config = ENV.fetch('CRONITOR_CONFIG', nil)
|
25
26
|
self.auto_discover_sidekiq = ENV.fetch('CRONITOR_AUTO_DISCOVER_SIDEKIQ', 'true').casecmp('true').zero? # https://github.com/cronitorio/cronitor-sidekiq
|
27
|
+
self.telemetry_domain = ENV.fetch('CRONITOR_TELEMETRY_DOMAIN', 'cronitor.link')
|
26
28
|
self.logger = Logger.new($stdout)
|
27
29
|
logger.level = Logger::INFO
|
28
30
|
end
|
data/lib/cronitor/monitor.rb
CHANGED
@@ -4,7 +4,7 @@ module Cronitor
|
|
4
4
|
class Monitor
|
5
5
|
attr_reader :key, :api_key, :api_version, :env
|
6
6
|
|
7
|
-
PING_RETRY_THRESHOLD =
|
7
|
+
PING_RETRY_THRESHOLD = 3
|
8
8
|
|
9
9
|
module Formats
|
10
10
|
ALL = [
|
@@ -24,19 +24,19 @@ module Cronitor
|
|
24
24
|
})
|
25
25
|
end
|
26
26
|
|
27
|
+
|
27
28
|
def self.put(opts = {})
|
28
29
|
rollback = opts[:rollback] || false
|
29
30
|
opts.delete(:rollback)
|
30
31
|
|
31
32
|
monitors = opts[:monitors] || [opts]
|
32
|
-
|
33
|
+
url = "https://cronitor.io/api/monitors"
|
33
34
|
if opts[:format] == Cronitor::Monitor::Formats::YAML
|
34
|
-
url = "#{
|
35
|
+
url = "#{url}.yaml"
|
35
36
|
monitors['rollback'] = true if rollback
|
36
37
|
body = YAML.dump(monitors)
|
37
38
|
headers = Cronitor::Monitor::Headers::YAML
|
38
39
|
else
|
39
|
-
url = Cronitor.monitor_api_url
|
40
40
|
body = {
|
41
41
|
monitors: monitors,
|
42
42
|
rollback: rollback
|
@@ -120,8 +120,7 @@ module Cronitor
|
|
120
120
|
|
121
121
|
begin
|
122
122
|
ping_url = ping_api_url
|
123
|
-
ping_url = fallback_ping_api_url if retry_count >
|
124
|
-
|
123
|
+
ping_url = fallback_ping_api_url if retry_count > Monitor::PING_RETRY_THRESHOLD
|
125
124
|
response = HTTParty.get(
|
126
125
|
ping_url,
|
127
126
|
query: clean_params(params),
|
@@ -159,7 +158,7 @@ module Cronitor
|
|
159
158
|
end
|
160
159
|
|
161
160
|
def pause(hours = nil)
|
162
|
-
pause_url = "#{monitor_api_url}/pause"
|
161
|
+
pause_url = "#{monitor_api_url}/#{key}/pause"
|
163
162
|
pause_url += "/#{hours}" unless hours.nil?
|
164
163
|
|
165
164
|
resp = HTTParty.get(
|
@@ -180,7 +179,7 @@ module Cronitor
|
|
180
179
|
end
|
181
180
|
|
182
181
|
def ping_api_url
|
183
|
-
"https
|
182
|
+
"https://#{Cronitor.telemetry_domain}/p/#{api_key}/#{key}"
|
184
183
|
end
|
185
184
|
|
186
185
|
def fallback_ping_api_url
|
@@ -188,9 +187,10 @@ module Cronitor
|
|
188
187
|
end
|
189
188
|
|
190
189
|
def monitor_api_url
|
191
|
-
"
|
190
|
+
"https://cronitor.io/api/monitors"
|
192
191
|
end
|
193
192
|
|
193
|
+
|
194
194
|
private
|
195
195
|
|
196
196
|
def fetch
|
@@ -201,7 +201,16 @@ module Cronitor
|
|
201
201
|
return
|
202
202
|
end
|
203
203
|
|
204
|
-
HTTParty.get(
|
204
|
+
HTTParty.get(
|
205
|
+
monitor_api_url,
|
206
|
+
basic_auth: {
|
207
|
+
username: api_key,
|
208
|
+
password: ''
|
209
|
+
},
|
210
|
+
timeout: Cronitor.timeout,
|
211
|
+
headers: Cronitor::Monitor::Headers::JSON,
|
212
|
+
format: :json
|
213
|
+
)
|
205
214
|
end
|
206
215
|
|
207
216
|
def clean_params(params)
|
data/lib/cronitor/version.rb
CHANGED
data/lib/cronitor.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cronitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1
|
4
|
+
version: 5.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Byrnes
|
8
8
|
- August Flanagan
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-01-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -165,7 +165,7 @@ dependencies:
|
|
165
165
|
- - "~>"
|
166
166
|
- !ruby/object:Gem::Version
|
167
167
|
version: '3.1'
|
168
|
-
description:
|
168
|
+
description:
|
169
169
|
email:
|
170
170
|
- thejeffbyrnes@gmail.com
|
171
171
|
- august@cronitor.io
|
@@ -194,7 +194,7 @@ files:
|
|
194
194
|
homepage: https://github.com/cronitorio/cronitor-ruby
|
195
195
|
licenses: []
|
196
196
|
metadata: {}
|
197
|
-
post_install_message:
|
197
|
+
post_install_message:
|
198
198
|
rdoc_options: []
|
199
199
|
require_paths:
|
200
200
|
- lib
|
@@ -209,8 +209,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
209
|
- !ruby/object:Gem::Version
|
210
210
|
version: '0'
|
211
211
|
requirements: []
|
212
|
-
rubygems_version: 3.1
|
213
|
-
signing_key:
|
212
|
+
rubygems_version: 3.0.3.1
|
213
|
+
signing_key:
|
214
214
|
specification_version: 4
|
215
215
|
summary: An interface for the Cronitor API
|
216
216
|
test_files: []
|