uppityrobot 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a43403fa79d70d7486e910da91559419ad6c354d1ae226ff9d2314334f7b843a
4
- data.tar.gz: a7df2cd6f2354ee75bc240ecadab18bb72ca8bfd1c341c59906e84089b3a5f61
3
+ metadata.gz: 343f05015c34d7aa261f85ff37aa3ec32dce89afc56a8d7c5753ed09899837b2
4
+ data.tar.gz: 3b3ae5b2897e25d28743c2b5de6b8dadef72e49072d0d028d6cc10d083c531c6
5
5
  SHA512:
6
- metadata.gz: 52658001a0f1d6b424bf5e2ffab409f5757b36bcba4022d7bb692cae8d603913c3bad0db13048f157517a03fe41a9d18ffc68d829633e7017c9a36e029521be3
7
- data.tar.gz: 980c09f8b48d92d1b770ef8af8d9d37f51c1231633808aa786c60b36a8db6297f883c2932a5e815d4041ba8775835c5c0a27e4dff78557f4b8ea17c849419cb0
6
+ metadata.gz: 31d7900e684a36840e30ee4d06f3687ed4dc83349ede3e5cf72b906b86208e648c15c258651db84e7b72712806b61721a8ebcbc27a7f61d4d91ab67a62fcdb27
7
+ data.tar.gz: fe39c68cf5760d100840864c0e6d0670f2f81bdd986dc750592adbb7e07adb053e668d73489ff9125a0f04d2aa2af2343e606ae9c50f0c89e6b604a93f2efa92
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- uppityrobot (0.2.0)
4
+ uppityrobot (0.3.1)
5
5
  dry-cli (~> 0.7)
6
6
  json (~> 2.5)
7
7
  uptimerobot (~> 0.2)
@@ -68,30 +68,34 @@ GEM
68
68
  cucumber-messages (~> 17.0, >= 17.0.1)
69
69
  diff-lcs (1.4.4)
70
70
  dry-cli (0.7.0)
71
- faraday (1.7.2)
71
+ faraday (1.10.0)
72
72
  faraday-em_http (~> 1.0)
73
73
  faraday-em_synchrony (~> 1.0)
74
74
  faraday-excon (~> 1.1)
75
- faraday-httpclient (~> 1.0.1)
75
+ faraday-httpclient (~> 1.0)
76
+ faraday-multipart (~> 1.0)
76
77
  faraday-net_http (~> 1.0)
77
- faraday-net_http_persistent (~> 1.1)
78
+ faraday-net_http_persistent (~> 1.0)
78
79
  faraday-patron (~> 1.0)
79
80
  faraday-rack (~> 1.0)
80
- multipart-post (>= 1.2, < 3)
81
+ faraday-retry (~> 1.0)
81
82
  ruby2_keywords (>= 0.0.4)
82
83
  faraday-em_http (1.0.0)
83
84
  faraday-em_synchrony (1.0.0)
84
85
  faraday-excon (1.1.0)
85
86
  faraday-httpclient (1.0.1)
87
+ faraday-multipart (1.0.3)
88
+ multipart-post (>= 1.2, < 3)
86
89
  faraday-net_http (1.0.1)
87
90
  faraday-net_http_persistent (1.2.0)
88
91
  faraday-patron (1.0.0)
89
92
  faraday-rack (1.0.0)
90
- faraday_middleware (1.1.0)
93
+ faraday-retry (1.0.3)
94
+ faraday_middleware (1.2.0)
91
95
  faraday (~> 1.0)
92
96
  ffi (1.15.4)
93
97
  hashdiff (1.0.1)
94
- json (2.5.1)
98
+ json (2.6.1)
95
99
  json_spec (1.1.5)
96
100
  multi_json (~> 1.0)
97
101
  rspec (>= 2.0, < 4.0)
@@ -192,4 +196,4 @@ DEPENDENCIES
192
196
  webmock
193
197
 
194
198
  BUNDLED WITH
195
- 2.2.21
199
+ 2.2.28
data/README.md CHANGED
@@ -107,18 +107,28 @@ client = UppityRobot::Client.new(:getMonitors, {search: 'aspace'})
107
107
  client.filter({'friendly_name' => 'columbia'}).each { |m| puts m.inspect; }
