upguard 0.0.1 → 0.0.9

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 (38) hide show
  1. checksums.yaml +2 -5
  2. data/lib/upguard.rb +19 -0
  3. data/lib/upguard/Account.rb +346 -102
  4. data/lib/upguard/BaseObject.rb +23 -22
  5. data/lib/upguard/ConnectionManager.rb +18 -3
  6. data/lib/upguard/ConnectionManagerGroup.rb +31 -9
  7. data/lib/upguard/ConnectionManagerGroupList.rb +47 -0
  8. data/lib/upguard/ConnectionManagerList.rb +47 -0
  9. data/lib/upguard/Environment.rb +34 -11
  10. data/lib/upguard/EnvironmentList.rb +47 -0
  11. data/lib/upguard/Event.rb +3 -3
  12. data/lib/upguard/EventAction.rb +8 -2
  13. data/lib/upguard/EventActionList.rb +47 -0
  14. data/lib/upguard/Incident.rb +33 -0
  15. data/lib/upguard/IncidentList.rb +47 -0
  16. data/lib/upguard/Job.rb +60 -0
  17. data/lib/upguard/JobList.rb +47 -0
  18. data/lib/upguard/MediumType.rb +2 -2
  19. data/lib/upguard/Node.rb +54 -18
  20. data/lib/upguard/NodeGroup.rb +80 -8
  21. data/lib/upguard/NodeGroupList.rb +47 -0
  22. data/lib/upguard/NodeGroupUser.rb +21 -0
  23. data/lib/upguard/NodeGroupUserList.rb +58 -0
  24. data/lib/upguard/NodeList.rb +47 -0
  25. data/lib/upguard/NodeType.rb +2 -2
  26. data/lib/upguard/OperatingSystem.rb +3 -3
  27. data/lib/upguard/OperatingSystemFamily.rb +8 -8
  28. data/lib/upguard/OperatingSystemFamilyList.rb +47 -0
  29. data/lib/upguard/OperatingSystemList.rb +47 -0
  30. data/lib/upguard/Policy.rb +79 -0
  31. data/lib/upguard/PolicyList.rb +47 -0
  32. data/lib/upguard/ScheduledJob.rb +6 -3
  33. data/lib/upguard/ScheduledJobList.rb +47 -0
  34. data/lib/upguard/SystemMetric.rb +2 -2
  35. data/lib/upguard/SystemMetricList.rb +47 -0
  36. data/lib/upguard/User.rb +2 -2
  37. data/lib/upguard/UserList.rb +58 -0
  38. metadata +23 -4
@@ -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
  )
@@ -1,28 +1,43 @@
1
1
  module UpGuard
2
2
  class ConnectionManager < BaseObject
3
+ attr_accessor :channels
4
+ attr_accessor :connection_manager_group_id
5
+ attr_accessor :created_at
3
6
  attr_accessor :id
4
7
  attr_accessor :hostname
5
8
  attr_accessor :last_contact
9
+ attr_accessor :stats
10
+ attr_accessor :updated_at
6
11
  def from_hash(h)
12
+ self.channels = h['channels'] if h.include?('channels')
13
+ self.connection_manager_group_id = h['connection_manager_group_id'] if h.include?('connection_manager_group_id')
14
+ self.created_at = h['created_at'] if h.include?('created_at')
7
15
  self.id = h['id'] if h.include?('id')
8
16
  self.hostname = h['hostname'] if h.include?('hostname')
9
17
  self.last_contact = h['last_contact'] if h.include?('last_contact')
18
+ self.stats = h['stats'] if h.include?('stats')
19
+ self.updated_at = h['updated_at'] if h.include?('updated_at')
10
20
  end
11
21
  def to_hash
12
22
  h = {}
23
+ h['channels'] = self.channels
24
+ h['connection_manager_group_id'] = self.connection_manager_group_id
25
+ h['created_at'] = self.created_at
13
26
  h['id'] = self.id
14
27
  h['hostname'] = self.hostname
15
28
  h['last_contact'] = self.last_contact
29
+ h['stats'] = self.stats
30
+ h['updated_at'] = self.updated_at
16
31
  return h
17
32
  end
18
- def to_json
33
+ def to_json(options = nil)
19
34
  h = to_hash
20
- return h.to_json
35
+ return h.to_json(options)
21
36
  end
22
37
 
23
38
  def connection_manager_group
24
39
  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)
40
+ elem = ConnectionManagerGroup.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
26
41
  elem.id = obj["id"]
27
42
  elem.name = obj["name"]
28
43
  return elem
@@ -1,32 +1,54 @@
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
5
7
  def from_hash(h)
8
+ self.api_key = h['api_key'] if h.include?('api_key')
6
9
  self.id = h['id'] if h.include?('id')
7
10
  self.name = h['name'] if h.include?('name')
11
+ self.status = h['status'] if h.include?('status')
8
12
  end
9
13
  def to_hash
10
14
  h = {}
15
+ h['api_key'] = self.api_key
11
16
  h['id'] = self.id
12
17
  h['name'] = self.name
18
+ h['status'] = self.status
13
19
  return h
14
20
  end
15
- def to_json
21
+ def to_json(options = nil)
16
22
  h = to_hash
17
- return h.to_json
23
+ return h.to_json(options)
18
24
  end
19
25
 
20
26
  def connection_managers
21
- obj = http_get("todo")
22
- list = []
27
+ obj = http_get("/api/v2/connection_manager_groups/#{self.id}/connection_managers.json")
28
+ the_list = ConnectionManagerList.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
23
29
  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
