upguard 0.0.6 → 0.0.17

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.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/lib/upguard.rb +13 -0
  3. data/lib/upguard/Account.rb +192 -49
  4. data/lib/upguard/BaseObject.rb +8 -7
  5. data/lib/upguard/ChangeRequest.rb +55 -0
  6. data/lib/upguard/ChangeRequestList.rb +53 -0
  7. data/lib/upguard/ConnectionManager.rb +25 -1
  8. data/lib/upguard/ConnectionManagerGroup.rb +16 -6
  9. data/lib/upguard/ConnectionManagerGroupList.rb +17 -3
  10. data/lib/upguard/ConnectionManagerList.rb +17 -3
  11. data/lib/upguard/Environment.rb +16 -2
  12. data/lib/upguard/EnvironmentList.rb +17 -3
  13. data/lib/upguard/Event.rb +13 -1
  14. data/lib/upguard/EventAction.rb +10 -0
  15. data/lib/upguard/EventActionList.rb +17 -3
  16. data/lib/upguard/EventList.rb +53 -0
  17. data/lib/upguard/EventVariables.rb +43 -0
  18. data/lib/upguard/ExternalEvent.rb +36 -0
  19. data/lib/upguard/Incident.rb +10 -0
  20. data/lib/upguard/IncidentList.rb +17 -3
  21. data/lib/upguard/Job.rb +37 -0
  22. data/lib/upguard/JobList.rb +17 -3
  23. data/lib/upguard/MediumType.rb +3 -0
  24. data/lib/upguard/Node.rb +93 -5
  25. data/lib/upguard/NodeGroup.rb +82 -2
  26. data/lib/upguard/NodeGroupList.rb +28 -3
  27. data/lib/upguard/NodeGroupUser.rb +27 -0
  28. data/lib/upguard/NodeGroupUserList.rb +64 -0
  29. data/lib/upguard/NodeList.rb +17 -3
  30. data/lib/upguard/NodeMediumInfo.rb +49 -0
  31. data/lib/upguard/NodeScan.rb +78 -0
  32. data/lib/upguard/NodeScanList.rb +53 -0
  33. data/lib/upguard/NodeType.rb +10 -0
  34. data/lib/upguard/OperatingSystem.rb +9 -1
  35. data/lib/upguard/OperatingSystemFamily.rb +8 -2
  36. data/lib/upguard/OperatingSystemFamilyList.rb +17 -3
  37. data/lib/upguard/OperatingSystemList.rb +17 -3
  38. data/lib/upguard/Pluggable.rb +81 -0
  39. data/lib/upguard/PluggableList.rb +53 -0
  40. data/lib/upguard/Policy.rb +34 -0
  41. data/lib/upguard/PolicyList.rb +17 -3
  42. data/lib/upguard/ScheduledJob.rb +11 -1
  43. data/lib/upguard/ScheduledJobList.rb +17 -3
  44. data/lib/upguard/SystemMetric.rb +7 -0
  45. data/lib/upguard/SystemMetricList.rb +17 -3
  46. data/lib/upguard/User.rb +37 -0
  47. data/lib/upguard/UserList.rb +39 -3
  48. data/lib/upguard/Version.rb +21 -0
  49. metadata +21 -8
@@ -3,19 +3,19 @@ require 'json'
3
3
  module UpGuard
4
4
  class BaseObject
5
5
  attr_accessor :appliance_url
6
- attr_accessor :api_key
6
+ attr_accessor :appliance_api_key
7
7
  attr_accessor :sec_key
8
8
  attr_accessor :insecure
9
9
  def from_hash(h)
10
10
  self.appliance_url = h['appliance_url'] if h.include?('appliance_url')