108
108
  ```
109
109
 
110
- ## Release
111
-
112
- To release a new version:
110
+ ## Including UppityRobot tasks in another project
113
111
 
114
- - Update the version number in `version.rb`
115
- - Run `bundle exec rake release`
112
+ ```ruby
113
+ require "uppityrobot"
114
+ spec = Gem::Specification.find_by_name("uppityrobot")
115
+ load File.join(spec.gem_dir, "lib", "uppityrobot", "Rakefile")
116
+ ```
116
117
 
117
- This:
118
+ ## Release
118
119
 
119
- - Creates a git tag for the version
120
- - Pushes git commits and the created tag
121
- - Pushes the `.gem` file to [rubygems.org](https://rubygems.org).
120
+ ```bash
121
+ gem install gem-release
122
+ # https://github.com/svenfuchs/gem-release#gem-bump
123
+ gem bump --version $VERSION --tag
124
+ # i.e.
125
+ gem bump --version minor --tag --pretend # dryrun
126
+ gem bump --version minor --tag # do it for real
127
+
128
+ bundle
129
+ git commit --amend # needed via Rakefile
130
+ # now push & release
131
+ ```
122
132
 
123
133
  ## Contributing
124
134
 
data/Rakefile CHANGED
@@ -12,3 +12,5 @@ require "cucumber/rake/task"
12
12
  Cucumber::Rake::Task.new
13
13
 
14
14
  task default: %i[spec cucumber rubocop]
15
+
16
+ load File.join("lib", "uppityrobot", "Rakefile")
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uppityrobot"
4
+ Dir.glob(File.join(File.expand_path(__dir__), "tasks", "*.rake")).each { |f| import f }
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Metrics/BlockLength
4
+
5
+ namespace :uppityrobot do
6
+ namespace :tasks do
7
+ def alert_contacts
8
+ ENV.fetch("UPTIMEROBOT_ALERT_CONTACTS") do
9
+ contacts = UppityRobot::Client.new(:getAlertContacts, {}).execute
10
+ contact = contacts["alert_contacts"].find { |c| c["friendly_name"] == friendly_name }
11
+ raise "CONTACT NOT FOUND" unless contact
12
+
13
+ contact["id"]
14
+ end
15
+ end
16
+
17
+ def friendly_name
18
+ ENV.fetch("UPTIMEROBOT_FRIENDLY_NAME", "")
19
+ end
20
+
21
+ def monitors(prefix:)
22
+ monitors = {}
23
+ UppityRobot::Client.new(:getMonitors, search: prefix).filter("friendly_name" => "^#{prefix}").each do |m|
24
+ monitors[m["friendly_name"]] = m
25
+ end
26
+ monitors
27
+ end
28
+
29
+ desc "Display uptimerobot contacts set via environment"
30
+ task :contacts do
31
+ raise "UPTIMEROBOT_API_KEY is required" unless ENV["UPTIMEROBOT_API_KEY"]
32
+
33
+ puts alert_contacts
34
+ end
35
+
36
+ desc "List all uptimerobot monitors by prefix"
37
+ task :list, [:prefix] do |_, args|
38
+ raise "UPTIMEROBOT_API_KEY is required" unless ENV["UPTIMEROBOT_API_KEY"]
39
+
40
+ puts monitors(prefix: args.fetch(:prefix)).to_json
41
+ end
42
+
43
+ desc "Process uptimerobot monitors csv"
44
+ task :process, [:prefix, :csv] do |_, args|
45
+ raise "UPTIMEROBOT_API_KEY is required" unless ENV["UPTIMEROBOT_API_KEY"]
46
+
47
+ prefix = args[:prefix]
48
+ csv = args.fetch(:csv, File.join(Dir.getwd, "files", "monitors", "uptimerobot.csv"))
49
+ raise "CSV not found" unless File.file? csv
50
+
51
+ contacts = alert_contacts
52
+ current_monitors = monitors(prefix: prefix)
53
+
54
+ CSV.read(csv, headers: true).each do |row|
55
+ data = row.to_hash
56
+ name = data["friendly_name"]
57
+ url = data["url"]
58
+
59
+ begin
60
+ if !current_monitors.key?(name)
61
+ puts "Creating monitor: #{name} #{url}"
62
+ d = {
63
+ friendly_name: name,
64
+ url: url,
65
+ type: UptimeRobot::Monitor::Type::HTTP,
66
+ subtype: UptimeRobot::Monitor::SubType::HTTPS,
67
+ alert_contacts: contacts
68
+ }
69
+ UppityRobot::Client.new(:newMonitor, d).execute
70
+ elsif current_monitors.key?(name) && current_monitors[name]["url"] != url
71
+ puts "Updating monitor: #{current_monitors[name]["url"]} TO #{url} WITH CONTACTS #{contacts}"
72
+ # avoid uptimerobot client weirdness
73
+ d = { id: current_monitors[name]["id"], url: url, alert_contacts: contacts }.dup
74
+ UppityRobot::Client.new(:editMonitor, d).execute
75
+ end
76
+ rescue UptimeRobot::Error => e
77
+ puts "Error processing monitor: #{data} #{e.message}"
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ # rubocop:enable Metrics/BlockLength
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UppityRobot
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uppityrobot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Cooper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-15 00:00:00.000000000 Z
11
+ date: 2022-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -222,6 +222,7 @@ files:
222
222
  - fixtures/getMonitors.mywebpage.json
223
223
  - fixtures/newMonitor.json
224
224
  - lib/uppityrobot.rb
225
+ - lib/uppityrobot/Rakefile
225
226
  - lib/uppityrobot/cli/commands/exec.rb
226
227
  - lib/uppityrobot/cli/commands/monitors/create.rb
227
228
  - lib/uppityrobot/cli/commands/monitors/delete.rb
@@ -231,6 +232,7 @@ files:
231
232
  - lib/uppityrobot/cli/commands/registry.rb
232
233
  - lib/uppityrobot/cli/commands/version.rb
233
234
  - lib/uppityrobot/client.rb
235
+ - lib/uppityrobot/tasks/uppityrobot.rake
234
236
  - lib/uppityrobot/version.rb
235
237
  - uppityrobot.gemspec
236
238
  homepage: https://github.com/lyrasis/uppityrobot.git