30
+ elem = ConnectionManager.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
31
+ elem.id = x["id"] if x.include?("id")
32
+ elem.name = x["name"] if x.include?("name")
33
+ the_list << elem
28
34
  end
29
- return list
35
+ return the_list
36
+ end
37
+
38
+
39
+ def save
40
+ if self.id.to_i == 0
41
+ return create
42
+ else
43
+ raise "Cannot update a ConnectionManagerGroup"
44
+ end
45
+ end
46
+
47
+
48
+ def create
49
+ h = to_hash
50
+ out = http_post("/api/v2/connection_manager_groups.json", h)
51
+ from_hash(out)
30
52
  end
31
53
 
32
54
 
@@ -0,0 +1,47 @@
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
+ def count
19
+ return @inner_list.count
20
+ end
21
+
22
+ def [](idx)
23
+ return @inner_list[idx]
24
+ end
25
+
26
+
27
+
28
+ def each(&block)
29
+ @inner_list.each(&block)
30
+ end
31
+
32
+
33
+
34
+ def <<(obj)
35
+ @inner_list << obj
36
+ end
37
+
38
+
39
+
40
+ def to_json
41
+ return @inner_list.to_json
42
+ end
43
+
44
+
45
+
46
+ end
47
+ end
@@ -0,0 +1,47 @@
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
+ def count
19
+ return @inner_list.count
20
+ end
21
+
22
+ def [](idx)
23
+ return @inner_list[idx]
24
+ end
25
+
26
+
27
+
28
+ def each(&block)
29
+ @inner_list.each(&block)
30
+ end
31
+
32
+
33
+
34
+ def <<(obj)
35
+ @inner_list << obj
36
+ end
37
+
38
+
39
+
40
+ def to_json
41
+ return @inner_list.to_json
42
+ end
43
+
44
+
45
+
46
+ end
47
+ end
@@ -1,26 +1,44 @@
1
1
  module UpGuard
2
2
  class Environment < BaseObject
3
+ attr_accessor :description
3
4
  attr_accessor :id
4
5
  attr_accessor :name
5
- attr_accessor :organisation_id
6
+ attr_accessor :node_rules
6
7
  attr_accessor :short_description
8
+ attr_accessor :updated_by
9
+ attr_accessor :created_by
10
+ attr_accessor :updated_at
11
+ attr_accessor :created_at
12
+ attr_accessor :weight
7
13
  def from_hash(h)
14
+ self.description = h['description'] if h.include?('description')
8
15
  self.id = h['id'] if h.include?('id')
9
16
  self.name = h['name'] if h.include?('name')
10
- self.organisation_id = h['organisation_id'] if h.include?('organisation_id')
17
+ self.node_rules = h['node_rules'] if h.include?('node_rules')
11
18
  self.short_description = h['short_description'] if h.include?('short_description')
19
+ self.updated_by = h['updated_by'] if h.include?('updated_by')
20
+ self.created_by = h['created_by'] if h.include?('created_by')
21
+ self.updated_at = h['updated_at'] if h.include?('updated_at')
22
+ self.created_at = h['created_at'] if h.include?('created_at')
23
+ self.weight = h['weight'] if h.include?('weight')
12
24
  end
13
25
  def to_hash
14
26
  h = {}
27
+ h['description'] = self.description
15
28
  h['id'] = self.id
16
29
  h['name'] = self.name
17
- h['organisation_id'] = self.organisation_id
30
+ h['node_rules'] = self.node_rules
18
31
  h['short_description'] = self.short_description
32
+ h['updated_by'] = self.updated_by
33
+ h['created_by'] = self.created_by
34
+ h['updated_at'] = self.updated_at
35
+ h['created_at'] = self.created_at
36
+ h['weight'] = self.weight
19
37
  return h
20
38
  end
21
- def to_json
39
+ def to_json(options = nil)
22
40
  h = to_hash
23
- return h.to_json
41
+ return h.to_json(options)
24
42
  end
25
43
 
26
44
  def load
@@ -49,6 +67,11 @@ module UpGuard
49
67
  h = to_hash
50
68
  h.delete("id")
51
69
  h.delete("organisation_id")
70
+ h.delete("updated_by")
71
+ h.delete("created_by")
72
+ h.delete("updated_at")
73
+ h.delete("created_at")
74
+ h.delete("weight")
52
75
  http_put("/api/v2/environments/#{self.id}.json", h)
53
76
  end
54
77
 
@@ -59,14 +82,14 @@ module UpGuard
59
82
 
60
83
  def nodes
61
84
  obj = http_get("/api/v2/environments/#{self.id}/nodes.json")
62
- list = []
85
+ the_list = NodeList.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
63
86
  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
87
+ elem = Node.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
88
+ elem.id = x["id"] if x.include?("id")
89
+ elem.name = x["name"] if x.include?("name")
90
+ the_list << elem
68
91
  end
69
- return list
92
+ return the_list
70
93
  end
71
94
 
72
95
 
@@ -0,0 +1,47 @@
1
+ module UpGuard
2
+ class EnvironmentList < 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
+ def count
19
+ return @inner_list.count
20
+ end
21
+
22
+ def [](idx)
23
+ return @inner_list[idx]
24
+ end
25
+
26
+
27
+
28
+ def each(&block)
29
+ @inner_list.each(&block)
30
+ end
31
+
32
+
33
+
34
+ def <<(obj)
35
+ @inner_list << obj
36
+ end
37
+
38
+
39
+
40
+ def to_json
41
+ return @inner_list.to_json
42
+ end
43
+
44
+
45
+
46
+ end
47
+ end