uptimerobot_cmd 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -9
- data/lib/uptimerobot_cmd.rb +12 -45
- data/lib/uptimerobot_cmd/cli.rb +123 -56
- data/lib/uptimerobot_cmd/version.rb +1 -1
- data/uptimerobot_cmd.gemspec +0 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02f5f7e56ee4cff14f89ab3b86186f3d476142e8
|
4
|
+
data.tar.gz: 32d053ab4394994e861aac0bc26a3fcbf7e7eab3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 766f2ea20adbce5d7e2a3d5c1b1a1c29f47daa2e2813f1bca43b96c839c517032de86c6fc39c033a77afdeb2ad7146e9ea065876fec1cbf532b990c21e6ae1a2
|
7
|
+
data.tar.gz: 8f940133b8cd5bdd79e5b048e377c9ca6a86573e794cb63e2f49bee5a0760463d4c93c774099caec388b8aa9615dd3a0e4ab2dec89cf98d6eda058287b6814b2
|
data/README.md
CHANGED
@@ -36,13 +36,38 @@ All commands:
|
|
36
36
|
|
37
37
|
```bash
|
38
38
|
Commands:
|
39
|
-
uptimerobot_cmd
|
40
|
-
uptimerobot_cmd
|
41
|
-
uptimerobot_cmd
|
42
|
-
uptimerobot_cmd
|
43
|
-
uptimerobot_cmd
|
39
|
+
uptimerobot_cmd add # Add new service for monitoring
|
40
|
+
uptimerobot_cmd contacts # List current contacts for monitors
|
41
|
+
uptimerobot_cmd delete # Delete monitor
|
42
|
+
uptimerobot_cmd help [COMMAND] # Describe available commands or one specific command
|
43
|
+
uptimerobot_cmd list # List current monitors
|
44
|
+
uptimerobot_cmd search NAME or URL # Search in monitored services
|
45
|
+
|
46
|
+
Options:
|
47
|
+
[--color], [--no-color]
|
44
48
|
```
|
45
49
|
|
50
|
+
### add
|
51
|
+
|
52
|
+
You can set `UPTIMEROBOT_DEFAULT_CONTACT` environment variable for default
|
53
|
+
contact. This will help you to add more quicker. You don’t need to pass
|
54
|
+
`--contact` if you have `UPTIMEROBOT_DEFAULT_CONTACT` environment variable set.
|
55
|
+
|
56
|
+
```bash
|
57
|
+
# without UPTIMEROBOT_DEFAULT_CONTACT
|
58
|
+
uptimerobot_cmd add http://example.com --contact=1234567
|
59
|
+
uptimerobot_cmd add http://example.com --name=Example --contact=1234567
|
60
|
+
uptimerobot_cmd add http://example.com --name="Example Website" --contact=1234567
|
61
|
+
|
62
|
+
# with UPTIMEROBOT_DEFAULT_CONTACT
|
63
|
+
uptimerobot_cmd add http://example.com
|
64
|
+
uptimerobot_cmd add http://example.com --name=Example
|
65
|
+
uptimerobot_cmd add http://example.com --name="Example Website"
|
66
|
+
```
|
67
|
+
|
68
|
+
Will be more features for **add** soon!
|
69
|
+
|
70
|
+
|
46
71
|
## Development
|
47
72
|
|
48
73
|
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
@@ -65,10 +90,6 @@ bundle exec rake TEST=test/private_test.rb
|
|
65
90
|
Due to Security and Privacy, most of the test cases are private. You can find
|
66
91
|
example private tests under `test/` folder.
|
67
92
|
|
68
|
-
## TODO
|
69
|
-
|
70
|
-
- `add_new_monitor` will have more options/features...
|
71
|
-
|
72
93
|
## Contributing
|
73
94
|
|
74
95
|
Bug reports and pull requests are welcome on GitHub at
|
data/lib/uptimerobot_cmd.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'uptimerobot_cmd/version'
|
2
|
-
require 'colorize'
|
3
2
|
require 'httparty'
|
4
3
|
require 'terminal-table'
|
5
4
|
|
@@ -24,17 +23,18 @@ module UptimerobotCmd
|
|
24
23
|
def self.human_readable_status(status_code)
|
25
24
|
case status_code
|
26
25
|
when '0'
|
27
|
-
['paused', :
|
26
|
+
['paused', :black]
|
28
27
|
when '1'
|
29
28
|
['not checked yet', :black]
|
30
29
|
when '2'
|
31
30
|
['up', :yellow]
|
32
31
|
when '8'
|
33
|
-
['seems down', :
|
32
|
+
['seems down', :red]
|
34
33
|
when '9'
|
35
34
|
['down', :red]
|
36
35
|
end
|
37
36
|
end
|
37
|
+
|
38
38
|
def self.apikey_defined
|
39
39
|
raise ::UptimerobotCmd::APIKEYError, "Please set UPTIMEROBOT_APIKEY environment variable." unless ENV['UPTIMEROBOT_APIKEY']
|
40
40
|
true
|
@@ -54,53 +54,20 @@ module UptimerobotCmd
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
def self.
|
57
|
+
def self.search_in_monitors(input)
|
58
58
|
if ::UptimerobotCmd.apikey_defined
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
def self.list_alert_contacts
|
65
|
-
if ::UptimerobotCmd.apikey_defined
|
66
|
-
contacts = ::UptimerobotCmd.get_alert_contacts
|
67
|
-
rows = []
|
68
|
-
table_title = 'Listing %d contact(s)' % contacts.count
|
69
|
-
table_title = table_title.colorize(:yellow) if ENV['UPTIMEROBOT_COLORIZE']
|
70
|
-
contacts.each do |contact|
|
71
|
-
contact_id = contact['id']
|
72
|
-
contact_id = contact_id.colorize(:green) if ENV['UPTIMEROBOT_COLORIZE']
|
73
|
-
contact_info = contact['value']
|
74
|
-
contact_info = contact_info.colorize(:light_green) if ENV['UPTIMEROBOT_COLORIZE']
|
75
|
-
rows << [contact_id, contact_info]
|
76
|
-
end
|
77
|
-
Terminal::Table.new :headings => ['ID', 'Info'],
|
78
|
-
:rows => rows,
|
79
|
-
:title => table_title
|
59
|
+
monitors = ::UptimerobotCmd.get_monitors
|
60
|
+
monitors.select{|monitor|
|
61
|
+
monitor['friendlyname'] =~ /#{input}/i ||
|
62
|
+
monitor['url'] =~ /#{input}/i
|
63
|
+
}
|
80
64
|
end
|
81
65
|
end
|
82
66
|
|
83
|
-
def self.
|
67
|
+
def self.get_alert_contacts
|
84
68
|
if ::UptimerobotCmd.apikey_defined
|
85
|
-
|
86
|
-
|
87
|
-
table_title = table_title.colorize(:yellow) if ENV['UPTIMEROBOT_COLORIZE']
|
88
|
-
rows = []
|
89
|
-
monitors.each do |monitor|
|
90
|
-
monitor_id = monitor['id']
|
91
|
-
monitor_id = monitor_id.colorize(:green) if ENV['UPTIMEROBOT_COLORIZE']
|
92
|
-
status_data = ::UptimerobotCmd.human_readable_status(monitor['status'])
|
93
|
-
status = status_data[0]
|
94
|
-
status = status_data[0].colorize(status_data[1]) if ENV['UPTIMEROBOT_COLORIZE']
|
95
|
-
friendly_name = monitor['friendlyname']
|
96
|
-
friendly_name = friendly_name.colorize(:light_white) if ENV['UPTIMEROBOT_COLORIZE']
|
97
|
-
url = monitor['url']
|
98
|
-
url = url.colorize(:default) if ENV['UPTIMEROBOT_COLORIZE']
|
99
|
-
rows << [monitor_id, status, friendly_name, url]
|
100
|
-
end
|
101
|
-
Terminal::Table.new :headings => ['ID', 'Status', 'Name', 'Url'],
|
102
|
-
:rows => rows,
|
103
|
-
:title => table_title
|
69
|
+
response = HTTParty.get(::UptimerobotCmd.build_service_url(:get_alert_contacts))
|
70
|
+
response["alertcontacts"]["alertcontact"]
|
104
71
|
end
|
105
72
|
end
|
106
73
|
|
data/lib/uptimerobot_cmd/cli.rb
CHANGED
@@ -1,92 +1,159 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'uptimerobot_cmd'
|
3
|
+
require 'uri'
|
3
4
|
|
4
5
|
module UptimerobotCmd
|
5
6
|
class CLI < Thor
|
7
|
+
class_option :color, :type => :boolean
|
6
8
|
|
7
|
-
|
8
|
-
desc "list_monitors", "List current monitors"
|
9
|
+
desc "list", "List current monitors"
|
9
10
|
long_desc <<-LONGDESC
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
\x5
|
15
|
-
\x5> uptimerobot_cmd list_monitors
|
16
|
-
\x5> uptimerobot_cmd list_monitors --color
|
11
|
+
List current monitored services.\n
|
12
|
+
|
13
|
+
$ uptimerobot_cmd list\n
|
14
|
+
$ uptimerobot_cmd list --color
|
17
15
|
LONGDESC
|
18
|
-
def
|
16
|
+
def list
|
19
17
|
ENV['UPTIMEROBOT_COLORIZE'] = '1' if options[:color]
|
20
|
-
|
18
|
+
monitors = UptimerobotCmd.get_monitors
|
19
|
+
table_title = 'Monitoring %d site(s)' % monitors.count
|
20
|
+
puts print_monitors(monitors, table_title)
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
desc "list_contacts", "List current contacts for monitors"
|
23
|
+
desc "contacts", "List current contacts for monitors"
|
25
24
|
long_desc <<-LONGDESC
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
\x5> uptimerobot_cmd list_contacts --color
|
25
|
+
List available contact information.\n
|
26
|
+
|
27
|
+
$ uptimerobot_cmd contacts\n
|
28
|
+
$ uptimerobot_cmd contacts --color
|
31
29
|
LONGDESC
|
32
|
-
def
|
30
|
+
def contacts
|
33
31
|
ENV['UPTIMEROBOT_COLORIZE'] = '1' if options[:color]
|
34
|
-
|
32
|
+
contacts = UptimerobotCmd.get_alert_contacts
|
33
|
+
table_title = 'Listing %d contact(s)' % contacts.count
|
34
|
+
puts print_contacts(contacts, table_title)
|
35
35
|
end
|
36
36
|
|
37
|
-
option :
|
38
|
-
option :
|
39
|
-
|
40
|
-
desc "add_new_monitor", "Add new service for monitor"
|
37
|
+
option :contact, :banner => "<contact_id>"
|
38
|
+
option :name, :banner => "<friendly name>"
|
39
|
+
desc "add", "Add new service for monitoring"
|
41
40
|
long_desc <<-LONGDESC
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
You need to provide `--contact` option or must set `UPTIMEROBOT_DEFAULT_CONTACT`
|
42
|
+
environment variable.
|
43
|
+
|
44
|
+
$ uptimerobot_cmd add http://example.com --contact=1234567\n
|
45
|
+
$ uptimerobot_cmd add http://example.com --name=Example --contact=1234567\n
|
46
|
+
$ uptimerobot_cmd add http://example.com --name="Example Website" --contact=1234567
|
46
47
|
LONGDESC
|
47
|
-
def
|
48
|
+
def add(url)
|
49
|
+
ENV['UPTIMEROBOT_COLORIZE'] = '1' if options[:color]
|
50
|
+
|
48
51
|
my_options = {}
|
49
|
-
my_options[:monitor_url] =
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
my_options[:contact_id] = options[:contact_id] if options[:contact_id]
|
52
|
+
my_options[:monitor_url] = url if url =~ /\A#{URI::regexp}\z/
|
53
|
+
unless my_options[:monitor_url]
|
54
|
+
puts "Please enter valid url. Example: http://example.com or https://example.com"
|
55
|
+
exit
|
54
56
|
end
|
55
|
-
|
57
|
+
my_options[:contact_id] = options[:contact] || ENV['UPTIMEROBOT_DEFAULT_CONTACT'] || nil
|
56
58
|
unless my_options[:contact_id]
|
57
|
-
puts "Please
|
59
|
+
puts "Please set contact or set UPTIMEROBOT_DEFAULT_CONTACT environment variable"
|
58
60
|
exit
|
59
61
|
end
|
60
|
-
|
61
62
|
my_options[:friendly_name] = options[:name] if options[:name]
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
|
64
|
+
duplicate_entries = UptimerobotCmd.search_in_monitors(url)
|
65
|
+
if duplicate_entries.count > 0
|
66
|
+
table_title = 'Found duplicate %d monitor(s)' % duplicate_entries.count
|
67
|
+
puts print_monitors(duplicate_entries, table_title)
|
68
|
+
exit
|
69
|
+
else
|
70
|
+
begin
|
71
|
+
response = UptimerobotCmd.add_new_monitor(my_options)
|
72
|
+
if response[0] == 200 and response[1] == "ok"
|
73
|
+
message = "#{my_options[:monitor_url]} has been added."
|
74
|
+
else
|
75
|
+
message = "Error. Response code: #{response[0]}, status: #{response[1]}"
|
76
|
+
end
|
77
|
+
puts message
|
78
|
+
rescue UptimerobotCmd::OptionsError => e
|
79
|
+
puts e
|
68
80
|
end
|
69
|
-
puts message
|
70
|
-
rescue UptimerobotCmd::OptionsError => e
|
71
|
-
puts e
|
72
81
|
end
|
73
82
|
end
|
74
83
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
84
|
+
desc "delete", "Delete monitor"
|
85
|
+
def delete(input)
|
86
|
+
ENV['UPTIMEROBOT_COLORIZE'] = '1' if options[:color]
|
87
|
+
search = UptimerobotCmd.search_in_monitors(input)
|
88
|
+
delete_id = nil
|
89
|
+
if search.count > 1
|
90
|
+
puts print_monitors(search, 'Found %d monitor(s)' % search.count)
|
91
|
+
ask_delete_id = ask("Please enter ID number:").to_i
|
92
|
+
delete_id = ask_delete_id if ask_delete_id > 0
|
93
|
+
else
|
94
|
+
ask_user = "You are going to delete %{name} [%{url}]" % {
|
95
|
+
name: search.first['friendlyname'],
|
96
|
+
url: search.first['url'],
|
97
|
+
}
|
98
|
+
result = ask(ask_user, :limited_to => ['y', 'n'])
|
99
|
+
delete_id = search.first['id'] if result == 'y'
|
100
|
+
end
|
101
|
+
|
102
|
+
if delete_id
|
103
|
+
response = UptimerobotCmd.delete_monitor(monitor_id: delete_id)
|
82
104
|
if response[0] == 200 and response[1] == "ok"
|
83
|
-
message = "Site has been deleted."
|
105
|
+
message = "Site has been deleted."
|
84
106
|
else
|
85
107
|
message = "Error. Response code: #{response[0]}, status: #{response[1]}"
|
86
108
|
end
|
87
109
|
puts message
|
88
|
-
|
89
|
-
puts
|
110
|
+
else
|
111
|
+
puts "Delete canceled..."
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
desc "search NAME or URL", "Search in monitored services"
|
116
|
+
def search(input)
|
117
|
+
ENV['UPTIMEROBOT_COLORIZE'] = '1' if options[:color]
|
118
|
+
results = UptimerobotCmd.search_in_monitors(input)
|
119
|
+
table_title = 'Found %d monitor(s)' % results.count
|
120
|
+
puts print_monitors(results, table_title)
|
121
|
+
end
|
122
|
+
|
123
|
+
no_commands do
|
124
|
+
def print_contacts(contacts, table_title)
|
125
|
+
table_title = set_color(table_title, :yellow) if ENV['UPTIMEROBOT_COLORIZE']
|
126
|
+
rows = []
|
127
|
+
contacts.each do |contact|
|
128
|
+
contact_id = contact['id']
|
129
|
+
contact_id = set_color(contact_id, :green) if ENV['UPTIMEROBOT_COLORIZE']
|
130
|
+
contact_info = contact['value']
|
131
|
+
contact_info = set_color(contact_info, :white) if ENV['UPTIMEROBOT_COLORIZE']
|
132
|
+
rows << [contact_id, contact_info]
|
133
|
+
end
|
134
|
+
Terminal::Table.new :headings => ['ID', 'Info'],
|
135
|
+
:rows => rows,
|
136
|
+
:title => table_title
|
137
|
+
end
|
138
|
+
|
139
|
+
def print_monitors(monitors, table_title)
|
140
|
+
table_title = set_color(table_title, :yellow) if ENV['UPTIMEROBOT_COLORIZE']
|
141
|
+
rows = []
|
142
|
+
monitors.each do |monitor|
|
143
|
+
monitor_id = monitor['id']
|
144
|
+
monitor_id = set_color(monitor_id, :green) if ENV['UPTIMEROBOT_COLORIZE']
|
145
|
+
status_data = ::UptimerobotCmd.human_readable_status(monitor['status'])
|
146
|
+
status = status_data[0]
|
147
|
+
status = set_color(status, status_data[1], :bold) if ENV['UPTIMEROBOT_COLORIZE']
|
148
|
+
friendly_name = monitor['friendlyname']
|
149
|
+
friendly_name = set_color(friendly_name, :white) if ENV['UPTIMEROBOT_COLORIZE']
|
150
|
+
url = monitor['url']
|
151
|
+
url = set_color(url, :cyan) if ENV['UPTIMEROBOT_COLORIZE']
|
152
|
+
rows << [monitor_id, status, friendly_name, url]
|
153
|
+
end
|
154
|
+
Terminal::Table.new :headings => ['ID', 'Status', 'Name', 'Url'],
|
155
|
+
:rows => rows,
|
156
|
+
:title => table_title
|
90
157
|
end
|
91
158
|
end
|
92
159
|
|
data/uptimerobot_cmd.gemspec
CHANGED
@@ -25,7 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'minitest-reporters', '~> 1.1', '>= 1.1.10'
|
26
26
|
|
27
27
|
spec.add_runtime_dependency 'httparty', '~> 0.13.7'
|
28
|
-
spec.add_runtime_dependency 'colorize', '~> 0.8.1'
|
29
28
|
spec.add_runtime_dependency 'terminal-table', '~> 1.6'
|
30
29
|
spec.add_runtime_dependency 'thor', '~> 0.19.1'
|
31
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uptimerobot_cmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uğur Özyılmazel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,20 +86,6 @@ dependencies:
|
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: 0.13.7
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: colorize
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: 0.8.1
|
96
|
-
type: :runtime
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: 0.8.1
|
103
89
|
- !ruby/object:Gem::Dependency
|
104
90
|
name: terminal-table
|
105
91
|
requirement: !ruby/object:Gem::Requirement
|