11
- self.api_key = h['api_key'] if h.include?('api_key')
11
+ self.appliance_api_key = h['appliance_api_key'] if h.include?('appliance_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
17
  h['appliance_url'] = self.appliance_url
18
- h['api_key'] = self.api_key
18
+ h['appliance_api_key'] = self.appliance_api_key
19
19
  h['sec_key'] = self.sec_key
20
20
  h['insecure'] = self.insecure
21
21
  return h
@@ -24,21 +24,21 @@ module UpGuard
24
24
  h = to_hash
25
25
  return h.to_json(options)
26
26
  end
27
- def initialize(appliance_url, api_key, sec_key, insecure = false)
27
+ def initialize(appliance_url, appliance_api_key, sec_key, insecure = false)
28
28
  if appliance_url.to_s.start_with?("http://") || appliance_url.to_s.start_with?("https://")
29
29
  # all good
30
30
  else
31
31
  appliance_url = "https://" + appliance_url
32
32
  end
33
33
  self.appliance_url = appliance_url
34
- self.api_key = api_key
34
+ self.appliance_api_key = appliance_api_key
35
35
  self.sec_key = sec_key
36
36
  self.insecure = insecure
37
37
  end
38
38
 
39
39
  def make_headers
40
40
  return {
41
- "Authorization" => "Token token=\"#{self.api_key}#{self.sec_key}\"",
41
+ "Authorization" => "Token token=\"#{self.appliance_api_key}#{self.sec_key}\"",
42
42
  "Content-Type" => "application/json"
43
43
  }
44
44
  end
@@ -62,9 +62,10 @@ module UpGuard
62
62
  :verify => (self.insecure == false),
63
63
  :body => body.to_json
64
64
  )
65
- if ["200", "201"].include?(response.code.to_s) == false
65
+ if ["200", "201", "204"].include?(response.code.to_s) == false
66
66
  raise response.body
67
67
  end
68
+ return true if response.code.to_s == "204"
68
69
  obj = JSON.parse(response.body)
69
70
  return obj
70
71
  end
@@ -0,0 +1,55 @@
1
+ module UpGuard
2
+ class ChangeRequest < BaseObject
3
+ attr_accessor :data
4
+ attr_accessor :ended_at
5
+ attr_accessor :external_id
6
+ attr_accessor :id
7
+ attr_accessor :planned_end_at
8
+ attr_accessor :planned_start_at
9
+ attr_accessor :short_description
10
+ attr_accessor :started_at
11
+ attr_accessor :url
12
+ def initialize(appliance_url, appliance_api_key, sec_key, insecure = false)
13
+ super(appliance_url, appliance_api_key, sec_key, insecure)
14
+ self.data = nil
15
+ self.ended_at = nil
16
+ self.external_id = nil
17
+ self.id = nil
18
+ self.planned_end_at = nil
19
+ self.planned_start_at = nil
20
+ self.short_description = nil
21
+ self.started_at = nil
22
+ self.url = nil
23
+ end
24
+
25
+ def from_hash(h)
26
+ self.data = h['data'] if h.include?('data')
27
+ self.ended_at = h['ended_at'] if h.include?('ended_at')
28
+ self.external_id = h['external_id'] if h.include?('external_id')
29
+ self.id = h['id'] if h.include?('id')
30
+ self.planned_end_at = h['planned_end_at'] if h.include?('planned_end_at')
31
+ self.planned_start_at = h['planned_start_at'] if h.include?('planned_start_at')
32
+ self.short_description = h['short_description'] if h.include?('short_description')
33
+ self.started_at = h['started_at'] if h.include?('started_at')
34
+ self.url = h['url'] if h.include?('url')
35
+ end
36
+ def to_hash
37
+ h = {}
38
+ h['data'] = self.data
39
+ h['ended_at'] = self.ended_at
40
+ h['external_id'] = self.external_id
41
+ h['id'] = self.id
42
+ h['planned_end_at'] = self.planned_end_at
43
+ h['planned_start_at'] = self.planned_start_at
44
+ h['short_description'] = self.short_description
45
+ h['started_at'] = self.started_at
46
+ h['url'] = self.url
47
+ return h
48
+ end
49
+ def to_json(options = nil)
50
+ h = to_hash
51
+ return h.to_json(options)
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,53 @@
1
+ module UpGuard
2
+ class ChangeRequestList < BaseObject
3
+ def from_hash(h)
4
+ end
5
+ def to_hash
6
+ h = {}
7
+ return h
8
+ end
9
+ def to_json(options = nil)
10
+ h = to_hash
11
+ return h.to_json(options)
12
+ end
13
+ def initialize(appliance_url, appliance_api_key, sec_key, insecure)
14
+ super(appliance_url, appliance_api_key, sec_key, insecure)
15
+ @inner_list = []
16
+ end
17
+
18
+
19
+ def [](idx)
20
+ return @inner_list[idx]
21
+ end
22
+
23
+
24
+ def count
25
+ return @inner_list.count
26
+ end
27
+
28
+
29
+
30
+ def each(&block)
31
+ @inner_list.each(&block)
32
+ end
33
+
34
+
35
+
36
+ def <<(obj)
37
+ if ["ChangeRequest", "UpGuard::ChangeRequest"].include?(obj.class.name)
38
+ @inner_list << obj
39
+ else
40
+ raise "Can only append 'ChangeRequest' to 'ChangeRequestList'"
41
+ end
42
+ end
43
+
44
+
45
+
46
+ def to_json
47
+ return @inner_list.to_json
48
+ end
49
+
50
+
51
+
52
+ end
53
+ end
@@ -1,18 +1,39 @@
1
1
  module UpGuard
