1and1 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/1and1-1.0.gem +0 -0
- data/1and1.gemspec +20 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/README.md +499 -0
- data/docs/reference.md +2447 -0
- data/examples/dvd_examples.rb +15 -0
- data/examples/example_app.rb +100 -0
- data/examples/firewall_examples.rb +137 -0
- data/examples/image_examples.rb +48 -0
- data/examples/load_balancer_examples.rb +145 -0
- data/examples/log_examples.rb +15 -0
- data/examples/monitoring_center_examples.rb +15 -0
- data/examples/monitoring_policy_examples.rb +343 -0
- data/examples/private_network_examples.rb +86 -0
- data/examples/public_ip_examples.rb +42 -0
- data/examples/role_examples.rb +113 -0
- data/examples/server_appliance_examples.rb +15 -0
- data/examples/server_examples.rb +438 -0
- data/examples/shared_storage_examples.rb +108 -0
- data/examples/usage_examples.rb +6 -0
- data/examples/user_examples.rb +113 -0
- data/examples/vpn_examples.rb +56 -0
- data/lib/1and1/datacenter.rb +73 -0
- data/lib/1and1/dvd.rb +73 -0
- data/lib/1and1/firewall.rb +427 -0
- data/lib/1and1/image.rb +231 -0
- data/lib/1and1/load_balancer.rb +448 -0
- data/lib/1and1/log.rb +77 -0
- data/lib/1and1/monitoring_center.rb +84 -0
- data/lib/1and1/monitoring_policy.rb +598 -0
- data/lib/1and1/oneandone.rb +57 -0
- data/lib/1and1/ping.rb +41 -0
- data/lib/1and1/ping_auth.rb +41 -0
- data/lib/1and1/pricing.rb +41 -0
- data/lib/1and1/private_network.rb +333 -0
- data/lib/1and1/public_ip.rb +192 -0
- data/lib/1and1/role.rb +381 -0
- data/lib/1and1/server.rb +1208 -0
- data/lib/1and1/server_appliance.rb +73 -0
- data/lib/1and1/shared_storage.rb +379 -0
- data/lib/1and1/usage.rb +58 -0
- data/lib/1and1/user.rb +374 -0
- data/lib/1and1/vpn.rb +249 -0
- data/lib/oneandone.rb +27 -0
- data/sphinx/Makefile +192 -0
- data/sphinx/_build/doctrees/dvds.doctree +0 -0
- data/sphinx/_build/doctrees/environment.pickle +0 -0
- data/sphinx/_build/doctrees/firewalls.doctree +0 -0
- data/sphinx/_build/doctrees/images.doctree +0 -0
- data/sphinx/_build/doctrees/index.doctree +0 -0
- data/sphinx/_build/doctrees/load_balancers.doctree +0 -0
- data/sphinx/_build/doctrees/logs.doctree +0 -0
- data/sphinx/_build/doctrees/monitoring_center.doctree +0 -0
- data/sphinx/_build/doctrees/monitoring_policies.doctree +0 -0
- data/sphinx/_build/doctrees/private_networks.doctree +0 -0
- data/sphinx/_build/doctrees/public_ips.doctree +0 -0
- data/sphinx/_build/doctrees/server_appliances.doctree +0 -0
- data/sphinx/_build/doctrees/servers.doctree +0 -0
- data/sphinx/_build/doctrees/shared_storages.doctree +0 -0
- data/sphinx/_build/doctrees/usages.doctree +0 -0
- data/sphinx/_build/doctrees/users.doctree +0 -0
- data/sphinx/_build/html/.buildinfo +4 -0
- data/sphinx/_build/html/_sources/dvds.txt +42 -0
- data/sphinx/_build/html/_sources/firewalls.txt +189 -0
- data/sphinx/_build/html/_sources/images.txt +101 -0
- data/sphinx/_build/html/_sources/index.txt +499 -0
- data/sphinx/_build/html/_sources/load_balancers.txt +231 -0
- data/sphinx/_build/html/_sources/logs.txt +55 -0
- data/sphinx/_build/html/_sources/monitoring_center.txt +55 -0
- data/sphinx/_build/html/_sources/monitoring_policies.txt +288 -0
- data/sphinx/_build/html/_sources/private_networks.txt +146 -0
- data/sphinx/_build/html/_sources/public_ips.txt +78 -0
- data/sphinx/_build/html/_sources/server_appliances.txt +42 -0
- data/sphinx/_build/html/_sources/servers.txt +630 -0
- data/sphinx/_build/html/_sources/shared_storages.txt +160 -0
- data/sphinx/_build/html/_sources/usages.txt +45 -0
- data/sphinx/_build/html/_sources/users.txt +172 -0
- data/sphinx/_build/html/_static/ajax-loader.gif +0 -0
- data/sphinx/_build/html/_static/alabaster.css +585 -0
- data/sphinx/_build/html/_static/basic.css +599 -0
- data/sphinx/_build/html/_static/comment-bright.png +0 -0
- data/sphinx/_build/html/_static/comment-close.png +0 -0
- data/sphinx/_build/html/_static/comment.png +0 -0
- data/sphinx/_build/html/_static/doctools.js +263 -0
- data/sphinx/_build/html/_static/down-pressed.png +0 -0
- data/sphinx/_build/html/_static/down.png +0 -0
- data/sphinx/_build/html/_static/file.png +0 -0
- data/sphinx/_build/html/_static/jquery-1.11.1.js +10308 -0
- data/sphinx/_build/html/_static/jquery.js +4 -0
- data/sphinx/_build/html/_static/minus.png +0 -0
- data/sphinx/_build/html/_static/plus.png +0 -0
- data/sphinx/_build/html/_static/pygments.css +63 -0
- data/sphinx/_build/html/_static/searchtools.js +651 -0
- data/sphinx/_build/html/_static/underscore-1.3.1.js +999 -0
- data/sphinx/_build/html/_static/underscore.js +31 -0
- data/sphinx/_build/html/_static/up-pressed.png +0 -0
- data/sphinx/_build/html/_static/up.png +0 -0
- data/sphinx/_build/html/_static/websupport.js +808 -0
- data/sphinx/_build/html/dvds.html +151 -0
- data/sphinx/_build/html/firewalls.html +397 -0
- data/sphinx/_build/html/genindex.html +114 -0
- data/sphinx/_build/html/images.html +236 -0
- data/sphinx/_build/html/index.html +571 -0
- data/sphinx/_build/html/load_balancers.html +409 -0
- data/sphinx/_build/html/logs.html +160 -0
- data/sphinx/_build/html/monitoring_center.html +160 -0
- data/sphinx/_build/html/monitoring_policies.html +530 -0
- data/sphinx/_build/html/objects.inv +0 -0
- data/sphinx/_build/html/private_networks.html +316 -0
- data/sphinx/_build/html/public_ips.html +215 -0
- data/sphinx/_build/html/rb-modindex.html +106 -0
- data/sphinx/_build/html/search.html +99 -0
- data/sphinx/_build/html/searchindex.js +1 -0
- data/sphinx/_build/html/server_appliances.html +153 -0
- data/sphinx/_build/html/servers.html +994 -0
- data/sphinx/_build/html/shared_storages.html +349 -0
- data/sphinx/_build/html/usages.html +140 -0
- data/sphinx/_build/html/users.html +363 -0
- data/sphinx/conf.py +287 -0
- data/sphinx/dvds.rst +42 -0
- data/sphinx/firewalls.rst +189 -0
- data/sphinx/images.rst +101 -0
- data/sphinx/index.rst +499 -0
- data/sphinx/load_balancers.rst +231 -0
- data/sphinx/logs.rst +55 -0
- data/sphinx/make.bat +263 -0
- data/sphinx/monitoring_center.rst +55 -0
- data/sphinx/monitoring_policies.rst +288 -0
- data/sphinx/private_networks.rst +146 -0
- data/sphinx/public_ips.rst +78 -0
- data/sphinx/server_appliances.rst +42 -0
- data/sphinx/servers.rst +630 -0
- data/sphinx/shared_storages.rst +160 -0
- data/sphinx/usages.rst +45 -0
- data/sphinx/users.rst +172 -0
- data/test/mock-api/add-firewall.json +66 -0
- data/test/mock-api/add-hdd.json +49 -0
- data/test/mock-api/add-lb.json +71 -0
- data/test/mock-api/add-new-ip.json +18 -0
- data/test/mock-api/add-pn.json +66 -0
- data/test/mock-api/add-port-mp.json +81 -0
- data/test/mock-api/add-process-mp.json +20 -0
- data/test/mock-api/add-rule-fp.json +33 -0
- data/test/mock-api/add-rule-lb.json +40 -0
- data/test/mock-api/add-server-ip.json +66 -0
- data/test/mock-api/add-server-mp.json +66 -0
- data/test/mock-api/assign-ip-fp.json +32 -0
- data/test/mock-api/assign-server-lb.json +39 -0
- data/test/mock-api/attach-server-pn.json +14 -0
- data/test/mock-api/attach-server-storage.json +24 -0
- data/test/mock-api/change-api-key.json +15 -0
- data/test/mock-api/change-password.json +5 -0
- data/test/mock-api/change-server-status.json +70 -0
- data/test/mock-api/clone-server.json +29 -0
- data/test/mock-api/create-fp.json +26 -0
- data/test/mock-api/create-image.json +30 -0
- data/test/mock-api/create-lb.json +33 -0
- data/test/mock-api/create-mp.json +81 -0
- data/test/mock-api/create-pn.json +11 -0
- data/test/mock-api/create-public-ip.json +10 -0
- data/test/mock-api/create-server.json +34 -0
- data/test/mock-api/create-snapshot.json +74 -0
- data/test/mock-api/create-storage.json +13 -0
- data/test/mock-api/create-user.json +14 -0
- data/test/mock-api/delete-fp.json +26 -0
- data/test/mock-api/delete-image.json +26 -0
- data/test/mock-api/delete-ip.json +15 -0
- data/test/mock-api/delete-lb.json +33 -0
- data/test/mock-api/delete-mp.json +71 -0
- data/test/mock-api/delete-pn.json +11 -0
- data/test/mock-api/delete-public-ip.json +10 -0
- data/test/mock-api/delete-rule-fp.json +26 -0
- data/test/mock-api/delete-server.json +50 -0
- data/test/mock-api/delete-snapshot.json +74 -0
- data/test/mock-api/delete-storage.json +24 -0
- data/test/mock-api/delete-user.json +15 -0
- data/test/mock-api/detach-server-lb.json +33 -0
- data/test/mock-api/detach-server-mp.json +65 -0
- data/test/mock-api/detach-server-storage.json +19 -0
- data/test/mock-api/edit-image.json +26 -0
- data/test/mock-api/eject-dvd.json +66 -0
- data/test/mock-api/fixed-server-flavors.json +70 -0
- data/test/mock-api/get-appliance.json +16 -0
- data/test/mock-api/get-dvd.json +9 -0
- data/test/mock-api/get-firewall.json +26 -0
- data/test/mock-api/get-fixed-server.json +17 -0
- data/test/mock-api/get-fp-rule.json +7 -0
- data/test/mock-api/get-hardware.json +13 -0
- data/test/mock-api/get-hdd.json +5 -0
- data/test/mock-api/get-image.json +26 -0
- data/test/mock-api/get-lb-rule.json +7 -0
- data/test/mock-api/get-lb-server.json +5 -0
- data/test/mock-api/get-load-balancer.json +33 -0
- data/test/mock-api/get-log.json +23 -0
- data/test/mock-api/get-monitoring-center.json +161 -0
- data/test/mock-api/get-mp-port.json +7 -0
- data/test/mock-api/get-mp-process.json +6 -0
- data/test/mock-api/get-mp-server.json +4 -0
- data/test/mock-api/get-mp.json +65 -0
- data/test/mock-api/get-pn-server.json +4 -0
- data/test/mock-api/get-private-network.json +20 -0
- data/test/mock-api/get-public-ip.json +10 -0
- data/test/mock-api/get-server-dvd.json +4 -0
- data/test/mock-api/get-server-image.json +4 -0
- data/test/mock-api/get-server-ip-fp.json +4 -0
- data/test/mock-api/get-server-ip.json +8 -0
- data/test/mock-api/get-server-pn.json +16 -0
- data/test/mock-api/get-server-status.json +4 -0
- data/test/mock-api/get-server-storage.json +5 -0
- data/test/mock-api/get-server.json +44 -0
- data/test/mock-api/get-storage.json +19 -0
- data/test/mock-api/get-usage.json +161 -0
- data/test/mock-api/get-user-api-key.json +3 -0
- data/test/mock-api/get-user-api.json +7 -0
- data/test/mock-api/get-user.json +15 -0
- data/test/mock-api/list-appliances.json +66 -0
- data/test/mock-api/list-credentials.json +5 -0
- data/test/mock-api/list-dvds.json +128 -0
- data/test/mock-api/list-firewalls.json +54 -0
- data/test/mock-api/list-fp-rules.json +16 -0
- data/test/mock-api/list-hdds.json +7 -0
- data/test/mock-api/list-images.json +54 -0
- data/test/mock-api/list-lb-rules.json +16 -0
- data/test/mock-api/list-lb-servers.json +12 -0
- data/test/mock-api/list-load-balancers.json +68 -0
- data/test/mock-api/list-logs.json +49 -0
- data/test/mock-api/list-monitoring-center-usages.json +90 -0
- data/test/mock-api/list-mp-ports.json +16 -0
- data/test/mock-api/list-mp-processes.json +14 -0
- data/test/mock-api/list-mp-servers.json +10 -0
- data/test/mock-api/list-mps.json +152 -0
- data/test/mock-api/list-pn-servers.json +10 -0
- data/test/mock-api/list-private-networks.json +24 -0
- data/test/mock-api/list-public-ips.json +44 -0
- data/test/mock-api/list-server-fps.json +4 -0
- data/test/mock-api/list-server-ips-fp.json +7 -0
- data/test/mock-api/list-server-ips.json +10 -0
- data/test/mock-api/list-server-lbs.json +6 -0
- data/test/mock-api/list-server-pns.json +6 -0
- data/test/mock-api/list-servers.json +66 -0
- data/test/mock-api/list-snapshots.json +7 -0
- data/test/mock-api/list-storages.json +47 -0
- data/test/mock-api/list-usages.json +144 -0
- data/test/mock-api/list-user-ips.json +5 -0
- data/test/mock-api/list-users.json +31 -0
- data/test/mock-api/load-dvd.json +63 -0
- data/test/mock-api/modify-fp.json +26 -0
- data/test/mock-api/modify-lb.json +33 -0
- data/test/mock-api/modify-mp.json +81 -0
- data/test/mock-api/modify-pn.json +20 -0
- data/test/mock-api/modify-port-mp.json +81 -0
- data/test/mock-api/modify-process-mp.json +73 -0
- data/test/mock-api/modify-public-ip.json +10 -0
- data/test/mock-api/modify-server-hardware.json +44 -0
- data/test/mock-api/modify-server-hdd.json +54 -0
- data/test/mock-api/modify-server.json +44 -0
- data/test/mock-api/modify-storage.json +19 -0
- data/test/mock-api/modify-user-api.json +15 -0
- data/test/mock-api/modify-user.json +15 -0
- data/test/mock-api/reinstall-image.json +52 -0
- data/test/mock-api/remove-firewall-policy.json +26 -0
- data/test/mock-api/remove-hdd.json +54 -0
- data/test/mock-api/remove-ip-fp.json +26 -0
- data/test/mock-api/remove-lb.json +66 -0
- data/test/mock-api/remove-pn.json +71 -0
- data/test/mock-api/remove-port-mp.json +73 -0
- data/test/mock-api/remove-process-mp.json +66 -0
- data/test/mock-api/remove-rule-lb.json +33 -0
- data/test/mock-api/remove-server-ip.json +58 -0
- data/test/mock-api/remove-server-pn.json +16 -0
- data/test/mock-api/restore-snapshot.json +55 -0
- data/test/mock-api/storage-servers.json +12 -0
- data/test/test_mock_dvd.rb +55 -0
- data/test/test_mock_firewall.rb +309 -0
- data/test/test_mock_image.rb +123 -0
- data/test/test_mock_load_balancer.rb +312 -0
- data/test/test_mock_log.rb +55 -0
- data/test/test_mock_monitoring_center.rb +55 -0
- data/test/test_mock_monitoring_policy.rb +587 -0
- data/test/test_mock_private_network.rb +206 -0
- data/test/test_mock_public_ip.rb +118 -0
- data/test/test_mock_server.rb +929 -0
- data/test/test_mock_server_appliance.rb +55 -0
- data/test/test_mock_shared_storage.rb +256 -0
- data/test/test_mock_usage.rb +34 -0
- data/test/test_mock_user.rb +270 -0
- metadata +360 -0
data/lib/1and1/log.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
module OneAndOne
|
2
|
+
|
3
|
+
|
4
|
+
class Log
|
5
|
+
|
6
|
+
|
7
|
+
def initialize(test: false)
|
8
|
+
|
9
|
+
# Check if hitting mock api or live api
|
10
|
+
if test
|
11
|
+
@connection = Excon.new($base_url, :mock => true)
|
12
|
+
else
|
13
|
+
@connection = Excon.new($base_url)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil,
|
20
|
+
period: 'LAST_24H', start_date: nil, end_date: nil)
|
21
|
+
|
22
|
+
# Build hash for query parameters
|
23
|
+
keyword_args = {
|
24
|
+
:page => page,
|
25
|
+
:per_page => per_page,
|
26
|
+
:sort => sort,
|
27
|
+
:q => q,
|
28
|
+
:fields => fields,
|
29
|
+
:period => period,
|
30
|
+
:start_date => start_date,
|
31
|
+
:end_date => end_date
|
32
|
+
}
|
33
|
+
|
34
|
+
# Clean out null query parameters
|
35
|
+
params = OneAndOne.clean_hash(keyword_args)
|
36
|
+
|
37
|
+
# Build URL
|
38
|
+
path = OneAndOne.build_url('/logs')
|
39
|
+
|
40
|
+
# Perform request
|
41
|
+
response = @connection.request(:method => :get,
|
42
|
+
:path => path,
|
43
|
+
:headers => $header,
|
44
|
+
:query => params)
|
45
|
+
|
46
|
+
# Check response status
|
47
|
+
OneAndOne.check_response(response.body, response.status)
|
48
|
+
|
49
|
+
#JSON-ify the response string
|
50
|
+
JSON.parse(response.body)
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
def get(log_id: nil)
|
56
|
+
|
57
|
+
# Build URL
|
58
|
+
path = OneAndOne.build_url("/logs/#{log_id}")
|
59
|
+
|
60
|
+
# Perform request
|
61
|
+
response = @connection.request(:method => :get,
|
62
|
+
:path => path,
|
63
|
+
:headers => $header)
|
64
|
+
|
65
|
+
# Check response status
|
66
|
+
OneAndOne.check_response(response.body, response.status)
|
67
|
+
|
68
|
+
#JSON-ify the response string
|
69
|
+
JSON.parse(response.body)
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module OneAndOne
|
2
|
+
|
3
|
+
|
4
|
+
class MonitoringCenter
|
5
|
+
|
6
|
+
|
7
|
+
def initialize(test: false)
|
8
|
+
|
9
|
+
# Check if hitting mock api or live api
|
10
|
+
if test
|
11
|
+
@connection = Excon.new($base_url, :mock => true)
|
12
|
+
else
|
13
|
+
@connection = Excon.new($base_url)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil)
|
20
|
+
|
21
|
+
# Build hash for query parameters
|
22
|
+
keyword_args = {
|
23
|
+
:page => page,
|
24
|
+
:per_page => per_page,
|
25
|
+
:sort => sort,
|
26
|
+
:q => q,
|
27
|
+
:fields => fields
|
28
|
+
}
|
29
|
+
|
30
|
+
# Clean out null query parameters
|
31
|
+
params = OneAndOne.clean_hash(keyword_args)
|
32
|
+
|
33
|
+
# Build URL
|
34
|
+
path = OneAndOne.build_url('/monitoring_center')
|
35
|
+
|
36
|
+
# Perform request
|
37
|
+
response = @connection.request(:method => :get,
|
38
|
+
:path => path,
|
39
|
+
:headers => $header,
|
40
|
+
:query => params)
|
41
|
+
|
42
|
+
# Check response status
|
43
|
+
OneAndOne.check_response(response.body, response.status)
|
44
|
+
|
45
|
+
#JSON-ify the response string
|
46
|
+
JSON.parse(response.body)
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def get(server_id: nil, period: nil, start_date: nil, end_date: nil)
|
52
|
+
|
53
|
+
# Build hash for query parameters
|
54
|
+
keyword_args = {
|
55
|
+
:period => period,
|
56
|
+
:start_date => start_date,
|
57
|
+
:end_date => end_date
|
58
|
+
}
|
59
|
+
|
60
|
+
# Clean out null query parameters
|
61
|
+
params = OneAndOne.clean_hash(keyword_args)
|
62
|
+
|
63
|
+
# Build URL
|
64
|
+
path = OneAndOne.build_url("/monitoring_center/#{server_id}")
|
65
|
+
|
66
|
+
# Perform request
|
67
|
+
response = @connection.request(:method => :get,
|
68
|
+
:path => path,
|
69
|
+
:headers => $header,
|
70
|
+
:query => params)
|
71
|
+
|
72
|
+
# Check response status
|
73
|
+
OneAndOne.check_response(response.body, response.status)
|
74
|
+
|
75
|
+
#JSON-ify the response string
|
76
|
+
JSON.parse(response.body)
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,598 @@
|
|
1
|
+
module OneAndOne
|
2
|
+
|
3
|
+
|
4
|
+
class MonitoringPolicy
|
5
|
+
|
6
|
+
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :specs
|
9
|
+
|
10
|
+
|
11
|
+
def initialize(test: false)
|
12
|
+
@id = nil
|
13
|
+
@specs = nil
|
14
|
+
|
15
|
+
# Check if hitting mock api or live api
|
16
|
+
if test
|
17
|
+
@connection = Excon.new($base_url, :mock => true)
|
18
|
+
else
|
19
|
+
@connection = Excon.new($base_url)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil)
|
26
|
+
|
27
|
+
# Build hash for query parameters
|
28
|
+
keyword_args = {
|
29
|
+
:page => page,
|
30
|
+
:per_page => per_page,
|
31
|
+
:sort => sort,
|
32
|
+
:q => q,
|
33
|
+
:fields => fields
|
34
|
+
}
|
35
|
+
|
36
|
+
# Clean out null query parameters
|
37
|
+
params = OneAndOne.clean_hash(keyword_args)
|
38
|
+
|
39
|
+
# Build URL
|
40
|
+
path = OneAndOne.build_url('/monitoring_policies')
|
41
|
+
|
42
|
+
# Perform request
|
43
|
+
response = @connection.request(:method => :get,
|
44
|
+
:path => path,
|
45
|
+
:headers => $header,
|
46
|
+
:query => params)
|
47
|
+
|
48
|
+
# Check response status
|
49
|
+
OneAndOne.check_response(response.body, response.status)
|
50
|
+
|
51
|
+
#JSON-ify the response string
|
52
|
+
JSON.parse(response.body)
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def create(name: nil, description: nil, email: nil, agent: nil,
|
58
|
+
thresholds: nil, ports: nil, processes: nil)
|
59
|
+
|
60
|
+
# Build POST body
|
61
|
+
new_monitoring_policy = {
|
62
|
+
'name' => name,
|
63
|
+
'description' => description,
|
64
|
+
'email' => email,
|
65
|
+
'agent' => agent,
|
66
|
+
'thresholds' => thresholds,
|
67
|
+
'ports' => ports,
|
68
|
+
'processes' => processes
|
69
|
+
}
|
70
|
+
|
71
|
+
# Clean out null keys in POST body
|
72
|
+
body = OneAndOne.clean_hash(new_monitoring_policy)
|
73
|
+
|
74
|
+
# Stringify the POST body
|
75
|
+
string_body = body.to_json
|
76
|
+
|
77
|
+
# Build URL
|
78
|
+
path = OneAndOne.build_url('/monitoring_policies')
|
79
|
+
|
80
|
+
# Perform request
|
81
|
+
response = @connection.request(:method => :post,
|
82
|
+
:path => path,
|
83
|
+
:headers => $header,
|
84
|
+
:body => string_body)
|
85
|
+
|
86
|
+
# Check response status
|
87
|
+
OneAndOne.check_response(response.body, response.status)
|
88
|
+
|
89
|
+
#JSON-ify the response string
|
90
|
+
json = JSON.parse(response.body)
|
91
|
+
|
92
|
+
# Save new monitoring policy ID to MonitoringPolicy instance
|
93
|
+
@id = json['id']
|
94
|
+
@specs = json
|
95
|
+
|
96
|
+
# If all good, return JSON
|
97
|
+
json
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
def get(monitoring_policy_id: @id)
|
103
|
+
|
104
|
+
# If user passed in monitoring policy ID, reassign
|
105
|
+
@id = monitoring_policy_id
|
106
|
+
|
107
|
+
# Build URL
|
108
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}")
|
109
|
+
|
110
|
+
# Perform request
|
111
|
+
response = @connection.request(:method => :get,
|
112
|
+
:path => path,
|
113
|
+
:headers => $header)
|
114
|
+
|
115
|
+
# Check response status
|
116
|
+
OneAndOne.check_response(response.body, response.status)
|
117
|
+
|
118
|
+
#JSON-ify the response string
|
119
|
+
json = JSON.parse(response.body)
|
120
|
+
|
121
|
+
# Reload specs attribute
|
122
|
+
@specs = json
|
123
|
+
|
124
|
+
# If all good, return JSON
|
125
|
+
json
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
def modify(monitoring_policy_id: @id, name: nil, description: nil,
|
131
|
+
email: nil, thresholds: nil)
|
132
|
+
|
133
|
+
# If user passed in monitoring policy ID, reassign
|
134
|
+
@id = monitoring_policy_id
|
135
|
+
|
136
|
+
# Build PUT body
|
137
|
+
modified_mp = {
|
138
|
+
'name' => name,
|
139
|
+
'description' => description,
|
140
|
+
'email' => email,
|
141
|
+
'thresholds' => thresholds
|
142
|
+
}
|
143
|
+
|
144
|
+
# Clean out null keys in PUT body
|
145
|
+
body = OneAndOne.clean_hash(modified_mp)
|
146
|
+
|
147
|
+
# Stringify the POST body
|
148
|
+
string_body = body.to_json
|
149
|
+
|
150
|
+
# Build URL
|
151
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}")
|
152
|
+
|
153
|
+
# Perform request
|
154
|
+
response = @connection.request(:method => :put,
|
155
|
+
:path => path,
|
156
|
+
:headers => $header,
|
157
|
+
:body => string_body)
|
158
|
+
|
159
|
+
# Check response status
|
160
|
+
OneAndOne.check_response(response.body, response.status)
|
161
|
+
|
162
|
+
#JSON-ify the response string
|
163
|
+
JSON.parse(response.body)
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
def delete(monitoring_policy_id: @id)
|
169
|
+
|
170
|
+
# If user passed in monitoring policy ID, reassign
|
171
|
+
@id = monitoring_policy_id
|
172
|
+
|
173
|
+
# Build URL
|
174
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}")
|
175
|
+
|
176
|
+
# Perform request
|
177
|
+
response = @connection.request(:method => :delete,
|
178
|
+
:path => path,
|
179
|
+
:headers => $header)
|
180
|
+
|
181
|
+
# Check response status
|
182
|
+
OneAndOne.check_response(response.body, response.status)
|
183
|
+
|
184
|
+
#JSON-ify the response string
|
185
|
+
JSON.parse(response.body)
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
def ports(monitoring_policy_id: @id)
|
191
|
+
|
192
|
+
# If user passed in monitoring policy ID, reassign
|
193
|
+
@id = monitoring_policy_id
|
194
|
+
|
195
|
+
# Build URL
|
196
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/ports")
|
197
|
+
|
198
|
+
# Perform request
|
199
|
+
response = @connection.request(:method => :get,
|
200
|
+
:path => path,
|
201
|
+
:headers => $header)
|
202
|
+
|
203
|
+
# Check response status
|
204
|
+
OneAndOne.check_response(response.body, response.status)
|
205
|
+
|
206
|
+
#JSON-ify the response string
|
207
|
+
JSON.parse(response.body)
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
def add_ports(monitoring_policy_id: @id, ports: nil)
|
213
|
+
|
214
|
+
# If user passed in monitoring policy ID, reassign
|
215
|
+
@id = monitoring_policy_id
|
216
|
+
|
217
|
+
# Build POST body
|
218
|
+
new_ports = {
|
219
|
+
'ports' => ports
|
220
|
+
}
|
221
|
+
|
222
|
+
# Clean out null keys in POST body
|
223
|
+
body = OneAndOne.clean_hash(new_ports)
|
224
|
+
|
225
|
+
# Stringify the POST body
|
226
|
+
string_body = body.to_json
|
227
|
+
|
228
|
+
# Build URL
|
229
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/ports")
|
230
|
+
|
231
|
+
# Perform request
|
232
|
+
response = @connection.request(:method => :post,
|
233
|
+
:path => path,
|
234
|
+
:headers => $header,
|
235
|
+
:body => string_body)
|
236
|
+
|
237
|
+
# Check response status
|
238
|
+
OneAndOne.check_response(response.body, response.status)
|
239
|
+
|
240
|
+
#JSON-ify the response string
|
241
|
+
JSON.parse(response.body)
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
def port(monitoring_policy_id: @id, port_id: nil)
|
247
|
+
|
248
|
+
# If user passed in monitoring policy ID, reassign
|
249
|
+
@id = monitoring_policy_id
|
250
|
+
|
251
|
+
# Build URL
|
252
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/ports/#{port_id}")
|
253
|
+
|
254
|
+
# Perform request
|
255
|
+
response = @connection.request(:method => :get,
|
256
|
+
:path => path,
|
257
|
+
:headers => $header)
|
258
|
+
|
259
|
+
# Check response status
|
260
|
+
OneAndOne.check_response(response.body, response.status)
|
261
|
+
|
262
|
+
#JSON-ify the response string
|
263
|
+
JSON.parse(response.body)
|
264
|
+
|
265
|
+
end
|
266
|
+
|
267
|
+
|
268
|
+
def modify_port(monitoring_policy_id: @id, port_id: nil, new_port: nil)
|
269
|
+
|
270
|
+
# If user passed in monitoring policy ID, reassign
|
271
|
+
@id = monitoring_policy_id
|
272
|
+
|
273
|
+
# Build PUT body
|
274
|
+
modified_port = {
|
275
|
+
'ports' => new_port
|
276
|
+
}
|
277
|
+
|
278
|
+
# Stringify the POST body
|
279
|
+
string_body = modified_port.to_json
|
280
|
+
|
281
|
+
# Build URL
|
282
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/ports/#{port_id}")
|
283
|
+
|
284
|
+
# Perform request
|
285
|
+
response = @connection.request(:method => :put,
|
286
|
+
:path => path,
|
287
|
+
:headers => $header,
|
288
|
+
:body => string_body)
|
289
|
+
|
290
|
+
# Check response status
|
291
|
+
OneAndOne.check_response(response.body, response.status)
|
292
|
+
|
293
|
+
#JSON-ify the response string
|
294
|
+
JSON.parse(response.body)
|
295
|
+
|
296
|
+
end
|
297
|
+
|
298
|
+
|
299
|
+
def delete_port(monitoring_policy_id: @id, port_id: nil)
|
300
|
+
|
301
|
+
# If user passed in monitoring policy ID, reassign
|
302
|
+
@id = monitoring_policy_id
|
303
|
+
|
304
|
+
# Build URL
|
305
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/ports/#{port_id}")
|
306
|
+
|
307
|
+
# Perform request
|
308
|
+
response = @connection.request(:method => :delete,
|
309
|
+
:path => path,
|
310
|
+
:headers => $header)
|
311
|
+
|
312
|
+
# Check response status
|
313
|
+
OneAndOne.check_response(response.body, response.status)
|
314
|
+
|
315
|
+
#JSON-ify the response string
|
316
|
+
JSON.parse(response.body)
|
317
|
+
|
318
|
+
end
|
319
|
+
|
320
|
+
|
321
|
+
def processes(monitoring_policy_id: @id)
|
322
|
+
|
323
|
+
# If user passed in monitoring policy ID, reassign
|
324
|
+
@id = monitoring_policy_id
|
325
|
+
|
326
|
+
# Build URL
|
327
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/processes")
|
328
|
+
|
329
|
+
# Perform request
|
330
|
+
response = @connection.request(:method => :get,
|
331
|
+
:path => path,
|
332
|
+
:headers => $header)
|
333
|
+
|
334
|
+
# Check response status
|
335
|
+
OneAndOne.check_response(response.body, response.status)
|
336
|
+
|
337
|
+
#JSON-ify the response string
|
338
|
+
JSON.parse(response.body)
|
339
|
+
|
340
|
+
end
|
341
|
+
|
342
|
+
|
343
|
+
def process(monitoring_policy_id: @id, process_id: nil)
|
344
|
+
|
345
|
+
# If user passed in monitoring policy ID, reassign
|
346
|
+
@id = monitoring_policy_id
|
347
|
+
|
348
|
+
# Build URL
|
349
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/processes/#{process_id}")
|
350
|
+
|
351
|
+
# Perform request
|
352
|
+
response = @connection.request(:method => :get,
|
353
|
+
:path => path,
|
354
|
+
:headers => $header)
|
355
|
+
|
356
|
+
# Check response status
|
357
|
+
OneAndOne.check_response(response.body, response.status)
|
358
|
+
|
359
|
+
#JSON-ify the response string
|
360
|
+
JSON.parse(response.body)
|
361
|
+
|
362
|
+
end
|
363
|
+
|
364
|
+
|
365
|
+
def add_processes(monitoring_policy_id: @id, processes: nil)
|
366
|
+
|
367
|
+
# If user passed in monitoring policy ID, reassign
|
368
|
+
@id = monitoring_policy_id
|
369
|
+
|
370
|
+
# Build POST body
|
371
|
+
new_processes = {
|
372
|
+
'processes' => processes
|
373
|
+
}
|
374
|
+
|
375
|
+
# Clean out null keys in POST body
|
376
|
+
body = OneAndOne.clean_hash(new_processes)
|
377
|
+
|
378
|
+
# Stringify the POST body
|
379
|
+
string_body = body.to_json
|
380
|
+
|
381
|
+
# Build URL
|
382
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/processes")
|
383
|
+
|
384
|
+
# Perform request
|
385
|
+
response = @connection.request(:method => :post,
|
386
|
+
:path => path,
|
387
|
+
:headers => $header,
|
388
|
+
:body => string_body)
|
389
|
+
|
390
|
+
# Check response status
|
391
|
+
OneAndOne.check_response(response.body, response.status)
|
392
|
+
|
393
|
+
#JSON-ify the response string
|
394
|
+
JSON.parse(response.body)
|
395
|
+
|
396
|
+
end
|
397
|
+
|
398
|
+
|
399
|
+
def modify_process(monitoring_policy_id: @id, process_id: nil,
|
400
|
+
new_process: nil)
|
401
|
+
|
402
|
+
# If user passed in monitoring policy ID, reassign
|
403
|
+
@id = monitoring_policy_id
|
404
|
+
|
405
|
+
# Build PUT body
|
406
|
+
modified_process = {
|
407
|
+
'processes' => new_process
|
408
|
+
}
|
409
|
+
|
410
|
+
# Stringify the POST body
|
411
|
+
string_body = modified_process.to_json
|
412
|
+
|
413
|
+
# Build URL
|
414
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/processes/#{process_id}")
|
415
|
+
|
416
|
+
# Perform request
|
417
|
+
response = @connection.request(:method => :put,
|
418
|
+
:path => path,
|
419
|
+
:headers => $header,
|
420
|
+
:body => string_body)
|
421
|
+
|
422
|
+
# Check response status
|
423
|
+
OneAndOne.check_response(response.body, response.status)
|
424
|
+
|
425
|
+
#JSON-ify the response string
|
426
|
+
JSON.parse(response.body)
|
427
|
+
|
428
|
+
end
|
429
|
+
|
430
|
+
|
431
|
+
def delete_process(monitoring_policy_id: @id, process_id: nil)
|
432
|
+
|
433
|
+
# If user passed in monitoring policy ID, reassign
|
434
|
+
@id = monitoring_policy_id
|
435
|
+
|
436
|
+
# Build URL
|
437
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/processes/#{process_id}")
|
438
|
+
|
439
|
+
# Perform request
|
440
|
+
response = @connection.request(:method => :delete,
|
441
|
+
:path => path,
|
442
|
+
:headers => $header)
|
443
|
+
|
444
|
+
# Check response status
|
445
|
+
OneAndOne.check_response(response.body, response.status)
|
446
|
+
|
447
|
+
#JSON-ify the response string
|
448
|
+
JSON.parse(response.body)
|
449
|
+
|
450
|
+
end
|
451
|
+
|
452
|
+
|
453
|
+
def servers(monitoring_policy_id: @id)
|
454
|
+
|
455
|
+
# If user passed in monitoring policy ID, reassign
|
456
|
+
@id = monitoring_policy_id
|
457
|
+
|
458
|
+
# Build URL
|
459
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/servers")
|
460
|
+
|
461
|
+
# Perform request
|
462
|
+
response = @connection.request(:method => :get,
|
463
|
+
:path => path,
|
464
|
+
:headers => $header)
|
465
|
+
|
466
|
+
# Check response status
|
467
|
+
OneAndOne.check_response(response.body, response.status)
|
468
|
+
|
469
|
+
#JSON-ify the response string
|
470
|
+
JSON.parse(response.body)
|
471
|
+
|
472
|
+
end
|
473
|
+
|
474
|
+
|
475
|
+
def server(monitoring_policy_id: @id, server_id: nil)
|
476
|
+
|
477
|
+
# If user passed in monitoring policy ID, reassign
|
478
|
+
@id = monitoring_policy_id
|
479
|
+
|
480
|
+
# Build URL
|
481
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/servers/#{server_id}")
|
482
|
+
|
483
|
+
# Perform request
|
484
|
+
response = @connection.request(:method => :get,
|
485
|
+
:path => path,
|
486
|
+
:headers => $header)
|
487
|
+
|
488
|
+
# Check response status
|
489
|
+
OneAndOne.check_response(response.body, response.status)
|
490
|
+
|
491
|
+
#JSON-ify the response string
|
492
|
+
JSON.parse(response.body)
|
493
|
+
|
494
|
+
end
|
495
|
+
|
496
|
+
|
497
|
+
def add_servers(monitoring_policy_id: @id, servers: nil)
|
498
|
+
|
499
|
+
# If user passed in monitoring policy ID, reassign
|
500
|
+
@id = monitoring_policy_id
|
501
|
+
|
502
|
+
# Build POST body
|
503
|
+
new_servers = {
|
504
|
+
'servers' => servers
|
505
|
+
}
|
506
|
+
|
507
|
+
# Clean out null keys in POST body
|
508
|
+
body = OneAndOne.clean_hash(new_servers)
|
509
|
+
|
510
|
+
# Stringify the POST body
|
511
|
+
string_body = body.to_json
|
512
|
+
|
513
|
+
# Build URL
|
514
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/servers")
|
515
|
+
|
516
|
+
# Perform request
|
517
|
+
response = @connection.request(:method => :post,
|
518
|
+
:path => path,
|
519
|
+
:headers => $header,
|
520
|
+
:body => string_body)
|
521
|
+
|
522
|
+
# Check response status
|
523
|
+
OneAndOne.check_response(response.body, response.status)
|
524
|
+
|
525
|
+
#JSON-ify the response string
|
526
|
+
JSON.parse(response.body)
|
527
|
+
|
528
|
+
end
|
529
|
+
|
530
|
+
|
531
|
+
def remove_server(monitoring_policy_id: @id, server_id: nil)
|
532
|
+
|
533
|
+
# If user passed in monitoring policy ID, reassign
|
534
|
+
@id = monitoring_policy_id
|
535
|
+
|
536
|
+
# Build URL
|
537
|
+
path = OneAndOne.build_url("/monitoring_policies/#{@id}/servers/#{server_id}")
|
538
|
+
|
539
|
+
# Perform request
|
540
|
+
response = @connection.request(:method => :delete,
|
541
|
+
:path => path,
|
542
|
+
:headers => $header)
|
543
|
+
|
544
|
+
# Check response status
|
545
|
+
OneAndOne.check_response(response.body, response.status)
|
546
|
+
|
547
|
+
#JSON-ify the response string
|
548
|
+
JSON.parse(response.body)
|
549
|
+
|
550
|
+
end
|
551
|
+
|
552
|
+
|
553
|
+
def reload
|
554
|
+
|
555
|
+
# This reload fx is just a wrapper for the get fx
|
556
|
+
get
|
557
|
+
|
558
|
+
end
|
559
|
+
|
560
|
+
|
561
|
+
def wait_for(timeout: 25, interval: 1)
|
562
|
+
|
563
|
+
# Capture start time
|
564
|
+
start = Time.now
|
565
|
+
|
566
|
+
# Poll MP and check initial state
|
567
|
+
initial_response = get
|
568
|
+
mp_state = initial_response['state']
|
569
|
+
|
570
|
+
# Keep polling the MP's state until good
|
571
|
+
until $good_states.include? mp_state
|
572
|
+
|
573
|
+
# Wait 1 second before polling again
|
574
|
+
sleep interval
|
575
|
+
|
576
|
+
# Check MP state again
|
577
|
+
current_response = get
|
578
|
+
mp_state = current_response['state']
|
579
|
+
|
580
|
+
# Calculate current duration and check for timeout
|
581
|
+
duration = (Time.now - start) / 60
|
582
|
+
if duration > timeout
|
583
|
+
puts "The operation timed out after #{timeout} minutes.\n"
|
584
|
+
return
|
585
|
+
end
|
586
|
+
|
587
|
+
end
|
588
|
+
|
589
|
+
# Return Duration
|
590
|
+
{:duration => duration}
|
591
|
+
|
592
|
+
end
|
593
|
+
|
594
|
+
|
595
|
+
end
|
596
|
+
|
597
|
+
|
598
|
+
end
|