uppityrobot 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +16 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/.vscode/settings.json +3 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +195 -0
- data/LICENSE.txt +21 -0
- data/README.md +129 -0
- data/Rakefile +14 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/uppityrobot +7 -0
- data/fixtures/deleteMonitor.json +1 -0
- data/fixtures/editMonitor.json +1 -0
- data/fixtures/getAlertContacts.json +22 -0
- data/fixtures/getMonitor.unknown.json +1 -0
- data/fixtures/getMonitors.google.json +35 -0
- data/fixtures/getMonitors.json +80 -0
- data/fixtures/getMonitors.mywebpage.json +55 -0
- data/fixtures/newMonitor.json +7 -0
- data/lib/uppityrobot/cli/commands/exec.rb +34 -0
- data/lib/uppityrobot/cli/commands/monitors/create.rb +50 -0
- data/lib/uppityrobot/cli/commands/monitors/delete.rb +47 -0
- data/lib/uppityrobot/cli/commands/monitors/exec.rb +57 -0
- data/lib/uppityrobot/cli/commands/monitors/list.rb +51 -0
- data/lib/uppityrobot/cli/commands/monitors/update.rb +72 -0
- data/lib/uppityrobot/cli/commands/registry.rb +21 -0
- data/lib/uppityrobot/cli/commands/version.rb +16 -0
- data/lib/uppityrobot/client.rb +112 -0
- data/lib/uppityrobot/version.rb +5 -0
- data/lib/uppityrobot.rb +25 -0
- data/uppityrobot.gemspec +41 -0
- metadata +261 -0
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "uppityrobot"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/uppityrobot
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"stat":"ok","monitor":{"id":777749809}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"stat":"ok","monitor":{"id":777712827}}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"stat": "ok",
|
3
|
+
"limit": 50,
|
4
|
+
"offset": 0,
|
5
|
+
"total": 2,
|
6
|
+
"alert_contacts": [
|
7
|
+
{
|
8
|
+
"id": "0993765",
|
9
|
+
"friendly_name": "John Doe",
|
10
|
+
"type": 2,
|
11
|
+
"status": 1,
|
12
|
+
"value": "johndoe@gmail.com"
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"id": "2403924",
|
16
|
+
"friendly_name": "My Twitter",
|
17
|
+
"type": 3,
|
18
|
+
"status": 0,
|
19
|
+
"value": "sampleTwitterAccount"
|
20
|
+
}
|
21
|
+
]
|
22
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"stat":"ok","total":0,"monitors":[]}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
{
|
2
|
+
"stat": "ok",
|
3
|
+
"pagination": {
|
4
|
+
"offset": 0,
|
5
|
+
"limit": 50,
|
6
|
+
"total": 1
|
7
|
+
},
|
8
|
+
"monitors": [
|
9
|
+
{
|
10
|
+
"id": 777749809,
|
11
|
+
"friendly_name": "Google",
|
12
|
+
"url": "http://www.google.com",
|
13
|
+
"type": 1,
|
14
|
+
"sub_type": "",
|
15
|
+
"keyword_type": "",
|
16
|
+
"keyword_case_type": "",
|
17
|
+
"keyword_value": "",
|
18
|
+
"http_username": "",
|
19
|
+
"http_password": "",
|
20
|
+
"port": "",
|
21
|
+
"interval": 900,
|
22
|
+
"status": 1,
|
23
|
+
"create_datetime": 1462565497,
|
24
|
+
"monitor_group": 0,
|
25
|
+
"is_group_main": 0,
|
26
|
+
"logs": [
|
27
|
+
{
|
28
|
+
"type": 98,
|
29
|
+
"datetime": 1463540297,
|
30
|
+
"duration": 1054134
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
]
|
35
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
{
|
2
|
+
"stat": "ok",
|
3
|
+
"pagination": {
|
4
|
+
"offset": 0,
|
5
|
+
"limit": 50,
|
6
|
+
"total": 2
|
7
|
+
},
|
8
|
+
"monitors": [
|
9
|
+
{
|
10
|
+
"id": 777749809,
|
11
|
+
"friendly_name": "Google",
|
12
|
+
"url": "http://www.google.com",
|
13
|
+
"type": 1,
|
14
|
+
"sub_type": "",
|
15
|
+
"keyword_type": "",
|
16
|
+
"keyword_case_type": "",
|
17
|
+
"keyword_value": "",
|
18
|
+
"http_username": "",
|
19
|
+
"http_password": "",
|
20
|
+
"port": "",
|
21
|
+
"interval": 900,
|
22
|
+
"status": 1,
|
23
|
+
"create_datetime": 1462565497,
|
24
|
+
"monitor_group": 0,
|
25
|
+
"is_group_main": 0,
|
26
|
+
"logs": [
|
27
|
+
{
|
28
|
+
"type": 98,
|
29
|
+
"datetime": 1463540297,
|
30
|
+
"duration": 1054134
|
31
|
+
}
|
32
|
+
]
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"id": 777712827,
|
36
|
+
"friendly_name": "My Web Page",
|
37
|
+
"url": "http://mywebpage.com/",
|
38
|
+
"type": 1,
|
39
|
+
"sub_type": "",
|
40
|
+
"keyword_type": "",
|
41
|
+
"keyword_case_type": "",
|
42
|
+
"keyword_value": "",
|
43
|
+
"http_username": "",
|
44
|
+
"http_password": "",
|
45
|
+
"port": "",
|
46
|
+
"interval": 60,
|
47
|
+
"status": 2,
|
48
|
+
"create_datetime": 1462465496,
|
49
|
+
"monitor_group": 0,
|
50
|
+
"is_group_main": 0,
|
51
|
+
"logs": [
|
52
|
+
{
|
53
|
+
"type": 98,
|
54
|
+
"datetime": 1462465202,
|
55
|
+
"duration": 32
|
56
|
+
},
|
57
|
+
{
|
58
|
+
"type": 1,
|
59
|
+
"datetime": 1462465234,
|
60
|
+
"duration": 490140
|
61
|
+
},
|
62
|
+
{
|
63
|
+
"type": 2,
|
64
|
+
"datetime": 1462955374,
|
65
|
+
"duration": 85
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"type": 99,
|
69
|
+
"datetime": 1462955588,
|
70
|
+
"duration": 12
|
71
|
+
},
|
72
|
+
{
|
73
|
+
"type": 98,
|
74
|
+
"datetime": 1462955600,
|
75
|
+
"duration": 22
|
76
|
+
}
|
77
|
+
]
|
78
|
+
}
|
79
|
+
]
|
80
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
{
|
2
|
+
"stat": "ok",
|
3
|
+
"pagination": {
|
4
|
+
"offset": 0,
|
5
|
+
"limit": 50,
|
6
|
+
"total": 1
|
7
|
+
},
|
8
|
+
"monitors": [
|
9
|
+
{
|
10
|
+
"id": 777712827,
|
11
|
+
"friendly_name": "My Web Page",
|
12
|
+
"url": "http://mywebpage.com/",
|
13
|
+
"type": 1,
|
14
|
+
"sub_type": "",
|
15
|
+
"keyword_type": "",
|
16
|
+
"keyword_case_type": "",
|
17
|
+
"keyword_value": "",
|
18
|
+
"http_username": "",
|
19
|
+
"http_password": "",
|
20
|
+
"port": "",
|
21
|
+
"interval": 60,
|
22
|
+
"status": 2,
|
23
|
+
"create_datetime": 1462465496,
|
24
|
+
"monitor_group": 0,
|
25
|
+
"is_group_main": 0,
|
26
|
+
"logs": [
|
27
|
+
{
|
28
|
+
"type": 98,
|
29
|
+
"datetime": 1462465202,
|
30
|
+
"duration": 32
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"type": 1,
|
34
|
+
"datetime": 1462465234,
|
35
|
+
"duration": 490140
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"type": 2,
|
39
|
+
"datetime": 1462955374,
|
40
|
+
"duration": 85
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"type": 99,
|
44
|
+
"datetime": 1462955588,
|
45
|
+
"duration": 12
|
46
|
+
},
|
47
|
+
{
|
48
|
+
"type": 98,
|
49
|
+
"datetime": 1462955600,
|
50
|
+
"duration": 22
|
51
|
+
}
|
52
|
+
]
|
53
|
+
}
|
54
|
+
]
|
55
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UppityRobot
|
4
|
+
module CLI
|
5
|
+
module Commands
|
6
|
+
# UppityRobot::CLI::Commands::Exec executes an API task
|
7
|
+
class Exec < Dry::CLI::Command
|
8
|
+
desc "Execute an API task"
|
9
|
+
|
10
|
+
argument :task, required: true, values: UptimeRobot::Client::METHODS, desc: "API task to be executed"
|
11
|
+
|
12
|
+
option :data, type: :string, desc: "JSON data file"
|
13
|
+
option :params, type: :string, default: "{}", desc: "JSON params"
|
14
|
+
|
15
|
+
example [
|
16
|
+
"getMonitors --data $json_data_file",
|
17
|
+
'getMonitors --params \'{"monitors": "123-456-789"}\''
|
18
|
+
]
|
19
|
+
|
20
|
+
def call(task:, data: nil, params: "{}", **)
|
21
|
+
task = task.to_sym
|
22
|
+
params = data.nil? ? JSON.parse(params) : parse_file(data)
|
23
|
+
puts UppityRobot::Client.new(task, params).execute.to_json
|
24
|
+
rescue JSON::ParserError => e
|
25
|
+
puts JSON.generate({ stat: "fail", error: "JSON parser #{e.message}" })
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse_file(file)
|
29
|
+
JSON.parse(File.read(File.expand_path(file)))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UppityRobot
|
4
|
+
module CLI
|
5
|
+
module Commands
|
6
|
+
module Monitors
|
7
|
+
# UppityRobot::CLI::Commands::Monitors::Create creates an HTTP monitor
|
8
|
+
class Create < Dry::CLI::Command
|
9
|
+
desc "Create a new HTTP monitor"
|
10
|
+
|
11
|
+
argument :name, required: true, desc: "The name for the monitor"
|
12
|
+
argument :url, required: true, desc: "The http/s url to monitor"
|
13
|
+
argument :contacts, required: true, desc: "The list of contact ids"
|
14
|
+
|
15
|
+
example [
|
16
|
+
"google https://www.google.com 1-2-3"
|
17
|
+
]
|
18
|
+
|
19
|
+
def call(name:, url:, contacts:, **)
|
20
|
+
sub_type = check_subtype(URI.parse(url))
|
21
|
+
|
22
|
+
data = {
|
23
|
+
friendly_name: name,
|
24
|
+
url: url,
|
25
|
+
type: UptimeRobot::Monitor::Type::HTTP,
|
26
|
+
sub_type: sub_type,
|
27
|
+
alert_contacts: contacts
|
28
|
+
}
|
29
|
+
|
30
|
+
response = UppityRobot::Client.new(:newMonitor, data).execute
|
31
|
+
puts response.to_json
|
32
|
+
rescue URI::InvalidURIError => e
|
33
|
+
puts JSON.generate({ stat: "fail", error: "URI parser #{e.message}" })
|
34
|
+
end
|
35
|
+
|
36
|
+
def check_subtype(uri)
|
37
|
+
if uri.instance_of?(URI::HTTP)
|
38
|
+
UptimeRobot::Monitor::SubType::HTTP
|
39
|
+
elsif uri.instance_of?(URI::HTTPS)
|
40
|
+
UptimeRobot::Monitor::SubType::HTTPS
|
41
|
+
else
|
42
|
+
abort({ stat: "fail",
|
43
|
+
error: "Monitor URL must be HTTP/S" }.to_json)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UppityRobot
|
4
|
+
module CLI
|
5
|
+
module Commands
|
6
|
+
module Monitors
|
7
|
+
# UppityRobot::CLI::Commands::Monitors::Delete delete a monitor
|
8
|
+
class Delete < Dry::CLI::Command
|
9
|
+
desc "Delete a monitor"
|
10
|
+
|
11
|
+
argument :field, required: true, values: %w[id name], desc: "The field used to target the monitor"
|
12
|
+
argument :value, required: true, type: Integer, desc: "The field value"
|
13
|
+
|
14
|
+
example [
|
15
|
+
"id 1",
|
16
|
+
"name aspace"
|
17
|
+
]
|
18
|
+
|
19
|
+
def call(field:, value:, **)
|
20
|
+
check_field(field)
|
21
|
+
monitor = find_monitor(field, value)
|
22
|
+
response = UppityRobot::Client.new(:deleteMonitor, { id: monitor["id"] }).execute
|
23
|
+
puts response.to_json
|
24
|
+
end
|
25
|
+
|
26
|
+
def check_field(field)
|
27
|
+
return if %w[id name].include? field
|
28
|
+
|
29
|
+
abort({ stat: "fail",
|
30
|
+
error: "Field not recognized, must be one of: [id, name]" }.to_json)
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_monitor(field, value)
|
34
|
+
params = {}
|
35
|
+
case field
|
36
|
+
when "id"
|
37
|
+
params[:monitors] = value
|
38
|
+
when "name"
|
39
|
+
params[:search] = value
|
40
|
+
end
|
41
|
+
UppityRobot::Client.new(:getMonitors, params).fetch
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UppityRobot
|
4
|
+
module CLI
|
5
|
+
module Commands
|
6
|
+
module Monitors
|
7
|
+
# UppityRobot::CLI::Commands::Monitors::Exec pauses or starts monitors
|
8
|
+
class Exec < Dry::CLI::Command
|
9
|
+
desc "Execute a pause or start request for monitors"
|
10
|
+
|
11
|
+
argument :task, required: true, values: %w[pause start], desc: "Pause or Start monitors"
|
12
|
+
argument :search, required: true, desc: "Search term for monitors"
|
13
|
+
|
14
|
+
option :filter, type: :string, default: "{}", desc: "Filter string for monitors"
|
15
|
+
|
16
|
+
example [
|
17
|
+
"pause aspace",
|
18
|
+
'start aspace --filter \'{"status": 0}\''
|
19
|
+
]
|
20
|
+
|
21
|
+
# rubocop:disable Metrics/AbcSize
|
22
|
+
def call(task:, search:, filter: "{}", **)
|
23
|
+
status = check_task(task)
|
24
|
+
filter = JSON.parse(filter)
|
25
|
+
filtered = { stat: "ok", total: 0, monitors: [] }
|
26
|
+
params = { search: search }
|
27
|
+
total = 0
|
28
|
+
|
29
|
+
UppityRobot::Client.new(:getMonitors, params).filter(filter).each do |m|
|
30
|
+
data = { id: m["id"], status: status }
|
31
|
+
filtered[:monitors] << UppityRobot::Client.new(:editMonitor, data).execute
|
32
|
+
total += 1
|
33
|
+
end
|
34
|
+
|
35
|
+
filtered[:total] = total
|
36
|
+
puts filtered.to_json
|
37
|
+
rescue JSON::ParserError => e
|
38
|
+
puts JSON.generate({ stat: "fail", error: "JSON parser #{e.message}" })
|
39
|
+
end
|
40
|
+
# rubocop:enable Metrics/AbcSize
|
41
|
+
|
42
|
+
def check_task(task)
|
43
|
+
case task.downcase
|
44
|
+
when "pause"
|
45
|
+
UptimeRobot::Monitor::Status::Paused
|
46
|
+
when "start"
|
47
|
+
UptimeRobot::Monitor::Status::NotCheckedYet
|
48
|
+
else
|
49
|
+
abort({ stat: "fail",
|
50
|
+
error: "Task not recognized, must be one of: [pause, start]" }.to_json)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|