2
2
  class ConnectionManager < BaseObject
3
+ attr_accessor :agent_version
4
+ attr_accessor :agent_type
3
5
  attr_accessor :channels
4
6
  attr_accessor :connection_manager_group_id
5
7
  attr_accessor :created_at
6
8
  attr_accessor :id
9
+ attr_accessor :ip_address
7
10
  attr_accessor :hostname
8
11
  attr_accessor :last_contact
9
12
  attr_accessor :stats
10
13
  attr_accessor :updated_at
14
+ def initialize(appliance_url, appliance_api_key, sec_key, insecure = false)
15
+ super(appliance_url, appliance_api_key, sec_key, insecure)
16
+ self.agent_version = nil
17
+ self.agent_type = nil
18
+ self.channels = nil
19
+ self.connection_manager_group_id = nil
20
+ self.created_at = nil
21
+ self.id = nil
22
+ self.ip_address = nil
23
+ self.hostname = nil
24
+ self.last_contact = nil
25
+ self.stats = nil
26
+ self.updated_at = nil
27
+ end
28
+
11
29
  def from_hash(h)
30
+ self.agent_version = h['agent_version'] if h.include?('agent_version')
31
+ self.agent_type = h['agent_type'] if h.include?('agent_type')
12
32
  self.channels = h['channels'] if h.include?('channels')
13
33
  self.connection_manager_group_id = h['connection_manager_group_id'] if h.include?('connection_manager_group_id')
14
34
  self.created_at = h['created_at'] if h.include?('created_at')
15
35
  self.id = h['id'] if h.include?('id')
36
+ self.ip_address = h['ip_address'] if h.include?('ip_address')
16
37
  self.hostname = h['hostname'] if h.include?('hostname')
17
38
  self.last_contact = h['last_contact'] if h.include?('last_contact')
18
39
  self.stats = h['stats'] if h.include?('stats')
@@ -20,10 +41,13 @@ module UpGuard
20
41
  end
21
42
  def to_hash
22
43
  h = {}
44
+ h['agent_version'] = self.agent_version
45
+ h['agent_type'] = self.agent_type
23
46
  h['channels'] = self.channels
24
47
  h['connection_manager_group_id'] = self.connection_manager_group_id
25
48
  h['created_at'] = self.created_at
26
49
  h['id'] = self.id
50
+ h['ip_address'] = self.ip_address
27
51
  h['hostname'] = self.hostname
28
52
  h['last_contact'] = self.last_contact
29
53
  h['stats'] = self.stats
@@ -37,7 +61,7 @@ module UpGuard
37
61
 
38
62
  def connection_manager_group
39
63
  obj = http_get("/api/v2/connection_manager_groups/{connection_manager_group_id}.json")
40
- elem = ConnectionManagerGroup.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
64
+ elem = ConnectionManagerGroup.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
41
65
  elem.id = obj["id"]
42
66
  elem.name = obj["name"]
43
67
  return elem
@@ -1,20 +1,28 @@
1
1
  module UpGuard
2
2
  class ConnectionManagerGroup < BaseObject
3
+ attr_accessor :api_key
3
4
  attr_accessor :id
4
5
  attr_accessor :name
5
- attr_accessor :organisation_id
6
6
  attr_accessor :status
7
+ def initialize(appliance_url, appliance_api_key, sec_key, insecure = false)
8
+ super(appliance_url, appliance_api_key, sec_key, insecure)
9
+ self.api_key = nil
10
+ self.id = nil
11
+ self.name = nil
12
+ self.status = nil
13
+ end
14
+
7
15
  def from_hash(h)
