autocronitor 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4334ec51866f0f902f5c4a5fa001226434fdba70
4
- data.tar.gz: 3af9bb04c359f60413a0bf74a6317a833f8c3698
3
+ metadata.gz: f147f3bfb273ce8a257216566f9c2da8bd1ce99b
4
+ data.tar.gz: 77925a1f8fc30e30489433def65c0cc87ab82627
5
5
  SHA512:
6
- metadata.gz: fecee7908256c2413572797156d6a6cd63e2e8ad29b4224a6f0ba186637c14d97c56f39a947d9bb467dec5ab24c3c5cea90cb0ed75e0ae3d2f2b3f6b953838cf
7
- data.tar.gz: f12b4218c4c9d38aefde4e7d825d4b2eb3bed2c9d4d7e410a12b35575c3bd609cf072e71be7a88cec966ac1a26f6ade64e97bab6cf8d84a83b055b8e54c73792
6
+ metadata.gz: fe0b93395126992d15b54b79ab96a86171cc553f7aaa4863e43e509608cd09dc2c1b59b6adbecf766e2af477b5bcda5fdfc305b984fcfce83a30bb7db268f296
7
+ data.tar.gz: f2df409a03a48810a675e76b2cbdf306652d34af23a1390ceadf4a44ddff2cec0f7cf9cf69868e9c9a872a264cb2439c493b0b6025e498ef34dc411e12cbc3d7
@@ -1,3 +1,9 @@
1
+ ## 0.0.5(22nd June, 2017)
2
+
3
+ Features:
4
+
5
+ - Update to v3 of Cronitor API (Thanks to @cronitorio https://github.com/jonlives/autocronitor/pull/2)
6
+
1
7
  ## 0.0.1(14th Dec, 2015)
2
8
 
3
9
  Bugfixes:
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+ gemspec
4
+
5
+ # gem "rails"
@@ -0,0 +1,29 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ autocronitor (0.0.4)
5
+ choice (~> 0.2, >= 0.2.0)
6
+ unirest (~> 1.1, >= 1.1.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.3.8)
12
+ choice (0.2.0)
13
+ json (1.8.6)
14
+ mime-types (1.25.1)
15
+ rest-client (1.6.9)
16
+ mime-types (~> 1.16)
17
+ unirest (1.1.2)
18
+ addressable (~> 2.3.5)
19
+ json (~> 1.8.1)
20
+ rest-client (~> 1.6.7)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ autocronitor!
27
+
28
+ BUNDLED WITH
29
+ 1.13.6
data/README.md CHANGED
@@ -38,9 +38,9 @@ Text to exclude:
38
38
  * Mandatory Parameters (you must specify one or the other)
39
39
  * -a, --api-key APIKEY Your cronitor.io API key
40
40
  * -f, --filename FILENAME The crontab files to read
41
- * -t, --templace *TEMPLATES The Cronitor.io template(s) to use for notifications
42
41
 
43
42
  * Optional Parameters
43
+ * -t, --templace *TEMPLATES The Cronitor.io template(s) to use for notifications. If not provided Cronitor will default to using the email address of your account to send notifications.
44
44
  * -c, --common-text *COMMONTEXT A space separated list of common text to exclude from cron names
45
45
  * -i, --common-include-text *COMMONINCLUDETEXT A space separated list of common text to exclude from cron names (includes strings which contain each phrase)
46
46
 
@@ -54,8 +54,6 @@ Processing file test.conf
54
54
 
55
55
  Cron expression: 10 * * * *
56
56
  Cron name: testcron
57
- Suggested rules:
58
- [{"rule_type"=>"ran_longer_than", "duration"=>1, "human_readable"=>"Ran for longer than 1 hour", "time_unit"=>"hours", "hours_to_followup_alert"=>24}, {"rule_type"=>"not_completed_in", "duration"=>61, "human_readable"=>"Has not received a complete ping in over 61 minutes", "time_unit"=>"minutes", "hours_to_followup_alert"=>24}]
59
57
  Creating monitor testcron...
60
58
  Monitor 'testcron' created with ID abc123
61
59
 
@@ -2,7 +2,7 @@ $:.push File.expand_path('../lib', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'autocronitor'
5
- gem.version = '0.0.4'
5
+ gem.version = '0.0.5'
6
6
  gem.authors = ["Jon Cowie"]
7
7
  gem.email = 'jonlives@gmail.com'
8
8
  gem.homepage = 'https://github.com/jonlives/autocronitor'
@@ -26,7 +26,7 @@ Choice.options do
26
26
  separator ''
27
27
  separator 'Email Options: '
28
28
 
29
- option :template_name, :required => true do
29
+ option :template_name do
30
30
  short '-t'
31
31
  long '--templace *TEMPLATES'
32
32
  desc 'The Cronitor.io templates to send alerts for this monitor to'
@@ -73,8 +73,8 @@ else
73
73
  # Read all lines from file
74
74
  File.readlines(file_name).each do |line|
75
75
 
76
- # Skip the current line if it's a comment
77
- if line.include?("#") or line == "\n"
76
+ # Skip the current line if it's a comment, empty, or MAILTO
77
+ if line.include?("#") or line.start_with?("MAILTO") or line == "\n"
78
78
  new_file_lines << line
79
79
  next
80
80
  end
@@ -97,18 +97,12 @@ else
97
97
 
98
98
  puts "Cron expression: #{cron_expression}"
99
99
  puts "Cron name: #{filtered_line}"
100
-
101
- # Talk to cronitor's suggest API to get auto-generated rules for our cron expression
102
- rules = helper.monitor_suggest(cron_expression)
103
- puts "Suggested rules:"
104
- puts rules.inspect
105
-
106
- # Create a new monitor via cronitor's API with the name and rules we've created
107
100
  puts "Creating monitor #{filtered_line}..."
108
- monitor_id = helper.monitor_create(filtered_line,rules,template_names)
101
+
102
+ monitor_id = helper.monitor_create(filtered_line, cron_expression, template_names)
109
103
 
110
104
  # Construct the replacement line to be written back to the file
111
- cronitored_line = "#{cron_expression} curl #{monitor_id + '/run'} -m 10 && #{remaining_line.join(" ")} && curl #{monitor_id + '/complete'} -m 10"
105
+ cronitored_line = "#{cron_expression} curl #{monitor_id + '/run'} -m 10 ; #{remaining_line.join(" ")} && curl #{monitor_id + '/complete'} -m 10"
112
106
  new_file_lines << cronitored_line
113
107
  puts ""
114
108
  end
@@ -5,25 +5,29 @@ module Autocronitor
5
5
 
6
6
  def initialize(api_key)
7
7
  @monitor_template = {
8
- name: '',
9
- notifications: {
10
- templates: [],
11
- },
12
- rules: [
13
- ],
14
- note: 'A human-friendly description of this monitor'
8
+ name: '',
9
+ notifications: {
10
+ templates: [],
11
+ },
12
+ rules: [],
13
+ type: 'heartbeat'
15
14
  }
16
15
 
17
- @api_url = 'https://cronitor.io/v1'
16
+ @api_url = 'https://cronitor.io/v3'
18
17
  @monitor_url = 'https://cronitor.link'
19
18
  @monitor_details = {}
20
19
  @api_key = api_key
21
20
  end
22
21
 
23
- def monitor_create(monitor_name,rules,template_names)
24
- @monitor_template[:name] = monitor_name
25
- @monitor_template[:rules] = rules
26
- @monitor_template[:notifications][:templates] = rules.kind_of?(Array) ? template_names : [template_names]
22
+ def monitor_create(monitor_name, cron_expression, template_names)
23
+ @monitor_template[:name] = monitor_name[0..99]
24
+ @monitor_template[:rules] = [
25
+ {
26
+ rule_type: 'not_on_schedule',
27
+ value: cron_expression
28
+ }
29
+ ]
30
+ @monitor_template[:notifications][:templates] = template_names.kind_of?(Array) ? template_names : [template_names]
27
31
 
28
32
  response = Unirest.post(
29
33
  "#{@api_url}/monitors",
@@ -34,21 +38,16 @@ module Autocronitor
34
38
  monitor_id = response.body["code"]
35
39
  if response.code == 201
36
40
  puts "Monitor '#{monitor_name}' created with ID #{monitor_id}"
41
+ elsif response.code == 400 && JSON.parse(response.body)['name'] == ["name must be unique"]
42
+ puts "Monitor '#{monitor_name}' already exists, skipping \n"
37
43
  else
38
44
  puts "Error code: #{response.code} returned, exiting"
45
+ puts "Response: \n\n #{response.body}"
39
46
  exit 1
40
47
  end
41
48
  @monitor_details[monitor_name] = monitor_id
42
49
  return "#{@monitor_url}/#{monitor_id}"
43
50
  end
44
51
 
45
- def monitor_suggest(cron_expression)
46
- response = Unirest.get(
47
- "#{@api_url}/rules/suggest",
48
- auth: { user: @api_key },
49
- parameters:{ 'cron-expression' => cron_expression }
50
- )
51
- return response.body
52
- end
53
52
  end
54
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autocronitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Cowie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-08 00:00:00.000000000 Z
11
+ date: 2017-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unirest
@@ -64,6 +64,8 @@ extra_rdoc_files: []
64
64
  files:
65
65
  - .gitignore
66
66
  - CHANGELOG.md
67
+ - Gemfile
68
+ - Gemfile.lock
67
69
  - LICENSE
68
70
  - README.md
69
71
  - autocronitor.gemspec
@@ -90,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
92
  version: '0'
91
93
  requirements: []
92
94
  rubyforge_project:
93
- rubygems_version: 2.0.14
95
+ rubygems_version: 2.0.14.1
94
96
  signing_key:
95
97
  specification_version: 4
96
98
  summary: A tool to automatically pass a standard-format crontab file and add jobs