upguard 0.0.4 → 0.0.16

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 (47) hide show
  1. checksums.yaml +5 -5
  2. data/lib/upguard.rb +27 -0
  3. data/lib/upguard/Account.rb +404 -129
  4. data/lib/upguard/BaseObject.rb +23 -22
  5. data/lib/upguard/ChangeRequest.rb +55 -0
  6. data/lib/upguard/ChangeRequestList.rb +53 -0
  7. data/lib/upguard/ConnectionManager.rb +42 -3
  8. data/lib/upguard/ConnectionManagerGroup.rb +41 -9
  9. data/lib/upguard/ConnectionManagerGroupList.rb +53 -0
  10. data/lib/upguard/ConnectionManagerList.rb +53 -0
  11. data/lib/upguard/Environment.rb +48 -11
  12. data/lib/upguard/EnvironmentList.rb +53 -0
  13. data/lib/upguard/Event.rb +15 -3
  14. data/lib/upguard/EventAction.rb +18 -2
  15. data/lib/upguard/EventActionList.rb +53 -0
  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 +12 -2
  20. data/lib/upguard/IncidentList.rb +53 -0
  21. data/lib/upguard/Job.rb +70 -0
  22. data/lib/upguard/JobList.rb +53 -0
  23. data/lib/upguard/MediumType.rb +5 -2
  24. data/lib/upguard/Node.rb +86 -9
  25. data/lib/upguard/NodeGroup.rb +97 -8
  26. data/lib/upguard/NodeGroupList.rb +64 -0
  27. data/lib/upguard/NodeGroupUser.rb +27 -0
  28. data/lib/upguard/NodeGroupUserList.rb +64 -0
  29. data/lib/upguard/NodeList.rb +53 -0
  30. data/lib/upguard/NodeMediumInfo.rb +49 -0
  31. data/lib/upguard/NodeType.rb +12 -2
  32. data/lib/upguard/OperatingSystem.rb +11 -3
  33. data/lib/upguard/OperatingSystemFamily.rb +14 -8
  34. data/lib/upguard/OperatingSystemFamilyList.rb +53 -0
  35. data/lib/upguard/OperatingSystemList.rb +53 -0
  36. data/lib/upguard/Pluggable.rb +81 -0
  37. data/lib/upguard/PluggableList.rb +53 -0
  38. data/lib/upguard/Policy.rb +87 -0
  39. data/lib/upguard/PolicyList.rb +53 -0
  40. data/lib/upguard/ScheduledJob.rb +16 -3
  41. data/lib/upguard/ScheduledJobList.rb +53 -0
  42. data/lib/upguard/SystemMetric.rb +9 -2
  43. data/lib/upguard/SystemMetricList.rb +53 -0
  44. data/lib/upguard/User.rb +39 -2
  45. data/lib/upguard/UserList.rb +75 -0
  46. data/lib/upguard/Version.rb +21 -0
  47. metadata +37 -10
@@ -2,51 +2,54 @@ require 'httparty'
2
2
  require 'json'
3
3
  module UpGuard
4
4
  class BaseObject
5
- attr_accessor :appliance_hostname
6
- attr_accessor :api_key
5
+ attr_accessor :appliance_url
6
+ attr_accessor :appliance_api_key
7
7
  attr_accessor :sec_key
8
8
  attr_accessor :insecure