16
+ self.api_key = h['api_key'] if h.include?('api_key')
8
17
  self.id = h['id'] if h.include?('id')
9
18
  self.name = h['name'] if h.include?('name')
10
- self.organisation_id = h['organisation_id'] if h.include?('organisation_id')
11
19
  self.status = h['status'] if h.include?('status')
12
20
  end
13
21
  def to_hash
14
22
  h = {}
23
+ h['api_key'] = self.api_key
15
24
  h['id'] = self.id
16
25
  h['name'] = self.name
17
- h['organisation_id'] = self.organisation_id
18
26
  h['status'] = self.status
19
27
  return h
20
28
  end
@@ -22,12 +30,14 @@ module UpGuard
22
30
  h = to_hash
23
31
  return h.to_json(options)
24
32
  end
33
+ STATUS_DISABLED = 0
34
+ STATUS_ACTIVE = 1
25
35
 
26
36
  def connection_managers
27
- obj = http_get("todo")
28
- the_list = ConnectionManagerList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
37
+ obj = http_get("/api/v2/connection_manager_groups/#{self.id}/connection_managers.json")
38
+ the_list = ConnectionManagerList.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
29
39
  obj.each do |x|
30
- elem = ConnectionManager.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
40
+ elem = ConnectionManager.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
31
41
  elem.id = x["id"] if x.include?("id")
32
42
  elem.name = x["name"] if x.include?("name")
33
43
  the_list << elem
@@ -10,12 +10,22 @@ module UpGuard
10
10
  h = to_hash
11
11
  return h.to_json(options)
12
12
  end
13
- def initialize(appliance_url, api_key, sec_key, insecure)
14
- super(appliance_url, api_key, sec_key, insecure)
13
+ def initialize(appliance_url, appliance_api_key, sec_key, insecure)
14
+ super(appliance_url, appliance_api_key, sec_key, insecure)
15
15
  @inner_list = []
16
16
  end
17
17
 
18
18
 
19
+ def [](idx)
20
+ return @inner_list[idx]
21
+ end
22
+
23
+
24
+ def count
25
+ return @inner_list.count
26
+ end
27
+
28
+
19
29
 
20
30
  def each(&block)
21
31
  @inner_list.each(&block)
@@ -24,7 +34,11 @@ module UpGuard
24
34
 
25
35
 
26
36
  def <<(obj)
27
- @inner_list << obj
37
+ if ["ConnectionManagerGroup", "UpGuard::ConnectionManagerGroup"].include?(obj.class.name)
38
+ @inner_list << obj
39
+ else
40
+ raise "Can only append 'ConnectionManagerGroup' to 'ConnectionManagerGroupList'"
41
+ end
28
42
  end
29
43
 
30
44
 
@@ -10,12 +10,22 @@ module UpGuard
10
10
  h = to_hash
11
11
  return h.to_json(options)
12
12
  end
13
- def initialize(appliance_url, api_key, sec_key, insecure)
14
- super(appliance_url, api_key, sec_key, insecure)
13
+ def initialize(appliance_url, appliance_api_key, sec_key, insecure)
14
+ super(appliance_url, appliance_api_key, sec_key, insecure)
15
15
  @inner_list = []
16
16
  end
17
17
 
18
18
 
19
+ def [](idx)
20
+ return @inner_list[idx]
21
+ end
22
+
23
+
24
+ def count
25
+ return @inner_list.count
26
+ end
27
+
28
+
19
29
 
20
30
  def each(&block)
21
31
  @inner_list.each(&block)
@@ -24,7 +34,11 @@ module UpGuard
24
34
 
25
35
 
26
36
  def <<(obj)
27
- @inner_list << obj
37
+ if ["ConnectionManager", "UpGuard::ConnectionManager"].include?(obj.class.name)
38
+ @inner_list << obj
39
+ else
40
+ raise "Can only append 'ConnectionManager' to 'ConnectionManagerList'"
41
+ end
28
42
  end
29
43
 
30
44
 
@@ -10,6 +10,20 @@ module UpGuard
10
10
  attr_accessor :updated_at
11
11
  attr_accessor :created_at
12
12
  attr_accessor :weight
