cronitor 5.2.2 → 5.3.0
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/cronitor/monitor.rb +29 -0
- data/lib/cronitor/version.rb +1 -1
- data/lib/cronitor.rb +11 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d786e1bcc6b048371b5a9ef9e2c9d4d0db9a7e8d65f30cfd1029cbd3409f9e0e
|
4
|
+
data.tar.gz: df00a0cfe1cd458146b892b145b2919caf51f384dbe4c89348a6f03b3afa4a83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaf140a231580c70c6653795e4530f792384602e9c1c5ee6da3cc4da4de2f55fa73d4bdb920af72448be5dcce75963a68f2b3e660593334f64482d05198a8d18
|
7
|
+
data.tar.gz: 4b530de67e7d3f2fbb86fece1a9cdae10a01456d6707a9c4d92f76a09004bc0c9a1a907c665fb6e62006a13b3e5394f41b44946e6cc853754330fdb16a4500b3
|
data/lib/cronitor/monitor.rb
CHANGED
@@ -77,6 +77,35 @@ module Cronitor
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
def self.as_yaml(api_key: nil, api_version: nil)
|
81
|
+
timeout = Cronitor.timeout || 10
|
82
|
+
api_key = api_key || Cronitor.api_key
|
83
|
+
|
84
|
+
unless api_key
|
85
|
+
raise Error.new('No API key detected. Set Cronitor.api_key or pass api_key parameter')
|
86
|
+
end
|
87
|
+
|
88
|
+
headers = Cronitor::Monitor::Headers::YAML.dup
|
89
|
+
headers[:'Cronitor-Version'] = api_version if api_version
|
90
|
+
|
91
|
+
resp = HTTParty.get(
|
92
|
+
"#{MONITOR_API_URL}.yaml",
|
93
|
+
basic_auth: {
|
94
|
+
username: api_key,
|
95
|
+
password: ''
|
96
|
+
},
|
97
|
+
headers: headers,
|
98
|
+
timeout: timeout
|
99
|
+
)
|
100
|
+
|
101
|
+
case resp.code
|
102
|
+
when 200
|
103
|
+
resp.body
|
104
|
+
else
|
105
|
+
raise Error.new("Unexpected error #{resp.code}: #{resp.body}")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
80
109
|
def delete
|
81
110
|
resp = HTTParty.delete(
|
82
111
|
"#{monitor_api_url}/#{key}",
|
data/lib/cronitor/version.rb
CHANGED
data/lib/cronitor.rb
CHANGED
@@ -49,6 +49,17 @@ module Cronitor
|
|
49
49
|
apply_config(rollback: true)
|
50
50
|
end
|
51
51
|
|
52
|
+
def self.generate_config(path = nil)
|
53
|
+
config_path = path || Cronitor.config || './cronitor.yaml'
|
54
|
+
yaml_content = Monitor.as_yaml
|
55
|
+
|
56
|
+
File.open(config_path, 'w') do |file|
|
57
|
+
file.write(yaml_content)
|
58
|
+
end
|
59
|
+
|
60
|
+
puts("Configuration saved to #{config_path}")
|
61
|
+
end
|
62
|
+
|
52
63
|
def self.job(key, &block)
|
53
64
|
monitor = Monitor.new(key)
|
54
65
|
series = Time.now.to_f
|