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
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative '../lib/oneandone'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
class TestMonitoringCenter < Minitest::Test
|
5
|
+
def setup
|
6
|
+
|
7
|
+
OneAndOne.start('TEST-API-KEY')
|
8
|
+
@monitoring_center = OneAndOne::MonitoringCenter.new(test: true)
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def test_list
|
14
|
+
|
15
|
+
# Read in mock JSON
|
16
|
+
file = File.read('mock-api/list-monitoring-center-usages.json')
|
17
|
+
data = JSON.parse(file)
|
18
|
+
|
19
|
+
# Create stub and perform call
|
20
|
+
Excon.stub({:method => :get, :path => '/v1/monitoring_center'},
|
21
|
+
{:body => JSON.generate(data), :status => 200})
|
22
|
+
|
23
|
+
response = @monitoring_center.list
|
24
|
+
|
25
|
+
# Assertions
|
26
|
+
assert_equal response[0]['id'], data[0]['id']
|
27
|
+
|
28
|
+
# Clear out stubs
|
29
|
+
Excon.stubs.clear
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def test_get
|
35
|
+
|
36
|
+
# Read in mock JSON
|
37
|
+
file = File.read('mock-api/get-monitoring-center.json')
|
38
|
+
data = JSON.parse(file)
|
39
|
+
|
40
|
+
# Create stub and perform call
|
41
|
+
Excon.stub({:method => :get, :path => "/v1/monitoring_center/#{data['id']}"},
|
42
|
+
{:body => JSON.generate(data), :status => 200})
|
43
|
+
|
44
|
+
response = @monitoring_center.get(server_id: data['id'], period: 'LAST_24H')
|
45
|
+
|
46
|
+
# Assertions
|
47
|
+
assert_equal response['id'], data['id']
|
48
|
+
|
49
|
+
# Clear out stubs
|
50
|
+
Excon.stubs.clear
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,587 @@
|
|
1
|
+
require_relative '../lib/oneandone'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
class TestMonitoringPolicy < Minitest::Test
|
5
|
+
def setup
|
6
|
+
|
7
|
+
OneAndOne.start('TEST-API-KEY')
|
8
|
+
@monitoring_policy = OneAndOne::MonitoringPolicy.new(test: true)
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def test_list
|
14
|
+
|
15
|
+
# Read in mock JSON
|
16
|
+
file = File.read('mock-api/list-mps.json')
|
17
|
+
data = JSON.parse(file)
|
18
|
+
|
19
|
+
# Create stub and perform call
|
20
|
+
Excon.stub({:method => :get, :path => '/v1/monitoring_policies'},
|
21
|
+
{:body => JSON.generate(data), :status => 200})
|
22
|
+
|
23
|
+
response = @monitoring_policy.list
|
24
|
+
|
25
|
+
# Assertions
|
26
|
+
assert_equal response[0]['id'], data[0]['id']
|
27
|
+
|
28
|
+
# Clear out stubs
|
29
|
+
Excon.stubs.clear
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def test_create
|
35
|
+
|
36
|
+
# Read in mock JSON
|
37
|
+
file = File.read('mock-api/create-mp.json')
|
38
|
+
data = JSON.parse(file)
|
39
|
+
|
40
|
+
# Create stub and perform call
|
41
|
+
Excon.stub({:method => :post, :path => '/v1/monitoring_policies'},
|
42
|
+
{:body => JSON.generate(data), :status => 202})
|
43
|
+
|
44
|
+
### Create threshold limits
|
45
|
+
thresholds = {
|
46
|
+
'cpu' => {
|
47
|
+
'warning' => {
|
48
|
+
'value' => 90,
|
49
|
+
'alert' => false
|
50
|
+
},
|
51
|
+
'critical' => {
|
52
|
+
'value' => 95,
|
53
|
+
'alert' => false
|
54
|
+
}
|
55
|
+
},
|
56
|
+
'ram' => {
|
57
|
+
'warning' => {
|
58
|
+
'value' => 90,
|
59
|
+
'alert' => false
|
60
|
+
},
|
61
|
+
'critical' => {
|
62
|
+
'value' => 95,
|
63
|
+
'alert' => false
|
64
|
+
}
|
65
|
+
},
|
66
|
+
'disk' => {
|
67
|
+
'warning' => {
|
68
|
+
'value' => 90,
|
69
|
+
'alert' => false
|
70
|
+
},
|
71
|
+
'critical' => {
|
72
|
+
'value' => 95,
|
73
|
+
'alert' => false
|
74
|
+
}
|
75
|
+
},
|
76
|
+
'transfer' => {
|
77
|
+
'warning' => {
|
78
|
+
'value' => 1000,
|
79
|
+
'alert' => false
|
80
|
+
},
|
81
|
+
'critical' => {
|
82
|
+
'value' => 2000,
|
83
|
+
'alert' => false
|
84
|
+
}
|
85
|
+
},
|
86
|
+
'internal_ping' => {
|
87
|
+
'warning' => {
|
88
|
+
'value' => 50,
|
89
|
+
'alert' => false
|
90
|
+
},
|
91
|
+
'critical' => {
|
92
|
+
'value' => 100,
|
93
|
+
'alert' => false
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
### Add ports
|
99
|
+
port1 = {
|
100
|
+
'protocol' => 'TCP',
|
101
|
+
'port' => 80,
|
102
|
+
'alert_if' => 'NOT_RESPONDING',
|
103
|
+
'email_notification' => true
|
104
|
+
}
|
105
|
+
|
106
|
+
ports = [port1]
|
107
|
+
|
108
|
+
### Add processes
|
109
|
+
process1 = {
|
110
|
+
'process' => 'test',
|
111
|
+
'alert_if' => 'NOT_RUNNING',
|
112
|
+
'email_notification' => true
|
113
|
+
}
|
114
|
+
|
115
|
+
processes = [process1]
|
116
|
+
|
117
|
+
response = @monitoring_policy.create(name: 'Test Monitoring Policy',
|
118
|
+
email: 'test@example.com', agent: true, thresholds: thresholds,
|
119
|
+
ports: ports, processes: processes)
|
120
|
+
|
121
|
+
# Assertions
|
122
|
+
assert_equal response['id'], data['id']
|
123
|
+
|
124
|
+
# Clear out stubs
|
125
|
+
Excon.stubs.clear
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
def test_get
|
131
|
+
|
132
|
+
# Read in mock JSON
|
133
|
+
file = File.read('mock-api/get-mp.json')
|
134
|
+
data = JSON.parse(file)
|
135
|
+
|
136
|
+
# Create stub and perform call
|
137
|
+
Excon.stub({:method => :get, :path => "/v1/monitoring_policies/#{data['id']}"},
|
138
|
+
{:body => JSON.generate(data), :status => 200})
|
139
|
+
|
140
|
+
response = @monitoring_policy.get(monitoring_policy_id: data['id'])
|
141
|
+
|
142
|
+
# Assertions
|
143
|
+
assert_equal response['id'], data['id']
|
144
|
+
|
145
|
+
# Clear out stubs
|
146
|
+
Excon.stubs.clear
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
def test_modify
|
152
|
+
|
153
|
+
# Read in mock JSON
|
154
|
+
file = File.read('mock-api/modify-mp.json')
|
155
|
+
data = JSON.parse(file)
|
156
|
+
|
157
|
+
# Create stub and perform call
|
158
|
+
Excon.stub({:method => :put, :path => "/v1/monitoring_policies/#{data['id']}"},
|
159
|
+
{:body => JSON.generate(data), :status => 202})
|
160
|
+
|
161
|
+
new_thresholds = {
|
162
|
+
'cpu' => {
|
163
|
+
'warning' => {
|
164
|
+
'value' => 80,
|
165
|
+
'alert' => false
|
166
|
+
},
|
167
|
+
'critical' => {
|
168
|
+
'value' => 85,
|
169
|
+
'alert' => false
|
170
|
+
}
|
171
|
+
},
|
172
|
+
'ram' => {
|
173
|
+
'warning' => {
|
174
|
+
'value' => 80,
|
175
|
+
'alert' => false
|
176
|
+
},
|
177
|
+
'critical' => {
|
178
|
+
'value' => 85,
|
179
|
+
'alert' => false
|
180
|
+
}
|
181
|
+
},
|
182
|
+
'disk' => {
|
183
|
+
'warning' => {
|
184
|
+
'value' => 80,
|
185
|
+
'alert' => false
|
186
|
+
},
|
187
|
+
'critical' => {
|
188
|
+
'value' => 85,
|
189
|
+
'alert' => false
|
190
|
+
}
|
191
|
+
},
|
192
|
+
'transfer' => {
|
193
|
+
'warning' => {
|
194
|
+
'value' => 750,
|
195
|
+
'alert' => false
|
196
|
+
},
|
197
|
+
'critical' => {
|
198
|
+
'value' => 1250,
|
199
|
+
'alert' => false
|
200
|
+
}
|
201
|
+
},
|
202
|
+
'internal_ping' => {
|
203
|
+
'warning' => {
|
204
|
+
'value' => 75,
|
205
|
+
'alert' => true
|
206
|
+
},
|
207
|
+
'critical' => {
|
208
|
+
'value' => 90,
|
209
|
+
'alert' => true
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
response = @monitoring_policy.modify(monitoring_policy_id: data['id'],
|
215
|
+
name: 'New Name', thresholds: new_thresholds)
|
216
|
+
|
217
|
+
# Assertions
|
218
|
+
assert_equal response['id'], data['id']
|
219
|
+
assert_equal response['name'], data['name']
|
220
|
+
|
221
|
+
# Clear out stubs
|
222
|
+
Excon.stubs.clear
|
223
|
+
|
224
|
+
end
|
225
|
+
|
226
|
+
|
227
|
+
def test_delete
|
228
|
+
|
229
|
+
# Read in mock JSON
|
230
|
+
file = File.read('mock-api/delete-mp.json')
|
231
|
+
data = JSON.parse(file)
|
232
|
+
|
233
|
+
# Create stub and perform call
|
234
|
+
Excon.stub({:method => :delete, :path => "/v1/monitoring_policies/#{data['id']}"},
|
235
|
+
{:body => JSON.generate(data), :status => 202})
|
236
|
+
|
237
|
+
response = @monitoring_policy.delete(monitoring_policy_id: data['id'])
|
238
|
+
|
239
|
+
# Assertions
|
240
|
+
assert_equal response['state'], 'REMOVING'
|
241
|
+
|
242
|
+
# Clear out stubs
|
243
|
+
Excon.stubs.clear
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
def test_ports
|
249
|
+
|
250
|
+
# Read in mock JSON
|
251
|
+
file = File.read('mock-api/list-mp-ports.json')
|
252
|
+
data = JSON.parse(file)
|
253
|
+
|
254
|
+
# Create stub and perform call
|
255
|
+
Excon.stub({:method => :get, :path => "/v1/monitoring_policies/MP-ID/ports"},
|
256
|
+
{:body => JSON.generate(data), :status => 200})
|
257
|
+
|
258
|
+
response = @monitoring_policy.ports(monitoring_policy_id: 'MP-ID')
|
259
|
+
|
260
|
+
# Assertions
|
261
|
+
assert_equal response[0]['id'], data[0]['id']
|
262
|
+
|
263
|
+
# Clear out stubs
|
264
|
+
Excon.stubs.clear
|
265
|
+
|
266
|
+
end
|
267
|
+
|
268
|
+
|
269
|
+
def test_add_ports
|
270
|
+
|
271
|
+
# Read in mock JSON
|
272
|
+
file = File.read('mock-api/add-port-mp.json')
|
273
|
+
data = JSON.parse(file)
|
274
|
+
|
275
|
+
# Create stub and perform call
|
276
|
+
Excon.stub({:method => :post, :path => "/v1/monitoring_policies/#{data['id']}/ports"},
|
277
|
+
{:body => JSON.generate(data), :status => 202})
|
278
|
+
|
279
|
+
port2 = {
|
280
|
+
'protocol' => 'TCP',
|
281
|
+
'port' => 90,
|
282
|
+
'alert_if' => 'NOT_RESPONDING',
|
283
|
+
'email_notification' => true
|
284
|
+
}
|
285
|
+
|
286
|
+
ports = [port2]
|
287
|
+
|
288
|
+
response = @monitoring_policy.add_ports(monitoring_policy_id: data['id'],
|
289
|
+
ports: ports)
|
290
|
+
|
291
|
+
# Assertions
|
292
|
+
assert_equal response['ports'].length, 1
|
293
|
+
|
294
|
+
# Clear out stubs
|
295
|
+
Excon.stubs.clear
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
|
300
|
+
def test_port
|
301
|
+
|
302
|
+
# Read in mock JSON
|
303
|
+
file = File.read('mock-api/get-mp-port.json')
|
304
|
+
data = JSON.parse(file)
|
305
|
+
|
306
|
+
# Create stub and perform call
|
307
|
+
Excon.stub({:method => :get, :path => "/v1/monitoring_policies/MP-ID/ports/#{data['id']}"},
|
308
|
+
{:body => JSON.generate(data), :status => 200})
|
309
|
+
|
310
|
+
response = @monitoring_policy.port(monitoring_policy_id: 'MP-ID',
|
311
|
+
port_id: data['id'])
|
312
|
+
|
313
|
+
# Assertions
|
314
|
+
assert_equal response['id'], data['id']
|
315
|
+
|
316
|
+
# Clear out stubs
|
317
|
+
Excon.stubs.clear
|
318
|
+
|
319
|
+
end
|
320
|
+
|
321
|
+
|
322
|
+
def test_delete_port
|
323
|
+
|
324
|
+
# Read in mock JSON
|
325
|
+
file = File.read('mock-api/remove-port-mp.json')
|
326
|
+
data = JSON.parse(file)
|
327
|
+
|
328
|
+
# Create stub and perform call
|
329
|
+
Excon.stub({:method => :delete, :path => "/v1/monitoring_policies/#{data['id']}/ports/PORT-ID"},
|
330
|
+
{:body => JSON.generate(data), :status => 202})
|
331
|
+
|
332
|
+
response = @monitoring_policy.delete_port(monitoring_policy_id: data['id'],
|
333
|
+
port_id: 'PORT-ID')
|
334
|
+
|
335
|
+
# Assertions
|
336
|
+
assert_equal response['ports'], []
|
337
|
+
|
338
|
+
# Clear out stubs
|
339
|
+
Excon.stubs.clear
|
340
|
+
|
341
|
+
end
|
342
|
+
|
343
|
+
|
344
|
+
def test_modify_port
|
345
|
+
|
346
|
+
# Read in mock JSON
|
347
|
+
file = File.read('mock-api/modify-port-mp.json')
|
348
|
+
data = JSON.parse(file)
|
349
|
+
|
350
|
+
# Create stub and perform call
|
351
|
+
Excon.stub({:method => :put, :path => "/v1/monitoring_policies/#{data['id']}/ports/PORT-ID"},
|
352
|
+
{:body => JSON.generate(data), :status => 202})
|
353
|
+
|
354
|
+
port = {
|
355
|
+
'protocol' => 'TCP',
|
356
|
+
'port' => 80,
|
357
|
+
'alert_if' => 'RESPONDING',
|
358
|
+
'email_notification' => false
|
359
|
+
}
|
360
|
+
|
361
|
+
response = @monitoring_policy.modify_port(monitoring_policy_id: data['id'],
|
362
|
+
port_id: 'PORT-ID', new_port: port)
|
363
|
+
|
364
|
+
# Assertions
|
365
|
+
assert_equal response['ports'][0]['port'], '22'
|
366
|
+
|
367
|
+
# Clear out stubs
|
368
|
+
Excon.stubs.clear
|
369
|
+
|
370
|
+
end
|
371
|
+
|
372
|
+
|
373
|
+
def test_processes
|
374
|
+
|
375
|
+
# Read in mock JSON
|
376
|
+
file = File.read('mock-api/list-mp-processes.json')
|
377
|
+
data = JSON.parse(file)
|
378
|
+
|
379
|
+
# Create stub and perform call
|
380
|
+
Excon.stub({:method => :get, :path => "/v1/monitoring_policies/MP-ID/processes"},
|
381
|
+
{:body => JSON.generate(data), :status => 200})
|
382
|
+
|
383
|
+
response = @monitoring_policy.processes(monitoring_policy_id: 'MP-ID')
|
384
|
+
|
385
|
+
# Assertions
|
386
|
+
assert_equal response[0]['id'], data[0]['id']
|
387
|
+
|
388
|
+
# Clear out stubs
|
389
|
+
Excon.stubs.clear
|
390
|
+
|
391
|
+
end
|
392
|
+
|
393
|
+
|
394
|
+
def test_process
|
395
|
+
|
396
|
+
# Read in mock JSON
|
397
|
+
file = File.read('mock-api/get-mp-process.json')
|
398
|
+
data = JSON.parse(file)
|
399
|
+
|
400
|
+
# Create stub and perform call
|
401
|
+
Excon.stub({:method => :get, :path => "/v1/monitoring_policies/MP-ID/processes/#{data['id']}"},
|
402
|
+
{:body => JSON.generate(data), :status => 200})
|
403
|
+
|
404
|
+
response = @monitoring_policy.process(monitoring_policy_id: 'MP-ID',
|
405
|
+
process_id: data['id'])
|
406
|
+
|
407
|
+
# Assertions
|
408
|
+
assert_equal response['id'], data['id']
|
409
|
+
|
410
|
+
# Clear out stubs
|
411
|
+
Excon.stubs.clear
|
412
|
+
|
413
|
+
end
|
414
|
+
|
415
|
+
|
416
|
+
def test_add_processes
|
417
|
+
|
418
|
+
# Read in mock JSON
|
419
|
+
file = File.read('mock-api/add-process-mp.json')
|
420
|
+
data = JSON.parse(file)
|
421
|
+
|
422
|
+
# Create stub and perform call
|
423
|
+
Excon.stub({:method => :post, :path => "/v1/monitoring_policies/MP-ID/processes"},
|
424
|
+
{:body => JSON.generate(data), :status => 202})
|
425
|
+
|
426
|
+
process2 = {
|
427
|
+
'process' => 'logger',
|
428
|
+
'alert_if' => 'NOT_RUNNING',
|
429
|
+
'email_notification' => true
|
430
|
+
}
|
431
|
+
|
432
|
+
processes = [process2]
|
433
|
+
|
434
|
+
response = @monitoring_policy.add_processes(monitoring_policy_id: 'MP-ID',
|
435
|
+
processes: processes)
|
436
|
+
|
437
|
+
# Assertions
|
438
|
+
assert_equal response.length, 3
|
439
|
+
|
440
|
+
# Clear out stubs
|
441
|
+
Excon.stubs.clear
|
442
|
+
|
443
|
+
end
|
444
|
+
|
445
|
+
|
446
|
+
def test_modify_process
|
447
|
+
|
448
|
+
# Read in mock JSON
|
449
|
+
file = File.read('mock-api/modify-process-mp.json')
|
450
|
+
data = JSON.parse(file)
|
451
|
+
|
452
|
+
# Create stub and perform call
|
453
|
+
Excon.stub({:method => :put, :path => "/v1/monitoring_policies/#{data['id']}/processes/PROCESS-ID"},
|
454
|
+
{:body => JSON.generate(data), :status => 202})
|
455
|
+
|
456
|
+
process = {
|
457
|
+
'process' => 'test',
|
458
|
+
'alert_if' => 'RUNNING',
|
459
|
+
'email_notification' => false
|
460
|
+
}
|
461
|
+
|
462
|
+
response = @monitoring_policy.modify_process(monitoring_policy_id: data['id'],
|
463
|
+
process_id: 'PROCESS-ID', new_process: process)
|
464
|
+
|
465
|
+
# Assertions
|
466
|
+
assert_equal response['processes'][0]['process'], 'test'
|
467
|
+
|
468
|
+
# Clear out stubs
|
469
|
+
Excon.stubs.clear
|
470
|
+
|
471
|
+
end
|
472
|
+
|
473
|
+
|
474
|
+
def test_delete_process
|
475
|
+
|
476
|
+
# Read in mock JSON
|
477
|
+
file = File.read('mock-api/remove-process-mp.json')
|
478
|
+
data = JSON.parse(file)
|
479
|
+
|
480
|
+
# Create stub and perform call
|
481
|
+
Excon.stub({:method => :delete, :path => "/v1/monitoring_policies/#{data['id']}/processes/PROCESS-ID"},
|
482
|
+
{:body => JSON.generate(data), :status => 202})
|
483
|
+
|
484
|
+
response = @monitoring_policy.delete_process(monitoring_policy_id: data['id'],
|
485
|
+
process_id: 'PROCESS-ID')
|
486
|
+
|
487
|
+
# Assertions
|
488
|
+
assert_equal response['processes'], []
|
489
|
+
|
490
|
+
# Clear out stubs
|
491
|
+
Excon.stubs.clear
|
492
|
+
|
493
|
+
end
|
494
|
+
|
495
|
+
|
496
|
+
def test_servers
|
497
|
+
|
498
|
+
# Read in mock JSON
|
499
|
+
file = File.read('mock-api/list-mp-servers.json')
|
500
|
+
data = JSON.parse(file)
|
501
|
+
|
502
|
+
# Create stub and perform call
|
503
|
+
Excon.stub({:method => :get, :path => "/v1/monitoring_policies/MP-ID/servers"},
|
504
|
+
{:body => JSON.generate(data), :status => 200})
|
505
|
+
|
506
|
+
response = @monitoring_policy.servers(monitoring_policy_id: 'MP-ID')
|
507
|
+
|
508
|
+
# Assertions
|
509
|
+
assert_equal response[0]['id'], data[0]['id']
|
510
|
+
|
511
|
+
# Clear out stubs
|
512
|
+
Excon.stubs.clear
|
513
|
+
|
514
|
+
end
|
515
|
+
|
516
|
+
|
517
|
+
def test_server
|
518
|
+
|
519
|
+
# Read in mock JSON
|
520
|
+
file = File.read('mock-api/get-mp-server.json')
|
521
|
+
data = JSON.parse(file)
|
522
|
+
|
523
|
+
# Create stub and perform call
|
524
|
+
Excon.stub({:method => :get, :path => "/v1/monitoring_policies/MP-ID/servers/#{data['id']}"},
|
525
|
+
{:body => JSON.generate(data), :status => 200})
|
526
|
+
|
527
|
+
response = @monitoring_policy.server(monitoring_policy_id: 'MP-ID',
|
528
|
+
server_id: data['id'])
|
529
|
+
|
530
|
+
# Assertions
|
531
|
+
assert_equal response['id'], data['id']
|
532
|
+
|
533
|
+
# Clear out stubs
|
534
|
+
Excon.stubs.clear
|
535
|
+
|
536
|
+
end
|
537
|
+
|
538
|
+
|
539
|
+
def test_add_servers
|
540
|
+
|
541
|
+
# Read in mock JSON
|
542
|
+
file = File.read('mock-api/add-server-mp.json')
|
543
|
+
data = JSON.parse(file)
|
544
|
+
|
545
|
+
# Create stub and perform call
|
546
|
+
Excon.stub({:method => :post, :path => "/v1/monitoring_policies/#{data['id']}/servers"},
|
547
|
+
{:body => JSON.generate(data), :status => 202})
|
548
|
+
|
549
|
+
server1 = '<SERVER-ID>'
|
550
|
+
|
551
|
+
servers = [server1]
|
552
|
+
|
553
|
+
response = @monitoring_policy.add_servers(monitoring_policy_id: data['id'],
|
554
|
+
servers: servers)
|
555
|
+
|
556
|
+
# Assertions
|
557
|
+
assert_equal response['state'], 'CONFIGURING'
|
558
|
+
|
559
|
+
# Clear out stubs
|
560
|
+
Excon.stubs.clear
|
561
|
+
|
562
|
+
end
|
563
|
+
|
564
|
+
|
565
|
+
def test_remove_server
|
566
|
+
|
567
|
+
# Read in mock JSON
|
568
|
+
file = File.read('mock-api/detach-server-mp.json')
|
569
|
+
data = JSON.parse(file)
|
570
|
+
|
571
|
+
# Create stub and perform call
|
572
|
+
Excon.stub({:method => :delete, :path => "/v1/monitoring_policies/#{data['id']}/servers/SERVER-ID"},
|
573
|
+
{:body => JSON.generate(data), :status => 202})
|
574
|
+
|
575
|
+
response = @monitoring_policy.remove_server(monitoring_policy_id: data['id'],
|
576
|
+
server_id: 'SERVER-ID')
|
577
|
+
|
578
|
+
# Assertions
|
579
|
+
assert_equal response['state'], 'CONFIGURING'
|
580
|
+
|
581
|
+
# Clear out stubs
|
582
|
+
Excon.stubs.clear
|
583
|
+
|
584
|
+
end
|
585
|
+
|
586
|
+
|
587
|
+
end
|