13
+ def initialize(appliance_url, appliance_api_key, sec_key, insecure = false)
14
+ super(appliance_url, appliance_api_key, sec_key, insecure)
15
+ self.description = nil
16
+ self.id = nil
17
+ self.name = nil
18
+ self.node_rules = nil
19
+ self.short_description = nil
20
+ self.updated_by = nil
21
+ self.created_by = nil
22
+ self.updated_at = nil
23
+ self.created_at = nil
24
+ self.weight = nil
25
+ end
26
+
13
27
  def from_hash(h)
14
28
  self.description = h['description'] if h.include?('description')
15
29
  self.id = h['id'] if h.include?('id')
@@ -82,9 +96,9 @@ module UpGuard
82
96
 
83
97
  def nodes
84
98
  obj = http_get("/api/v2/environments/#{self.id}/nodes.json")
85
- the_list = NodeList.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
99
+ the_list = NodeList.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
86
100
  obj.each do |x|
87
- elem = Node.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
101
+ elem = Node.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
88
102
  elem.id = x["id"] if x.include?("id")
89
103
  elem.name = x["name"] if x.include?("name")
90
104
  the_list << elem
@@ -10,12 +10,22 @@ module UpGuard
10
10
  h = to_hash
11
11
  return h.to_json(options)
12
12
  end
13
- def initialize(appliance_url, api_key, sec_key, insecure)
14
- super(appliance_url, api_key, sec_key, insecure)
13
+ def initialize(appliance_url, appliance_api_key, sec_key, insecure)
14
+ super(appliance_url, appliance_api_key, sec_key, insecure)
15
15
  @inner_list = []
16
16
  end
17
17
 
18
18
 
19
+ def [](idx)
20
+ return @inner_list[idx]
21
+ end
22
+
23
+
24
+ def count
25
+ return @inner_list.count
26
+ end
27
+
28
+
19
29
 
20
30
  def each(&block)
21
31
  @inner_list.each(&block)
@@ -24,7 +34,11 @@ module UpGuard
24
34
 
25
35
 
26
36
  def <<(obj)
27
- @inner_list << obj
37
+ if ["Environment", "UpGuard::Environment"].include?(obj.class.name)
38
+ @inner_list << obj
39
+ else
40
+ raise "Can only append 'Environment' to 'EnvironmentList'"
41
+ end
28
42
  end
29
43
 
30
44
 
@@ -4,11 +4,22 @@ module UpGuard
4
4
  attr_accessor :type_id
5
5
  attr_accessor :environment_id
6
6
  attr_accessor :created_at
7
+ attr_accessor :variables
8
+ def initialize(appliance_url, appliance_api_key, sec_key, insecure = false)
9
+ super(appliance_url, appliance_api_key, sec_key, insecure)
10
+ self.id = nil
11
+ self.type_id = nil
12
+ self.environment_id = nil
13
+ self.created_at = nil
14
+ self.variables = EventVariables.new(appliance_url, appliance_api_key, sec_key, insecure)
15
+ end
16
+
7
17
  def from_hash(h)
8
18
  self.id = h['id'] if h.include?('id')
9
19
  self.type_id = h['type_id'] if h.include?('type_id')
10
20
  self.environment_id = h['environment_id'] if h.include?('environment_id')
11
21
  self.created_at = h['created_at'] if h.include?('created_at')
22
+ self.variables = h['variables'] if h.include?('variables')
12
23
  end
13
24
  def to_hash
14
25
  h = {}
@@ -16,6 +27,7 @@ module UpGuard
16
27
  h['type_id'] = self.type_id
17
28
  h['environment_id'] = self.environment_id
18
29
  h['created_at'] = self.created_at
30
+ h['variables'] = self.variables
19
31
  return h
20
32
  end
21
33
  def to_json(options = nil)
@@ -25,7 +37,7 @@ module UpGuard
25
37
 
26
38
  def environment
27
39
  obj = http_get("/api/v2/environments/#{self.environment_id}.json")
28
- elem = Environment.new(self.appliance_url, self.api_key, self.sec_key, self.insecure)
40
+ elem = Environment.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
29
41
  elem.id = obj["id"]
30
42
  elem.name = obj["name"]
31
43
  elem.organisation_id = obj["organisation_id"]