9
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')
10
+ self.appliance_url = h['appliance_url'] if h.include?('appliance_url')
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
- h['appliance_hostname'] = self.appliance_hostname
18
- h['api_key'] = self.api_key
17
+ h['appliance_url'] = self.appliance_url
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
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(appliance_hostname, api_key, sec_key, insecure = false)
28
- self.appliance_hostname = appliance_hostname
29
- self.api_key = api_key
27
+ def initialize(appliance_url, appliance_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
34
+ self.appliance_api_key = appliance_api_key
30
35
  self.sec_key = sec_key
31
36
  self.insecure = insecure
32
37
  end
33
38
 
34
39
  def make_headers
35
40
  return {
36
- "Authorization" => "Token token=\"#{self.api_key}#{self.sec_key}\"",
41
+ "Authorization" => "Token token=\"#{self.appliance_api_key}#{self.sec_key}\"",
37
42
  "Content-Type" => "application/json"
38
43
  }
39
44
  end
40
45
 
41
46
  def http_get(path)
42
- url = "https://#{self.appliance_hostname}#{path}"
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,35 +57,33 @@ module UpGuard
54
57
  end
55
58
 
56
59
  def http_post(path, body)
57
- puts "http_post(path: #{path}, body: #{body})"
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
- if ["200", "201"].include?(response.code.to_s) == false
64
- puts "Exception: #{response.code}: #{response.body}"
65
+ if ["200", "201", "204"].include?(response.code.to_s) == false
65
66
  raise response.body
66
67
  end
68
+ return true if response.code.to_s == "204"
67
69
  obj = JSON.parse(response.body)
68
70
  return obj
69
71
  end
70
72
 
71
73
  def http_put(path, body)
72
- response = HTTParty.put("https://#{self.appliance_hostname}#{path}",
74
+ response = HTTParty.put("#{self.appliance_url}#{path}",
73
75
  :headers => make_headers,
74
76
  :verify => (self.insecure == false),
75
77
  :body => body.to_json
76
78
  )
77
79
  if response.code.to_s != "204"
78
- puts "Exception: #{response.code.to_s}: #{response.body}"
79
80
  raise response.body
80
81
  end
81
82
 
82
83
  end
83
84
 
84
85
  def http_delete(path)
85
- response = HTTParty.delete("https://#{self.appliance_hostname}#{path}",
86
+ response = HTTParty.delete("#{self.appliance_url}#{path}",
86
87
  :headers => make_headers,
87
88
  :verify => (self.insecure == false)
88
89
  )
@@ -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,28 +1,67 @@
1
1
  module UpGuard
2
2
  class ConnectionManager < BaseObject
3
+ attr_accessor :agent_version
4
+ attr_accessor :agent_type
5
+ attr_accessor :channels
6
+ attr_accessor :connection_manager_group_id
7
+ attr_accessor :created_at
3
8
  attr_accessor :id
9
+ attr_accessor :ip_address
4
10
  attr_accessor :hostname
5
11
  attr_accessor :last_contact
12
+ attr_accessor :stats
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
+
6
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')
32
+ self.channels = h['channels'] if h.include?('channels')
33
+ self.connection_manager_group_id = h['connection_manager_group_id'] if h.include?('connection_manager_group_id')
34
+ self.created_at = h['created_at'] if h.include?('created_at')
7
35
  self.id = h['id'] if h.include?('id')
36
+ self.ip_address = h['ip_address'] if h.include?('ip_address')
8
37
  self.hostname = h['hostname'] if h.include?('hostname')
9
38
  self.last_contact = h['last_contact'] if h.include?('last_contact')
39
+ self.stats = h['stats'] if h.include?('stats')
40
+ self.updated_at = h['updated_at'] if h.include?('updated_at')
10
41
  end
11
42
  def to_hash
12
43
  h = {}
44
+ h['agent_version'] = self.agent_version
45
+ h['agent_type'] = self.agent_type
46
+ h['channels'] = self.channels
47
+ h['connection_manager_group_id'] = self.connection_manager_group_id
48
+ h['created_at'] = self.created_at
13
49
  h['id'] = self.id
50
+ h['ip_address'] = self.ip_address
14
51
  h['hostname'] = self.hostname
15
52
  h['last_contact'] = self.last_contact
53
+ h['stats'] = self.stats
54
+ h['updated_at'] = self.updated_at
16
55
  return h
17
56
  end
18
- def to_json
57
+ def to_json(options = nil)
19
58
  h = to_hash
20
- return h.to_json
59
+ return h.to_json(options)
21
60
  end
22
61
 
23
62
  def connection_manager_group
24
63
  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)
64
+ elem = ConnectionManagerGroup.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
26
65
  elem.id = obj["id"]
27
66
  elem.name = obj["name"]
28
67
  return elem
@@ -1,32 +1,64 @@
1
1
  module UpGuard
2
2
  class ConnectionManagerGroup < BaseObject
3
+ attr_accessor :api_key
3
4
  attr_accessor :id
4
5
  attr_accessor :name
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
+
5
15
  def from_hash(h)
16
+ self.api_key = h['api_key'] if h.include?('api_key')
6
17
  self.id = h['id'] if h.include?('id')
7
18
  self.name = h['name'] if h.include?('name')
19
+ self.status = h['status'] if h.include?('status')
8
20
  end
9
21
  def to_hash
10
22
  h = {}
23
+ h['api_key'] = self.api_key
11
24
  h['id'] = self.id
12
25
  h['name'] = self.name
26
+ h['status'] = self.status
13
27
  return h
14
28
  end
15
- def to_json
29
+ def to_json(options = nil)
16
30
  h = to_hash
17
- return h.to_json
31
+ return h.to_json(options)
18
32
  end
33
+ STATUS_DISABLED = 0
34
+ STATUS_ACTIVE = 1
19
35
 
20
36
  def connection_managers
21
- obj = http_get("todo")
22
- list = []
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)
23
39
  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
40
+ elem = ConnectionManager.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
41
+ elem.id = x["id"] if x.include?("id")
42
+ elem.name = x["name"] if x.include?("name")
43
+ the_list << elem
44
+ end
45
+ return the_list
46
+ end
47
+
48
+
49
+ def save
50
+ if self.id.to_i == 0
51
+ return create
52
+ else
53
+ raise "Cannot update a ConnectionManagerGroup"
28
54
  end
29
- return list
55
+ end
56
+
57
+
58
+ def create
59
+ h = to_hash
60
+ out = http_post("/api/v2/connection_manager_groups.json", h)
61
+ from_hash(out)
30
62
  end
31
63
 
32
64
 
@@ -0,0 +1,53 @@
1
+ module UpGuard
2
+ class ConnectionManagerGroupList < 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 ["ConnectionManagerGroup", "UpGuard::ConnectionManagerGroup"].include?(obj.class.name)
38
+ @inner_list << obj
39
+ else
40
+ raise "Can only append 'ConnectionManagerGroup' to 'ConnectionManagerGroupList'"
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
@@ -0,0 +1,53 @@
1
+ module UpGuard
2
+ class ConnectionManagerList < 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 ["ConnectionManager", "UpGuard::ConnectionManager"].include?(obj.class.name)
38
+ @inner_list << obj
39
+ else
40
+ raise "Can only append 'ConnectionManager' to 'ConnectionManagerList'"
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