upguard 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f08c82c76dbfb5e63bbd7cdae0066ff208f8c66
4
+ data.tar.gz: a8d41839e02f2d2235f4fd398ddf4ec28ab70656
5
+ SHA512:
6
+ metadata.gz: 02b0df7adae2a5b54f2f212396d83eb29ba881a5ba241fee1c650ca9ef221e306dc21793234cb3248bc04beb76b96021aafdc261a2ec2c84d31f9316c91c2ea1
7
+ data.tar.gz: b8da5aeb26b21b6b85d1fb916b15094e3bd57f5ccb66fdd742445c10d526352c6d717b9812471a5d31f0ddde4a1d8b959c1e3110d6059fd643f7dfa27aa1f87c
@@ -0,0 +1,227 @@
1
+ module UpGuard
2
+ class Account < BaseObject
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ def from_hash(h)
6
+ self.id = h['id'] if h.include?('id')
7
+ self.name = h['name'] if h.include?('name')
8
+ end
9
+ def to_hash
10
+ h = {}
11
+ h['id'] = self.id
12
+ h['name'] = self.name
13
+ return h
14
+ end
15
+ def to_json
16
+ h = to_hash
17
+ return h.to_json
18
+ end
19
+
20
+ def connection_managers
21
+ obj = http_get("/api/v2/connection_managers.json")
22
+ list = []
23
+ obj.each do |x|
24
+ elem = ConnectionManager.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
25
+ elem.id = x["id"]
26
+ elem.hostname = x["hostname"]
27
+ elem.last_contact = x["last_contact"]
28
+ list << elem
29
+ end
30
+ return list
31
+ end
32
+
33
+
34
+ def connection_manager_groups
35
+ obj = http_get("/api/v2/connection_manager_groups.json")
36
+ list = []
37
+ obj.each do |x|
38
+ elem = ConnectionManagerGroup.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
39
+ elem.id = x["id"]
40
+ elem.name = x["name"]
41
+ list << elem
42
+ end
43
+ return list
44
+ end
45
+
46
+ def new_environment
47
+ return Environment.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
48
+ end
49
+
50
+
51
+ def environments
52
+ obj = http_get("/api/v2/environments.json")
53
+ list = []
54
+ obj.each do |x|
55
+ elem = Environment.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
56
+ elem.id = x["id"]
57
+ elem.name = x["name"]
58
+ list << elem
59
+ end
60
+ return list
61
+ end
62
+
63
+ def events_with_view_name(view_name)
64
+ url = "/api/v2/events.json?view_name=#{view_name}"
65
+ obj = http_get(url)
66
+ list = []
67
+ obj.each do |x|
68
+ elem = Event.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
69
+ elem.id = x["id"]
70
+ elem.type_id = x["type_id"]
71
+ elem.environment_id = x["environment_id"]
72
+ elem.created_at = x["created_at"]
73
+ list << elem
74
+ end
75
+ return list
76
+ end
77
+
78
+ def events_with_query(query)
79
+ url = "/api/v2/events.json?query=#{query}"
80
+ obj = http_get(url)
81
+ list = []
82
+ obj.each do |x|
83
+ elem = Event.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
84
+ elem.id = x["id"]
85
+ elem.type_id = x["type_id"]
86
+ elem.environment_id = x["environment_id"]
87
+ elem.created_at = x["created_at"]
88
+ list << elem
89
+ end
90
+ return list
91
+ end
92
+
93
+
94
+ def event_actions
95
+ obj = http_get("/api/v2/event_actions.json")
96
+ list = []
97
+ obj.each do |x|
98
+ elem = EventAction.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
99
+ elem.id = x["id"]
100
+ elem.name = x["name"]
101
+ elem.status = x["status"]
102
+ elem.type = x["type"]
103
+ list << elem
104
+ end
105
+ return list
106
+ end
107
+
108
+ def new_node
109
+ return Node.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
110
+ end
111
+
112
+
113
+ def nodes
114
+ obj = http_get("/api/v2/nodes.json")
115
+ list = []
116
+ obj.each do |x|
117
+ elem = Node.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
118
+ elem.id = x["id"]
119
+ elem.name = x["name"]
120
+ elem.external_id = x["external_id"]
121
+ elem.environment_id = x["environment_id"]
122
+ elem.operating_system_family_id = x["operating_system_family_id"]
123
+ elem.operating_system_id = x["operating_system_id"]
124
+ list << elem
125
+ end
126
+ return list
127
+ end
128
+
129
+
130
+ def node_groups
131
+ obj = http_get("/api/v2/node_groups.json")
132
+ list = []
133
+ obj.each do |x|
134
+ elem = Node.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
135
+ elem.id = x["id"]
136
+ elem.name = x["name"]
137
+ list << elem
138
+ end
139
+ return list
140
+ end
141
+
142
+
143
+ def operating_system_families
144
+ obj = http_get("/api/v2/operating_system_families.json")
145
+ list = []
146
+ obj.each do |x|
147
+ elem = OperatingSystemFamily.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
148
+ elem.id = x["id"]
149
+ elem.name = x["name"]
150
+ list << elem
151
+ end
152
+ return list
153
+ end
154
+
155
+
156
+ def operating_systems
157
+ obj = http_get("/api/v2/operating_systems.json")
158
+ list = []
159
+ obj.each do |x|
160
+ elem = OperatingSystem.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
161
+ elem.id = x["id"]
162
+ elem.name = x["name"]
163
+ elem.operating_system_family_id = x["operating_system_family_id"]
164
+ list << elem
165
+ end
166
+ return list
167
+ end
168
+
169
+
170
+ def system_metrics
171
+ obj = http_get("/api/v2/system_metrics.json")
172
+ list = []
173
+ obj.each do |x|
174
+ elem = SystemMetric.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
175
+ elem.metric = x["metric"]
176
+ elem.value = x["value"]
177
+ elem.timestamp = x["timestamp"]
178
+ list << elem
179
+ end
180
+ return list
181
+ end
182
+
183
+
184
+ def users
185
+ obj = http_get("/api/v2/users.json")
186
+ list = []
187
+ obj.each do |x|
188
+ elem = User.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
189
+ elem.id = x["id"]
190
+ elem.name = x["name"]
191
+ elem.surname = x["surname"]
192
+ elem.email = x["email"]
193
+ elem.role = x["role"]
194
+ list << elem
195
+ end
196
+ return list
197
+ end
198
+
199
+ def invite_user(email, role)
200
+ url = "/api/v2/users/invite.json?email=#{email}&role=#{role}"
201
+ obj = http_post(url, nil)
202
+ return obj
203
+ end
204
+
205
+ def find_node_by_external_id(external_id)
206
+ url = "/api/v2/nodes/lookup.json?external_id=#{external_id}"
207
+ obj = http_get(url)
208
+ id = obj["node_id"]
209
+ elem = Node.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
210
+ elem.id = id
211
+ elem.load
212
+ return elem
213
+ end
214
+
215
+ def find_node_by_name(name)
216
+ url = "/api/v2/nodes/lookup.json?name=#{name}"
217
+ obj = http_get(url)
218
+ id = obj["node_id"]
219
+ elem = Node.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
220
+ elem.id = id
221
+ elem.load
222
+ return elem
223
+ end
224
+
225
+
226
+ end
227
+ end
@@ -0,0 +1,97 @@
1
+ require 'httparty'
2
+ require 'json'
3
+ module UpGuard
4
+ class BaseObject
5
+ attr_accessor :appliance_hostname
6
+ attr_accessor :api_key
7
+ attr_accessor :sec_key
8
+ attr_accessor :insecure
9
+ def from_hash(h)
10
+ self.appliance_hostname = h['appliance_hostname'] if h.include?('appliance_hostname')
11
+ self.api_key = h['api_key'] if h.include?('api_key')
12
+ self.sec_key = h['sec_key'] if h.include?('sec_key')
13
+ self.insecure = h['insecure'] if h.include?('insecure')
14
+ end
15
+ def to_hash
16
+ h = {}
17
+ h['appliance_hostname'] = self.appliance_hostname
18
+ h['api_key'] = self.api_key
19
+ h['sec_key'] = self.sec_key
20
+ h['insecure'] = self.insecure
21
+ return h
22
+ end
23
+ def to_json
24
+ h = to_hash
25
+ return h.to_json
26
+ end
27
+ def initialize(appliance_hostname, api_key, sec_key, insecure = false)
28
+ self.appliance_hostname = appliance_hostname
29
+ self.api_key = api_key
30
+ self.sec_key = sec_key
31
+ self.insecure = insecure
32
+ end
33
+
34
+ def make_headers
35
+ return {
36
+ "Authorization" => "Token token=\"#{self.api_key}#{self.sec_key}\"",
37
+ "Content-Type" => "application/json"
38
+ }
39
+ end
40
+
41
+ def http_get(path)
42
+ url = "https://#{self.appliance_hostname}#{path}"
43
+ puts "http_get(#{url})"
44
+ response = HTTParty.get(url,
45
+ :headers => make_headers,
46
+ :verify => (self.insecure == false)
47
+ )
48
+ if response.code.to_s != "200"
49
+ puts response.code
50
+ raise response.body
51
+ end
52
+ obj = JSON.parse(response.body)
53
+ return obj
54
+ end
55
+
56
+ def http_post(path, body)
57
+ puts "http_post(path: #{path}, body: #{body})"
58
+ response = HTTParty.post("https://#{self.appliance_hostname}#{path}",
59
+ :headers => make_headers,
60
+ :verify => (self.insecure == false),
61
+ :body => body.to_json
62
+ )
63
+ if ["200", "201"].include?(response.code.to_s) == false
64
+ puts "Exception: #{response.code}: #{response.body}"
65
+ raise response.body
66
+ end
67
+ obj = JSON.parse(response.body)
68
+ return obj
69
+ end
70
+
71
+ def http_put(path, body)
72
+ response = HTTParty.put("https://#{self.appliance_hostname}#{path}",
73
+ :headers => make_headers,
74
+ :verify => (self.insecure == false),
75
+ :body => body.to_json
76
+ )
77
+ if response.code.to_s != "204"
78
+ puts "Exception: #{response.code.to_s}: #{response.body}"
79
+ raise response.body
80
+ end
81
+
82
+ end
83
+
84
+ def http_delete(path)
85
+ response = HTTParty.delete("https://#{self.appliance_hostname}#{path}",
86
+ :headers => make_headers,
87
+ :verify => (self.insecure == false)
88
+ )
89
+ if response.code.to_s != "204"
90
+ raise response.body
91
+ end
92
+
93
+ end
94
+
95
+
96
+ end
97
+ end
@@ -0,0 +1,33 @@
1
+ module UpGuard
2
+ class ConnectionManager < BaseObject
3
+ attr_accessor :id
4
+ attr_accessor :hostname
5
+ attr_accessor :last_contact
6
+ def from_hash(h)
7
+ self.id = h['id'] if h.include?('id')
8
+ self.hostname = h['hostname'] if h.include?('hostname')
9
+ self.last_contact = h['last_contact'] if h.include?('last_contact')
10
+ end
11
+ def to_hash
12
+ h = {}
13
+ h['id'] = self.id
14
+ h['hostname'] = self.hostname
15
+ h['last_contact'] = self.last_contact
16
+ return h
17
+ end
18
+ def to_json
19
+ h = to_hash
20
+ return h.to_json
21
+ end
22
+
23
+ def connection_manager_group
24
+ obj = http_get("/api/v2/connection_manager_groups/{connection_manager_group_id}.json")
25
+ elem = ConnectionManagerGroup.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
26
+ elem.id = obj["id"]
27
+ elem.name = obj["name"]
28
+ return elem
29
+ end
30
+
31
+
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ module UpGuard
2
+ class ConnectionManagerGroup < BaseObject
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ def from_hash(h)
6
+ self.id = h['id'] if h.include?('id')
7
+ self.name = h['name'] if h.include?('name')
8
+ end
9
+ def to_hash
10
+ h = {}
11
+ h['id'] = self.id
12
+ h['name'] = self.name
13
+ return h
14
+ end
15
+ def to_json
16
+ h = to_hash
17
+ return h.to_json
18
+ end
19
+
20
+ def connection_managers
21
+ obj = http_get("todo")
22
+ list = []
23
+ obj.each do |x|
24
+ elem = ConnectionManager.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
25
+ elem.id = x["id"]
26
+ elem.name = x["name"]
27
+ list << elem
28
+ end
29
+ return list
30
+ end
31
+
32
+
33
+ end
34
+ end
@@ -0,0 +1,74 @@
1
+ module UpGuard
2
+ class Environment < BaseObject
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ attr_accessor :organisation_id
6
+ attr_accessor :short_description
7
+ def from_hash(h)
8
+ self.id = h['id'] if h.include?('id')
9
+ self.name = h['name'] if h.include?('name')
10
+ self.organisation_id = h['organisation_id'] if h.include?('organisation_id')
11
+ self.short_description = h['short_description'] if h.include?('short_description')
12
+ end
13
+ def to_hash
14
+ h = {}
15
+ h['id'] = self.id
16
+ h['name'] = self.name
17
+ h['organisation_id'] = self.organisation_id
18
+ h['short_description'] = self.short_description
19
+ return h
20
+ end
21
+ def to_json
22
+ h = to_hash
23
+ return h.to_json
24
+ end
25
+
26
+ def load
27
+ obj = http_get("/api/v2/environments/#{self.id}.json")
28
+ from_hash(obj)
29
+ end
30
+
31
+
32
+ def save
33
+ if self.id.to_i == 0
34
+ return create
35
+ else
36
+ return update
37
+ end
38
+ end
39
+
40
+
41
+ def create
42
+ h = to_hash
43
+ out = http_post("/api/v2/environments.json", h)
44
+ from_hash(out)
45
+ end
46
+
47
+
48
+ def update
49
+ h = to_hash
50
+ h.delete("id")
51
+ h.delete("organisation_id")
52
+ http_put("/api/v2/environments/#{self.id}.json", h)
53
+ end
54
+
55
+ def delete
56
+ http_delete("/api/v2/environments/#{self.id}.json")
57
+ end
58
+
59
+
60
+ def nodes
61
+ obj = http_get("/api/v2/environments/#{self.id}/nodes.json")
62
+ list = []
63
+ obj.each do |x|
64
+ elem = Node.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
65
+ elem.id = x["id"]
66
+ elem.name = x["name"]
67
+ list << elem
68
+ end
69
+ return list
70
+ end
71
+
72
+
73
+ end
74
+ end
@@ -0,0 +1,39 @@
1
+ module UpGuard
2
+ class Event < BaseObject
3
+ attr_accessor :id
4
+ attr_accessor :type_id
5
+ attr_accessor :environment_id
6
+ attr_accessor :created_at
7
+ def from_hash(h)
8
+ self.id = h['id'] if h.include?('id')
9
+ self.type_id = h['type_id'] if h.include?('type_id')
10
+ self.environment_id = h['environment_id'] if h.include?('environment_id')
11
+ self.created_at = h['created_at'] if h.include?('created_at')
12
+ end
13
+ def to_hash
14
+ h = {}
15
+ h['id'] = self.id
16
+ h['type_id'] = self.type_id
17
+ h['environment_id'] = self.environment_id
18
+ h['created_at'] = self.created_at
19
+ return h
20
+ end
21
+ def to_json
22
+ h = to_hash
23
+ return h.to_json
24
+ end
25
+
26
+ def environment
27
+ obj = http_get("/api/v2/environments/#{self.environment_id}.json")
28
+ elem = Environment.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
29
+ elem.id = obj["id"]
30
+ elem.name = obj["name"]
31
+ elem.organisation_id = obj["organisation_id"]
32
+ elem.short_description = obj["short_description"]
33
+ elem.node_rules = obj["node_rules"]
34
+ return elem
35
+ end
36
+
37
+
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ module UpGuard
2
+ class EventAction < BaseObject
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ attr_accessor :status
6
+ attr_accessor :type
7
+ def from_hash(h)
8
+ self.id = h['id'] if h.include?('id')
9
+ self.name = h['name'] if h.include?('name')
10
+ self.status = h['status'] if h.include?('status')
11
+ self.type = h['type'] if h.include?('type')
12
+ end
13
+ def to_hash
14
+ h = {}
15
+ h['id'] = self.id
16
+ h['name'] = self.name
17
+ h['status'] = self.status
18
+ h['type'] = self.type
19
+ return h
20
+ end
21
+ def to_json
22
+ h = to_hash
23
+ return h.to_json
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ module UpGuard
2
+ class MediumType < BaseObject
3
+ def from_hash(h)
4
+ end
5
+ def to_hash
6
+ h = {}
7
+ return h
8
+ end
9
+ def to_json
10
+ h = to_hash
11
+ return h.to_json
12
+ end
13
+ SSH = 3
14
+
15
+ end
16
+ end
@@ -0,0 +1,123 @@
1
+ module UpGuard
2
+ class Node < BaseObject
3
+ attr_accessor :connection_manager_group_id
4
+ attr_accessor :environment_id
5
+ attr_accessor :external_id
6
+ attr_accessor :hostname
7
+ attr_accessor :id
8
+ attr_accessor :medium_hostname
9
+ attr_accessor :medium_type
10
+ attr_accessor :name
11
+ attr_accessor :node_type
12
+ attr_accessor :operating_system_family_id
13
+ attr_accessor :operating_system_id
14
+ def from_hash(h)
15
+ self.connection_manager_group_id = h['connection_manager_group_id'] if h.include?('connection_manager_group_id')
16
+ self.environment_id = h['environment_id'] if h.include?('environment_id')
17
+ self.external_id = h['external_id'] if h.include?('external_id')
18
+ self.hostname = h['hostname'] if h.include?('hostname')
19
+ self.id = h['id'] if h.include?('id')
20
+ self.medium_hostname = h['medium_hostname'] if h.include?('medium_hostname')
21
+ self.medium_type = h['medium_type'] if h.include?('medium_type')
22
+ self.name = h['name'] if h.include?('name')
23
+ self.node_type = h['node_type'] if h.include?('node_type')
24
+ self.operating_system_family_id = h['operating_system_family_id'] if h.include?('operating_system_family_id')
25
+ self.operating_system_id = h['operating_system_id'] if h.include?('operating_system_id')
26
+ end
27
+ def to_hash
28
+ h = {}
29
+ h['connection_manager_group_id'] = self.connection_manager_group_id
30
+ h['environment_id'] = self.environment_id
31
+ h['external_id'] = self.external_id
32
+ h['hostname'] = self.hostname
33
+ h['id'] = self.id
34
+ h['medium_hostname'] = self.medium_hostname
35
+ h['medium_type'] = self.medium_type
36
+ h['name'] = self.name
37
+ h['node_type'] = self.node_type
38
+ h['operating_system_family_id'] = self.operating_system_family_id
39
+ h['operating_system_id'] = self.operating_system_id
40
+ return h
41
+ end
42
+ def to_json
43
+ h = to_hash
44
+ return h.to_json
45
+ end
46
+
47
+ def load
48
+ obj = http_get("/api/v2/nodes/#{self.id}.json")
49
+ from_hash(obj)
50
+ end
51
+
52
+
53
+ def save
54
+ if self.id.to_i == 0
55
+ return create
56
+ else
57
+ return update
58
+ end
59
+ end
60
+
61
+
62
+ def create
63
+ h = to_hash
64
+ out = http_post("/api/v2/nodes.json", h)
65
+ from_hash(out)
66
+ end
67
+
68
+
69
+ def update
70
+ h = to_hash
71
+ h.delete("id")
72
+ http_put("/api/v2/nodes/#{self.id}.json", h)
73
+ end
74
+
75
+ def delete
76
+ http_delete("/api/v2/nodes/#{self.id}.json")
77
+ end
78
+
79
+
80
+ def connection_manager_group
81
+ obj = http_get("/api/v2/connection_manager_groups/{connection_manager_group_id}.json")
82
+ elem = ConnectionManagerGroup.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
83
+ elem.id = obj["id"]
84
+ elem.name = obj["name"]
85
+ return elem
86
+ end
87
+
88
+
89
+ def environment
90
+ obj = http_get("/api/v2/environments/#{self.environment_id}.json")
91
+ elem = Environment.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
92
+ elem.id = obj["id"]
93
+ elem.name = obj["name"]
94
+ return elem
95
+ end
96
+
97
+
98
+ def operating_system
99
+ obj = http_get("/api/v2/operating_systems/#{self.operating_system_id}.json")
100
+ elem = OperatingSystem.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
101
+ elem.id = obj["id"]
102
+ elem.name = obj["name"]
103
+ return elem
104
+ end
105
+
106
+
107
+ def operating_system_family
108
+ obj = http_get("/api/v2/operating_system_families/#{self.operating_system_family_id}.json")
109
+ elem = OperatingSystemFamily.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
110
+ elem.id = obj["id"]
111
+ elem.name = obj["name"]
112
+ return elem
113
+ end
114
+
115
+ def start_scan()
116
+ url = "/api/v2/nodes/#{self.id}/start_scan.json"
117
+ obj = http_post(url, nil)
118
+ return obj
119
+ end
120
+
121
+
122
+ end
123
+ end
@@ -0,0 +1,66 @@
1
+ module UpGuard
2
+ class NodeGroup < BaseObject
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ def from_hash(h)
6
+ self.id = h['id'] if h.include?('id')
7
+ self.name = h['name'] if h.include?('name')
8
+ end
9
+ def to_hash
10
+ h = {}
11
+ h['id'] = self.id
12
+ h['name'] = self.name
13
+ return h
14
+ end
15
+ def to_json
16
+ h = to_hash
17
+ return h.to_json
18
+ end
19
+
20
+ def load
21
+ obj = http_get("/api/v2/node_groups/#{self.id}.json")
22
+ from_hash(obj)
23
+ end
24
+
25
+
26
+ def save
27
+ if self.id.to_i == 0
28
+ return create
29
+ else
30
+ return update
31
+ end
32
+ end
33
+
34
+
35
+ def create
36
+ h = to_hash
37
+ out = http_post("/api/v2/node_groups.json", h)
38
+ from_hash(out)
39
+ end
40
+
41
+
42
+ def update
43
+ h = to_hash
44
+ http_put("/api/v2/node_groups/#{self.id}.json", h)
45
+ end
46
+
47
+ def delete
48
+ http_delete("/api/v2/node_groups/#{self.id}.json")
49
+ end
50
+
51
+
52
+ def nodes
53
+ obj = http_get("/api/v2/node_groups/#{self.id}/nodes.json")
54
+ list = []
55
+ obj.each do |x|
56
+ elem = Node.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
57
+ elem.id = x["id"]
58
+ elem.name = x["name"]
59
+ list << elem
60
+ end
61
+ return list
62
+ end
63
+
64
+
65
+ end
66
+ end
@@ -0,0 +1,16 @@
1
+ module UpGuard
2
+ class NodeType < BaseObject
3
+ def from_hash(h)
4
+ end
5
+ def to_hash
6
+ h = {}
7
+ return h
8
+ end
9
+ def to_json
10
+ h = to_hash
11
+ return h.to_json
12
+ end
13
+ SERVER = "SV"
14
+
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+ module UpGuard
2
+ class OperatingSystem < BaseObject
3
+ attr_accessor :description
4
+ attr_accessor :id
5
+ attr_accessor :name
6
+ attr_accessor :operating_system_family_id
7
+ def from_hash(h)
8
+ self.description = h['description'] if h.include?('description')
9
+ self.id = h['id'] if h.include?('id')
10
+ self.name = h['name'] if h.include?('name')
11
+ self.operating_system_family_id = h['operating_system_family_id'] if h.include?('operating_system_family_id')
12
+ end
13
+ def to_hash
14
+ h = {}
15
+ h['description'] = self.description
16
+ h['id'] = self.id
17
+ h['name'] = self.name
18
+ h['operating_system_family_id'] = self.operating_system_family_id
19
+ return h
20
+ end
21
+ def to_json
22
+ h = to_hash
23
+ return h.to_json
24
+ end
25
+
26
+ def operating_system_family
27
+ obj = http_get("/api/v2/operating_system_families/#{self.operating_system_family_id}.json")
28
+ elem = OperatingSystemFamily.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
29
+ elem.id = obj["id"]
30
+ elem.name = obj["name"]
31
+ return elem
32
+ end
33
+
34
+
35
+ end
36
+ end
@@ -0,0 +1,34 @@
1
+ module UpGuard
2
+ class OperatingSystemFamily < BaseObject
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ def from_hash(h)
6
+ self.id = h['id'] if h.include?('id')
7
+ self.name = h['name'] if h.include?('name')
8
+ end
9
+ def to_hash
10
+ h = {}
11
+ h['id'] = self.id
12
+ h['name'] = self.name
13
+ return h
14
+ end
15
+ def to_json
16
+ h = to_hash
17
+ return h.to_json
18
+ end
19
+
20
+ def operating_systems
21
+ obj = http_get("/api/v2/operating_system_families/#{self.id}/operating_systems.json")
22
+ list = []
23
+ obj.each do |x|
24
+ elem = OperatingSystem.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
25
+ elem.id = x["id"]
26
+ elem.name = x["name"]
27
+ list << elem
28
+ end
29
+ return list
30
+ end
31
+
32
+
33
+ end
34
+ end
@@ -0,0 +1,68 @@
1
+ module UpGuard
2
+ class ScheduledJob < BaseObject
3
+ attr_accessor :id
4
+ attr_accessor :source_id
5
+ attr_accessor :source_name
6
+ attr_accessor :source_type
7
+ attr_accessor :status
8
+ def from_hash(h)
9
+ self.id = h['id'] if h.include?('id')
10
+ self.source_id = h['source_id'] if h.include?('source_id')
11
+ self.source_name = h['source_name'] if h.include?('source_name')
12
+ self.source_type = h['source_type'] if h.include?('source_type')
13
+ self.status = h['status'] if h.include?('status')
14
+ end
15
+ def to_hash
16
+ h = {}
17
+ h['id'] = self.id
18
+ h['source_id'] = self.source_id
19
+ h['source_name'] = self.source_name
20
+ h['source_type'] = self.source_type
21
+ h['status'] = self.status
22
+ return h
23
+ end
24
+ def to_json
25
+ h = to_hash
26
+ return h.to_json
27
+ end
28
+
29
+ def load
30
+ obj = http_get("/api/v2/scheduledu_jobs/#{self.id}.json")
31
+ from_hash(obj)
32
+ end
33
+
34
+
35
+ def save
36
+ if self.id.to_i == 0
37
+ return create
38
+ else
39
+ return update
40
+ end
41
+ end
42
+
43
+
44
+ def create
45
+ h = to_hash
46
+ out = http_post("/api/v2/scheduled_jobs.json", h)
47
+ from_hash(out)
48
+ end
49
+
50
+
51
+ def update
52
+ h = to_hash
53
+ http_put("/api/v2/scheduled_jobs/#{self.id}.json", h)
54
+ end
55
+
56
+ def delete
57
+ http_delete("/api/v2/scheduled_jobs/#{self.id}.json")
58
+ end
59
+
60
+ def cancel_jobs()
61
+ url = "/api/v2/scheduled_jobs/#{self.id}/cancel_jobs.json"
62
+ obj = http_post(url, nil)
63
+ return obj
64
+ end
65
+
66
+
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ module UpGuard
2
+ class SystemMetric < BaseObject
3
+ attr_accessor :metric
4
+ attr_accessor :value
5
+ attr_accessor :timestamp
6
+ def from_hash(h)
7
+ self.metric = h['metric'] if h.include?('metric')
8
+ self.value = h['value'] if h.include?('value')
9
+ self.timestamp = h['timestamp'] if h.include?('timestamp')
10
+ end
11
+ def to_hash
12
+ h = {}
13
+ h['metric'] = self.metric
14
+ h['value'] = self.value
15
+ h['timestamp'] = self.timestamp
16
+ return h
17
+ end
18
+ def to_json
19
+ h = to_hash
20
+ return h.to_json
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,45 @@
1
+ module UpGuard
2
+ class User < BaseObject
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ attr_accessor :surname
6
+ attr_accessor :email
7
+ attr_accessor :role
8
+ attr_accessor :invited
9
+ attr_accessor :last_sign_in_at
10
+ attr_accessor :expiry
11
+ def from_hash(h)
12
+ self.id = h['id'] if h.include?('id')
13
+ self.name = h['name'] if h.include?('name')
14
+ self.surname = h['surname'] if h.include?('surname')
15
+ self.email = h['email'] if h.include?('email')
16
+ self.role = h['role'] if h.include?('role')
17
+ self.invited = h['invited'] if h.include?('invited')
18
+ self.last_sign_in_at = h['last_sign_in_at'] if h.include?('last_sign_in_at')
19
+ self.expiry = h['expiry'] if h.include?('expiry')
20
+ end
21
+ def to_hash
22
+ h = {}
23
+ h['id'] = self.id
24
+ h['name'] = self.name
25
+ h['surname'] = self.surname
26
+ h['email'] = self.email
27
+ h['role'] = self.role
28
+ h['invited'] = self.invited
29
+ h['last_sign_in_at'] = self.last_sign_in_at
30
+ h['expiry'] = self.expiry
31
+ return h
32
+ end
33
+ def to_json
34
+ h = to_hash
35
+ return h.to_json
36
+ end
37
+ def update_role(role)
38
+ url = "/api/v2/users/update_role.json?role=#{role}"
39
+ obj = http_put(url, nil)
40
+ return obj
41
+ end
42
+
43
+
44
+ end
45
+ end
data/lib/upguard.rb ADDED
@@ -0,0 +1,16 @@
1
+ require_relative 'upguard/BaseObject'
2
+ require_relative 'upguard/Account'
3
+ require_relative 'upguard/ConnectionManager'
4
+ require_relative 'upguard/ConnectionManagerGroup'
5
+ require_relative 'upguard/Environment'
6
+ require_relative 'upguard/Event'
7
+ require_relative 'upguard/EventAction'
8
+ require_relative 'upguard/MediumType'
9
+ require_relative 'upguard/Node'
10
+ require_relative 'upguard/NodeGroup'
11
+ require_relative 'upguard/NodeType'
12
+ require_relative 'upguard/OperatingSystem'
13
+ require_relative 'upguard/OperatingSystemFamily'
14
+ require_relative 'upguard/ScheduledJob'
15
+ require_relative 'upguard/SystemMetric'
16
+ require_relative 'upguard/User'
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: upguard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - UpGuard Inc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - support@upguard.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/upguard.rb
49
+ - lib/upguard/Account.rb
50
+ - lib/upguard/BaseObject.rb
51
+ - lib/upguard/ConnectionManager.rb
52
+ - lib/upguard/ConnectionManagerGroup.rb
53
+ - lib/upguard/Environment.rb
54
+ - lib/upguard/Event.rb
55
+ - lib/upguard/EventAction.rb
56
+ - lib/upguard/MediumType.rb
57
+ - lib/upguard/Node.rb
58
+ - lib/upguard/NodeGroup.rb
59
+ - lib/upguard/NodeType.rb
60
+ - lib/upguard/OperatingSystem.rb
61
+ - lib/upguard/OperatingSystemFamily.rb
62
+ - lib/upguard/ScheduledJob.rb
63
+ - lib/upguard/SystemMetric.rb
64
+ - lib/upguard/User.rb
65
+ homepage:
66
+ licenses: []
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.5.1
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: UpGuard Ruby SDK
88
+ test_files: []