upguard 0.0.4 → 0.0.6
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 +4 -4
- data/lib/upguard/Account.rb +263 -131
- data/lib/upguard/BaseObject.rb +16 -16
- data/lib/upguard/ConnectionManager.rb +18 -3
- data/lib/upguard/ConnectionManagerGroup.rb +30 -8
- data/lib/upguard/ConnectionManagerGroupList.rb +39 -0
- data/lib/upguard/ConnectionManagerList.rb +39 -0
- data/lib/upguard/Environment.rb +34 -11
- data/lib/upguard/EnvironmentList.rb +39 -0
- data/lib/upguard/Event.rb +3 -3
- data/lib/upguard/EventAction.rb +8 -2
- data/lib/upguard/EventActionList.rb +39 -0
- data/lib/upguard/Incident.rb +2 -2
- data/lib/upguard/IncidentList.rb +39 -0
- data/lib/upguard/Job.rb +33 -0
- data/lib/upguard/JobList.rb +39 -0
- data/lib/upguard/MediumType.rb +2 -2
- data/lib/upguard/Node.rb +24 -18
- data/lib/upguard/NodeGroup.rb +17 -8
- data/lib/upguard/NodeGroupList.rb +39 -0
- data/lib/upguard/NodeList.rb +39 -0
- data/lib/upguard/NodeType.rb +2 -2
- data/lib/upguard/OperatingSystem.rb +3 -3
- data/lib/upguard/OperatingSystemFamily.rb +8 -8
- data/lib/upguard/OperatingSystemFamilyList.rb +39 -0
- data/lib/upguard/OperatingSystemList.rb +39 -0
- data/lib/upguard/Policy.rb +53 -0
- data/lib/upguard/PolicyList.rb +39 -0
- data/lib/upguard/ScheduledJob.rb +6 -3
- data/lib/upguard/ScheduledJobList.rb +39 -0
- data/lib/upguard/SystemMetric.rb +2 -2
- data/lib/upguard/SystemMetricList.rb +39 -0
- data/lib/upguard/User.rb +2 -2
- data/lib/upguard/UserList.rb +39 -0
- data/lib/upguard.rb +16 -0
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a48de6f627011308b5e15643cf59434dc4a5165a
|
4
|
+
data.tar.gz: fe28ac17cb16733dfa0770a32b828f00080ba490
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7539d483e269ef662af049a551144768d28dfbc2fa3a3a1c59ae3ae28ec38a6af0c9cec9a3134fb7267fab45d667a046b1ae9aa36e54b0f19f09298e589f31f0
|
7
|
+
data.tar.gz: fd669c2bc3a8897092cfc8aef5c913f1af4976c1756739eb12d47e7e8a594e523b2d1f27daf75b498e647f3e5162dfe476ef314d59f6910b9edcad64dc907539
|
data/lib/upguard/Account.rb
CHANGED
@@ -12,221 +12,381 @@ module UpGuard
|
|
12
12
|
h['name'] = self.name
|
13
13
|
return h
|
14
14
|
end
|
15
|
-
def to_json
|
15
|
+
def to_json(options = nil)
|
16
16
|
h = to_hash
|
17
|
-
return h.to_json
|
17
|
+
return h.to_json(options)
|
18
18
|
end
|
19
19
|
|
20
|
+
def change_request_by_id(id)
|
21
|
+
obj = http_get("/api/v2/change_requests/#{id}.json")
|
22
|
+
elem = ChangeRequest.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
23
|
+
elem.external_id = obj["external_id"]
|
24
|
+
elem.id = obj["id"]
|
25
|
+
elem.planned_end_date = obj["planned_end_date"]
|
26
|
+
elem.planned_start_date = obj["planned_start_date"]
|
27
|
+
elem.short_description = obj["short_description"]
|
28
|
+
elem.started_at = obj["started_at"]
|
29
|
+
elem.ended_at = obj["ended_at"]
|
30
|
+
return elem
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def change_requests
|
35
|
+
obj = http_get("/api/v2/change_requests.json")
|
36
|
+
the_list = ChangeRequestList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
37
|
+
obj.each do |x|
|
38
|
+
elem = ChangeRequest.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
39
|
+
elem.external_id = x["external_id"] if x.include?("external_id")
|
40
|
+
elem.id = x["id"] if x.include?("id")
|
41
|
+
elem.planned_end_date = x["planned_end_date"] if x.include?("planned_end_date")
|
42
|
+
elem.planned_start_date = x["planned_start_date"] if x.include?("planned_start_date")
|
43
|
+
elem.short_description = x["short_description"] if x.include?("short_description")
|
44
|
+
elem.started_at = x["started_at"] if x.include?("started_at")
|
45
|
+
elem.ended_at = x["ended_at"] if x.include?("ended_at")
|
46
|
+
the_list << elem
|
47
|
+
end
|
48
|
+
return the_list
|
49
|
+
end
|
50
|
+
|
51
|
+
|
20
52
|
def connection_managers
|
21
53
|
obj = http_get("/api/v2/connection_managers.json")
|
22
|
-
|
54
|
+
the_list = ConnectionManagerList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
23
55
|
obj.each do |x|
|
24
|
-
elem = ConnectionManager.new(self.
|
25
|
-
elem.
|
26
|
-
elem.
|
27
|
-
elem.
|
28
|
-
|
56
|
+
elem = ConnectionManager.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
57
|
+
elem.channels = x["channels"] if x.include?("channels")
|
58
|
+
elem.connection_manager_group_id = x["connection_manager_group_id"] if x.include?("connection_manager_group_id")
|
59
|
+
elem.created_at = x["created_at"] if x.include?("created_at")
|
60
|
+
elem.hostname = x["hostname"] if x.include?("hostname")
|
61
|
+
elem.id = x["id"] if x.include?("id")
|
62
|
+
elem.last_contact = x["last_contact"] if x.include?("last_contact")
|
63
|
+
elem.stats = x["stats"] if x.include?("stats")
|
64
|
+
elem.updated_at = x["updated_at"] if x.include?("updated_at")
|
65
|
+
the_list << elem
|
29
66
|
end
|
30
|
-
return
|
67
|
+
return the_list
|
31
68
|
end
|
32
69
|
|
33
70
|
|
34
71
|
def connection_manager_groups
|
35
72
|
obj = http_get("/api/v2/connection_manager_groups.json")
|
36
|
-
|
73
|
+
the_list = ConnectionManagerGroupList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
37
74
|
obj.each do |x|
|
38
|
-
elem = ConnectionManagerGroup.new(self.
|
39
|
-
elem.id = x["id"]
|
40
|
-
elem.name = x["name"]
|
41
|
-
|
75
|
+
elem = ConnectionManagerGroup.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
76
|
+
elem.id = x["id"] if x.include?("id")
|
77
|
+
elem.name = x["name"] if x.include?("name")
|
78
|
+
elem.organisation_id = x["organisation_id"] if x.include?("organisation_id")
|
79
|
+
elem.status = x["status"] if x.include?("status")
|
80
|
+
the_list << elem
|
42
81
|
end
|
43
|
-
return
|
82
|
+
return the_list
|
44
83
|
end
|
45
84
|
|
46
85
|
def new_environment
|
47
|
-
return Environment.new(self.
|
86
|
+
return Environment.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def environment_by_id(id)
|
91
|
+
obj = http_get("/api/v2/environments/#{id}.json")
|
92
|
+
elem = Environment.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
93
|
+
elem.id = obj["id"]
|
94
|
+
elem.name = obj["name"]
|
95
|
+
return elem
|
48
96
|
end
|
49
97
|
|
50
98
|
|
51
99
|
def environments
|
52
100
|
obj = http_get("/api/v2/environments.json")
|
53
|
-
|
101
|
+
the_list = EnvironmentList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
54
102
|
obj.each do |x|
|
55
|
-
elem = Environment.new(self.
|
56
|
-
elem.
|
57
|
-
elem.
|
58
|
-
|
103
|
+
elem = Environment.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
104
|
+
elem.description = x["description"] if x.include?("description")
|
105
|
+
elem.id = x["id"] if x.include?("id")
|
106
|
+
elem.name = x["name"] if x.include?("name")
|
107
|
+
elem.node_rules = x["node_rules"] if x.include?("node_rules")
|
108
|
+
elem.short_description = x["short_description"] if x.include?("short_description")
|
109
|
+
the_list << elem
|
59
110
|
end
|
60
|
-
return
|
111
|
+
return the_list
|
61
112
|
end
|
62
113
|
|
63
114
|
def events_with_view_name(view_name)
|
64
115
|
url = "/api/v2/events.json?view_name=#{view_name}"
|
65
116
|
obj = http_get(url)
|
66
|
-
|
117
|
+
the_list = []
|
67
118
|
obj.each do |x|
|
68
|
-
elem = Event.new(self.
|
119
|
+
elem = Event.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
69
120
|
elem.id = x["id"]
|
70
121
|
elem.type_id = x["type_id"]
|
71
122
|
elem.environment_id = x["environment_id"]
|
72
123
|
elem.created_at = x["created_at"]
|
73
|
-
|
124
|
+
the_list << elem
|
74
125
|
end
|
75
|
-
return
|
126
|
+
return the_list
|
76
127
|
end
|
77
128
|
|
78
129
|
def events_with_query(query)
|
79
130
|
url = "/api/v2/events.json?query=#{query}"
|
80
131
|
obj = http_get(url)
|
81
|
-
|
132
|
+
the_list = []
|
82
133
|
obj.each do |x|
|
83
|
-
elem = Event.new(self.
|
134
|
+
elem = Event.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
84
135
|
elem.id = x["id"]
|
85
136
|
elem.type_id = x["type_id"]
|
86
137
|
elem.environment_id = x["environment_id"]
|
87
138
|
elem.created_at = x["created_at"]
|
88
|
-
|
139
|
+
the_list << elem
|
140
|
+
end
|
141
|
+
return the_list
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
def event_action_by_id(id)
|
146
|
+
obj = http_get("/api/v2/event_actions/#{id}.json")
|
147
|
+
elem = EventAction.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
148
|
+
elem.id = obj["id"]
|
149
|
+
elem.name = obj["name"]
|
150
|
+
return elem
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
def event_types
|
155
|
+
obj = http_get("/api/v2/events/types.json")
|
156
|
+
the_list = EventTypeList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
157
|
+
obj.each do |x|
|
158
|
+
elem = EventType.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
159
|
+
elem.id = x["id"] if x.include?("id")
|
160
|
+
elem.name = x["name"] if x.include?("name")
|
161
|
+
the_list << elem
|
89
162
|
end
|
90
|
-
return
|
163
|
+
return the_list
|
91
164
|
end
|
92
165
|
|
93
166
|
|
94
167
|
def event_actions
|
95
168
|
obj = http_get("/api/v2/event_actions.json")
|
96
|
-
|
169
|
+
the_list = EventActionList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
97
170
|
obj.each do |x|
|
98
|
-
elem = EventAction.new(self.
|
99
|
-
elem.id = x["id"]
|
100
|
-
elem.name = x["name"]
|
101
|
-
elem.status = x["status"]
|
102
|
-
elem.type = x["type"]
|
103
|
-
|
171
|
+
elem = EventAction.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
172
|
+
elem.id = x["id"] if x.include?("id")
|
173
|
+
elem.name = x["name"] if x.include?("name")
|
174
|
+
elem.status = x["status"] if x.include?("status")
|
175
|
+
elem.type = x["type"] if x.include?("type")
|
176
|
+
elem.variables = x["variables"] if x.include?("variables")
|
177
|
+
elem.view = x["view"] if x.include?("view")
|
178
|
+
the_list << elem
|
104
179
|
end
|
105
|
-
return
|
180
|
+
return the_list
|
106
181
|
end
|
107
182
|
|
108
183
|
|
109
184
|
def incidents
|
110
185
|
obj = http_get("/api/v2/incidents.json")
|
111
|
-
|
186
|
+
the_list = IncidentList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
112
187
|
obj.each do |x|
|
113
|
-
elem = Incident.new(self.
|
114
|
-
elem.id = x["id"]
|
115
|
-
elem.external_id = x["external_id"]
|
116
|
-
elem.short_description = x["short_description"]
|
117
|
-
elem.started_at = x["started_at"]
|
118
|
-
elem.ended_at = x["ended_at"]
|
119
|
-
elem.url = x["url"]
|
120
|
-
|
188
|
+
elem = Incident.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
189
|
+
elem.id = x["id"] if x.include?("id")
|
190
|
+
elem.external_id = x["external_id"] if x.include?("external_id")
|
191
|
+
elem.short_description = x["short_description"] if x.include?("short_description")
|
192
|
+
elem.started_at = x["started_at"] if x.include?("started_at")
|
193
|
+
elem.ended_at = x["ended_at"] if x.include?("ended_at")
|
194
|
+
elem.url = x["url"] if x.include?("url")
|
195
|
+
the_list << elem
|
121
196
|
end
|
122
|
-
return
|
197
|
+
return the_list
|
123
198
|
end
|
124
199
|
|
125
200
|
|
126
201
|
def jobs
|
127
202
|
obj = http_get("/api/v2/jobs.json")
|
128
|
-
|
203
|
+
the_list = JobList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
129
204
|
obj.each do |x|
|
130
|
-
elem = Job.new(self.
|
131
|
-
elem.id = x["id"]
|
132
|
-
elem.organisation_id = x["organisation_id"]
|
133
|
-
elem.source_id = x["source_id"]
|
134
|
-
elem.
|
135
|
-
elem.
|
136
|
-
|
205
|
+
elem = Job.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
206
|
+
elem.id = x["id"] if x.include?("id")
|
207
|
+
elem.organisation_id = x["organisation_id"] if x.include?("organisation_id")
|
208
|
+
elem.source_id = x["source_id"] if x.include?("source_id")
|
209
|
+
elem.source_name = x["source_name"] if x.include?("source_name")
|
210
|
+
elem.source_type = x["source_type"] if x.include?("source_type")
|
211
|
+
elem.status = x["status"] if x.include?("status")
|
212
|
+
the_list << elem
|
137
213
|
end
|
138
|
-
return
|
214
|
+
return the_list
|
139
215
|
end
|
140
216
|
|
141
217
|
def new_node
|
142
|
-
return Node.new(self.
|
218
|
+
return Node.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
143
219
|
end
|
144
220
|
|
145
221
|
|
146
222
|
def nodes
|
147
223
|
obj = http_get("/api/v2/nodes.json")
|
148
|
-
|
224
|
+
the_list = NodeList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
149
225
|
obj.each do |x|
|
150
|
-
elem = Node.new(self.
|
151
|
-
elem.
|
152
|
-
elem.
|
153
|
-
elem.
|
154
|
-
elem.
|
155
|
-
elem.
|
156
|
-
elem.
|
157
|
-
|
226
|
+
elem = Node.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
227
|
+
elem.external_id = x["external_id"] if x.include?("external_id")
|
228
|
+
elem.environment_id = x["environment_id"] if x.include?("environment_id")
|
229
|
+
elem.id = x["id"] if x.include?("id")
|
230
|
+
elem.last_scan_status = x["last_scan_status"] if x.include?("last_scan_status")
|
231
|
+
elem.last_scan_status_string = x["last_scan_status_string"] if x.include?("last_scan_status_string")
|
232
|
+
elem.mac_address = x["mac_address"] if x.include?("mac_address")
|
233
|
+
elem.name = x["name"] if x.include?("name")
|
234
|
+
elem.node_type = x["node_type"] if x.include?("node_type")
|
235
|
+
elem.online = x["online"] if x.include?("online")
|
236
|
+
elem.operating_system_family_id = x["operating_system_family_id"] if x.include?("operating_system_family_id")
|
237
|
+
elem.operating_system_id = x["operating_system_id"] if x.include?("operating_system_id")
|
238
|
+
elem.short_description = x["short_description"] if x.include?("short_description")
|
239
|
+
the_list << elem
|
158
240
|
end
|
159
|
-
return
|
241
|
+
return the_list
|
242
|
+
end
|
243
|
+
|
244
|
+
def node_by_external_id(external_id)
|
245
|
+
url = "/api/v2/nodes/lookup.json?external_id=#{external_id}"
|
246
|
+
obj = http_get(url)
|
247
|
+
id = obj["node_id"]
|
248
|
+
elem = Node.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
249
|
+
elem.id = id
|
250
|
+
elem.load
|
251
|
+
return elem
|
252
|
+
end
|
253
|
+
|
254
|
+
def node_by_name(name)
|
255
|
+
url = "/api/v2/nodes/lookup.json?name=#{name}"
|
256
|
+
obj = http_get(url)
|
257
|
+
id = obj["node_id"]
|
258
|
+
elem = Node.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
259
|
+
elem.id = id
|
260
|
+
elem.load
|
261
|
+
return elem
|
262
|
+
end
|
263
|
+
|
264
|
+
|
265
|
+
def node_by_id(id)
|
266
|
+
obj = http_get("/api/v2/nodes/#{id}.json")
|
267
|
+
elem = Node.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
268
|
+
elem.id = obj["id"]
|
269
|
+
elem.name = obj["name"]
|
270
|
+
return elem
|
160
271
|
end
|
161
272
|
|
162
273
|
|
163
274
|
def node_groups
|
164
275
|
obj = http_get("/api/v2/node_groups.json")
|
165
|
-
|
276
|
+
the_list = NodeGroupList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
166
277
|
obj.each do |x|
|
167
|
-
elem =
|
168
|
-
elem.
|
169
|
-
elem.
|
170
|
-
|
278
|
+
elem = NodeGroup.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
279
|
+
elem.description = x["description"] if x.include?("description")
|
280
|
+
elem.id = x["id"] if x.include?("id")
|
281
|
+
elem.name = x["name"] if x.include?("name")
|
282
|
+
elem.node_rules = x["node_rules"] if x.include?("node_rules")
|
283
|
+
elem.search_query = x["search_query"] if x.include?("search_query")
|
284
|
+
the_list << elem
|
171
285
|
end
|
172
|
-
return
|
286
|
+
return the_list
|
173
287
|
end
|
174
288
|
|
175
289
|
|
176
290
|
def operating_system_families
|
177
291
|
obj = http_get("/api/v2/operating_system_families.json")
|
178
|
-
|
292
|
+
the_list = OperatingSystemFamilyList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
179
293
|
obj.each do |x|
|
180
|
-
elem = OperatingSystemFamily.new(self.
|
181
|
-
elem.id = x["id"]
|
182
|
-
elem.name = x["name"]
|
183
|
-
|
294
|
+
elem = OperatingSystemFamily.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
295
|
+
elem.id = x["id"] if x.include?("id")
|
296
|
+
elem.name = x["name"] if x.include?("name")
|
297
|
+
the_list << elem
|
184
298
|
end
|
185
|
-
return
|
299
|
+
return the_list
|
186
300
|
end
|
187
301
|
|
188
302
|
|
189
303
|
def operating_systems
|
190
304
|
obj = http_get("/api/v2/operating_systems.json")
|
191
|
-
|
305
|
+
the_list = OperatingSystemList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
192
306
|
obj.each do |x|
|
193
|
-
elem = OperatingSystem.new(self.
|
194
|
-
elem.id = x["id"]
|
195
|
-
elem.name = x["name"]
|
196
|
-
elem.operating_system_family_id = x["operating_system_family_id"]
|
197
|
-
|
307
|
+
elem = OperatingSystem.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
308
|
+
elem.id = x["id"] if x.include?("id")
|
309
|
+
elem.name = x["name"] if x.include?("name")
|
310
|
+
elem.operating_system_family_id = x["operating_system_family_id"] if x.include?("operating_system_family_id")
|
311
|
+
elem.description = x["description"] if x.include?("description")
|
312
|
+
the_list << elem
|
313
|
+
end
|
314
|
+
return the_list
|
315
|
+
end
|
316
|
+
|
317
|
+
|
318
|
+
def policies
|
319
|
+
obj = http_get("/api/v2/policies.json")
|
320
|
+
the_list = PolicyList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
321
|
+
obj.each do |x|
|
322
|
+
elem = Policy.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
323
|
+
elem.id = x["id"] if x.include?("id")
|
324
|
+
elem.name = x["name"] if x.include?("name")
|
325
|
+
the_list << elem
|
198
326
|
end
|
199
|
-
return
|
327
|
+
return the_list
|
328
|
+
end
|
329
|
+
|
330
|
+
|
331
|
+
def scheduled_jobs
|
332
|
+
obj = http_get("/api/v2/scheduled_jobs.json")
|
333
|
+
the_list = ScheduledJobList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
334
|
+
obj.each do |x|
|
335
|
+
elem = ScheduledJob.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
336
|
+
elem.data = x["data"] if x.include?("data")
|
337
|
+
elem.id = x["id"] if x.include?("id")
|
338
|
+
elem.source_id = x["source_id"] if x.include?("source_id")
|
339
|
+
elem.source_name = x["source_name"] if x.include?("source_name")
|
340
|
+
elem.source_type = x["source_type"] if x.include?("source_type")
|
341
|
+
elem.status = x["status"] if x.include?("status")
|
342
|
+
the_list << elem
|
343
|
+
end
|
344
|
+
return the_list
|
200
345
|
end
|
201
346
|
|
202
347
|
|
203
348
|
def system_metrics
|
204
349
|
obj = http_get("/api/v2/system_metrics.json")
|
205
|
-
|
350
|
+
the_list = SystemMetricList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
206
351
|
obj.each do |x|
|
207
|
-
elem = SystemMetric.new(self.
|
208
|
-
elem.metric = x["metric"]
|
209
|
-
elem.value = x["value"]
|
210
|
-
elem.timestamp = x["timestamp"]
|
211
|
-
|
352
|
+
elem = SystemMetric.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
353
|
+
elem.metric = x["metric"] if x.include?("metric")
|
354
|
+
elem.value = x["value"] if x.include?("value")
|
355
|
+
elem.timestamp = x["timestamp"] if x.include?("timestamp")
|
356
|
+
the_list << elem
|
212
357
|
end
|
213
|
-
return
|
358
|
+
return the_list
|
359
|
+
end
|
360
|
+
|
361
|
+
|
362
|
+
def text_file_by_id(id)
|
363
|
+
obj = http_get("/api/v2/text_files/#{id}.json")
|
364
|
+
elem = TextFile.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
365
|
+
elem.category = obj["category"]
|
366
|
+
elem.checksum = obj["checksum"]
|
367
|
+
elem.created_at = obj["created_at"]
|
368
|
+
elem.data = obj["data"]
|
369
|
+
elem.id = obj["id"]
|
370
|
+
elem.name = obj["name"]
|
371
|
+
elem.updated_at = obj["updated_at"]
|
372
|
+
return elem
|
214
373
|
end
|
215
374
|
|
216
375
|
|
217
376
|
def users
|
218
377
|
obj = http_get("/api/v2/users.json")
|
219
|
-
|
378
|
+
the_list = UserList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
220
379
|
obj.each do |x|
|
221
|
-
elem = User.new(self.
|
222
|
-
elem.
|
223
|
-
elem.
|
224
|
-
elem.
|
225
|
-
elem.
|
226
|
-
elem.role = x["role"]
|
227
|
-
|
380
|
+
elem = User.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
|
381
|
+
elem.email = x["email"] if x.include?("email")
|
382
|
+
elem.id = x["id"] if x.include?("id")
|
383
|
+
elem.last_sign_in_at = x["last_sign_in_at"] if x.include?("last_sign_in_at")
|
384
|
+
elem.name = x["name"] if x.include?("name")
|
385
|
+
elem.role = x["role"] if x.include?("role")
|
386
|
+
elem.surname = x["surname"] if x.include?("surname")
|
387
|
+
the_list << elem
|
228
388
|
end
|
229
|
-
return
|
389
|
+
return the_list
|
230
390
|
end
|
231
391
|
|
232
392
|
def invite_user(email, role)
|
@@ -235,34 +395,6 @@ module UpGuard
|
|
235
395
|
return obj
|
236
396
|
end
|
237
397
|
|
238
|
-
def find_node_by_external_id(external_id)
|
239
|
-
url = "/api/v2/nodes/lookup.json?external_id=#{external_id}"
|
240
|
-
obj = http_get(url)
|
241
|
-
id = obj["node_id"]
|
242
|
-
elem = Node.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
|
243
|
-
elem.id = id
|
244
|
-
elem.load
|
245
|
-
return elem
|
246
|
-
end
|
247
|
-
|
248
|
-
def find_node_by_name(name)
|
249
|
-
url = "/api/v2/nodes/lookup.json?name=#{name}"
|
250
|
-
obj = http_get(url)
|
251
|
-
id = obj["node_id"]
|
252
|
-
elem = Node.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
|
253
|
-
elem.id = id
|
254
|
-
elem.load
|
255
|
-
return elem
|
256
|
-
end
|
257
|
-
|
258
|
-
def find_node_by_id(id)
|
259
|
-
url = "/api/v2/nodes/#{self.id}.json?id=#{id}"
|
260
|
-
obj = http_get(url)
|
261
|
-
elem = Node.new(self.appliance_hostname, self.api_key, self.sec_key, self.insecure)
|
262
|
-
elem.from_hash(obj)
|
263
|
-
return elem
|
264
|
-
end
|
265
|
-
|
266
398
|
|
267
399
|
end
|
268
400
|
end
|
data/lib/upguard/BaseObject.rb
CHANGED
@@ -2,30 +2,35 @@ require 'httparty'
|
|
2
2
|
require 'json'
|
3
3
|
module UpGuard
|
4
4
|
class BaseObject
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :appliance_url
|
6
6
|
attr_accessor :api_key
|
7
7
|
attr_accessor :sec_key
|
8
8
|
attr_accessor :insecure
|
9
9
|
def from_hash(h)
|
10
|
-
self.
|
10
|
+
self.appliance_url = h['appliance_url'] if h.include?('appliance_url')
|
11
11
|
self.api_key = h['api_key'] if h.include?('api_key')
|
12
12
|
self.sec_key = h['sec_key'] if h.include?('sec_key')
|
13
13
|
self.insecure = h['insecure'] if h.include?('insecure')
|
14
14
|
end
|
15
15
|
def to_hash
|
16
16
|
h = {}
|
17
|
-
h['
|
17
|
+
h['appliance_url'] = self.appliance_url
|
18
18
|
h['api_key'] = self.api_key
|
19
19
|
h['sec_key'] = self.sec_key
|
20
20
|
h['insecure'] = self.insecure
|
21
21
|
return h
|
22
22
|
end
|
23
|
-
def to_json
|
23
|
+
def to_json(options = nil)
|
24
24
|
h = to_hash
|
25
|
-
return h.to_json
|
25
|
+
return h.to_json(options)
|
26
26
|
end
|
27
|
-
def initialize(
|
28
|
-
|
27
|
+
def initialize(appliance_url, api_key, sec_key, insecure = false)
|
28
|
+
if appliance_url.to_s.start_with?("http://") || appliance_url.to_s.start_with?("https://")
|
29
|
+
# all good
|
30
|
+
else
|
31
|
+
appliance_url = "https://" + appliance_url
|
32
|
+
end
|
33
|
+
self.appliance_url = appliance_url
|
29
34
|
self.api_key = api_key
|
30
35
|
self.sec_key = sec_key
|
31
36
|
self.insecure = insecure
|
@@ -39,14 +44,12 @@ module UpGuard
|
|
39
44
|
end
|
40
45
|
|
41
46
|
def http_get(path)
|
42
|
-
url = "
|
43
|
-
puts "http_get(#{url})"
|
47
|
+
url = "#{self.appliance_url}#{path}"
|
44
48
|
response = HTTParty.get(url,
|
45
49
|
:headers => make_headers,
|
46
50
|
:verify => (self.insecure == false)
|
47
51
|
)
|
48
52
|
if response.code.to_s != "200"
|
49
|
-
puts response.code
|
50
53
|
raise response.body
|
51
54
|
end
|
52
55
|
obj = JSON.parse(response.body)
|
@@ -54,14 +57,12 @@ module UpGuard
|
|
54
57
|
end
|
55
58
|
|
56
59
|
def http_post(path, body)
|
57
|
-
|
58
|
-
response = HTTParty.post("https://#{self.appliance_hostname}#{path}",
|
60
|
+
response = HTTParty.post("#{self.appliance_url}#{path}",
|
59
61
|
:headers => make_headers,
|
60
62
|
:verify => (self.insecure == false),
|
61
63
|
:body => body.to_json
|
62
64
|
)
|
63
65
|
if ["200", "201"].include?(response.code.to_s) == false
|
64
|
-
puts "Exception: #{response.code}: #{response.body}"
|
65
66
|
raise response.body
|
66
67
|
end
|
67
68
|
obj = JSON.parse(response.body)
|
@@ -69,20 +70,19 @@ module UpGuard
|
|
69
70
|
end
|
70
71
|
|
71
72
|
def http_put(path, body)
|
72
|
-
response = HTTParty.put("
|
73
|
+
response = HTTParty.put("#{self.appliance_url}#{path}",
|
73
74
|
:headers => make_headers,
|
74
75
|
:verify => (self.insecure == false),
|
75
76
|
:body => body.to_json
|
76
77
|
)
|
77
78
|
if response.code.to_s != "204"
|
78
|
-
puts "Exception: #{response.code.to_s}: #{response.body}"
|
79
79
|
raise response.body
|
80
80
|
end
|
81
81
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def http_delete(path)
|
85
|
-
response = HTTParty.delete("
|
85
|
+
response = HTTParty.delete("#{self.appliance_url}#{path}",
|
86
86
|
:headers => make_headers,
|
87
87
|
:verify => (self.insecure == false)
|
88
88
|
)
|