Class: MMS::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/mms/agent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Agent

Returns a new instance of Agent.

Parameters:



6
7
8
# File 'lib/mms/agent.rb', line 6

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



3
4
5
# File 'lib/mms/agent.rb', line 3

def client
  @client
end

Instance Method Details

#alert_ack(alert_id, timestamp, group_id) ⇒ TrueClass, FalseClass

Parameters:

  • alert_id (String)
  • timestamp (String, Integer)
  • group_id (String)

Returns:

  • (TrueClass, FalseClass)


169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/mms/agent.rb', line 169

def alert_ack(alert_id, timestamp, group_id)
  timestamp = DateTime.now if timestamp == 'now'
  timestamp = DateTime.new(4000, 1, 1, 1, 1, 1, 1, 1) if timestamp == 'forever'

  group = find_group(group_id)

  if alert_id == 'all'
    group.alerts.each do |alert|
      alert.ack(timestamp, 'Triggered by CLI for all alerts.')
    end
  else
    group.alert(alert_id).ack(timestamp, 'Triggered by CLI.')
  end
end

#alertsArray<MMS::Resource::Alert>

Returns:



133
134
135
136
137
138
139
# File 'lib/mms/agent.rb', line 133

def alerts
  alert_list = []
  groups.each do |group|
    alert_list.concat group.alerts
  end
  alert_list.sort_by(&:created).reverse
end

#apiurl(apiurl) ⇒ Object

Parameters:

  • apiurl (String)


11
12
13
# File 'lib/mms/agent.rb', line 11

def apiurl(apiurl)
  @client.url = apiurl
end

#cluster_update(groupid, clusterid, name) ⇒ <MMS::Resource::Cluster>

Parameters:

  • groupid (String)
  • clusterid (String)
  • name (String)

Returns:



115
116
117
118
119
120
121
# File 'lib/mms/agent.rb', line 115

def cluster_update(groupid, clusterid, name)
  data = { clusterName: name }
  ret_cluster = client.patch("/groups/#{groupid}/clusters/#{clusterid}", data)
  cluster = MMS::Resource::Cluster.new
  cluster._from_hash(ret_cluster)
  cluster
end

#clustersArray<MMS::Resource::Cluster>

Returns:



103
104
105
106
107
108
109
# File 'lib/mms/agent.rb', line 103

def clusters
  cluster_list = []
  groups.each do |group|
    cluster_list.concat group.clusters
  end
  cluster_list
end

#find_group(id) ⇒ MMS::Resource::Group

Parameters:

  • id (String)

Returns:



186
187
188
# File 'lib/mms/agent.rb', line 186

def find_group(id)
  MMS::Resource::Group.find(@client, id)
end

#groupsArray<MMS::Resource::Group>

Returns:



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mms/agent.rb', line 16

def groups
  group_list = []
  client.get('/groups').each do |group|
    g = MMS::Resource::Group.new
    g.client(client)
    g.data(group)

    group_list.push g
  end
  group_list
end

#host_create(groupid, hostname, port, options = {}) ⇒ <MMS::Resource::Host>

Parameters:

  • groupid (String)
  • hostname (String)
  • port (Integer)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • username (String)

    Required if authMechanismName is MONGODB_CR. Otherwise illegal.

  • password (String)

    Required if authMechanismName is MONGODB_CR. Otherwise illegal.

  • sslEnabled (TrueClass, FalseClass)

    Must be true if the authMechanismName is MONGODB_X509. Default is false if omitted.

  • logsEnabled (TrueClass, FalseClass)

    Default is false if omitted.

  • alertsEnabled (TrueClass, FalseClass)

    Default is true if omitted.

  • profilerEnabled (TrueClass, FalseClass)

    Default is false if omitted.

  • muninPort (Integer)

    Default is 0 and Munin stats are not collected if omitted.

  • authMechanismName (String)

    Default is NONE if omitted. If set to MONGODB_CR then you must provide the username and password.

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/mms/agent.rb', line 49

def host_create(groupid, hostname, port, options = {})
  data = {}
  data[:hostname] = hostname
  data[:port] = port
  data[:username] = options[:username] || nil
  data[:password] = options[:password] || nil
  data[:sslEnabled] = options[:sslEnabled] || false
  data[:logsEnabled] = options[:logsEnabled] || false
  data[:alertsEnabled] = options[:alertsEnabled] || true
  data[:profilerEnabled] = options[:profilerEnabled] || false
  data[:muninPort] = options[:muninPort] || 0
  data[:authMechanismName] = options[:authMechanismName] || nil
  ret_host = client.post("/groups/#{groupid}/hosts", data)
  host = MMS::Resource::Host.new
  host._from_hash(ret_host)
  host
end

#host_delete(groupid, hostid) ⇒ TrueClass, FalseClass

Parameters:

  • groupid (String)
  • hostid (String)

Returns:

  • (TrueClass, FalseClass)


97
98
99
100
# File 'lib/mms/agent.rb', line 97

def host_delete(groupid, hostid)
  host = client.delete("/groups/#{groupid}/hosts/#{hostid}")
  host == {} ? true : false
end

#host_update(groupid, hostid, options = {}) ⇒ <MMS::Resource::Host>

Parameters:

  • groupid (String)
  • hostid (String)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • username (String)

    Required if authMechanismName is MONGODB_CR. Otherwise illegal.

  • password (String)

    Required if authMechanismName is MONGODB_CR. Otherwise illegal.

  • sslEnabled (TrueClass, FalseClass)

    Must be true if the authMechanismName is MONGODB_X509. Default is false if omitted.

  • logsEnabled (TrueClass, FalseClass)

    Default is false if omitted.

  • alertsEnabled (TrueClass, FalseClass)

    Default is true if omitted.

  • profilerEnabled (TrueClass, FalseClass)

    Default is false if omitted.

  • muninPort (Integer)

    Default is 0 and Munin stats are not collected if omitted.

  • authMechanismName (String)

    Default is NONE if omitted. If set to MONGODB_CR then you must provide the username and password.

Returns:



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mms/agent.rb', line 78

def host_update(groupid, hostid, options = {})
  data = {}
  data[:username] = options[:username] if options.include?(:username)
  data[:password] = options[:password] if options.include?(:password)
  data[:sslEnabled] = options[:sslEnabled] if options.include?(:sslEnabled)
  data[:logsEnabled] = options[:logsEnabled] if options.include?(:logsEnabled)
  data[:alertsEnabled] = options[:alertsEnabled] if options.include?(:alertsEnabled)
  data[:profilerEnabled] = options[:profilerEnabled] if options.include?(:profilerEnabled)
  data[:muninPort] = options[:muninPort] if options.include?(:muninPort)
  data[:authMechanismName] = options[:authMechanismName] if options.include?(:authMechanismName)
  ret_host = client.patch("/groups/#{groupid}/hosts/#{hostid}", data)
  host = MMS::Resource::Host.new
  host._from_hash(ret_host)
  host
end

#hostsArray<MMS::Resource::Host>

Returns:



29
30
31
32
33
34
35
# File 'lib/mms/agent.rb', line 29

def hosts
  host_list = []
  groups.each do |group|
    host_list.concat group.hosts
  end
  host_list
end

#restorejob_create(type_value, group_id, cluster_id) ⇒ Array<MMS::Resource::RestoreJob>

Parameters:

  • type_value (String)
  • group_id (String)
  • cluster_id (String)

Returns:



154
155
156
157
158
159
160
161
162
163
# File 'lib/mms/agent.rb', line 154

def restorejob_create(type_value, group_id, cluster_id)
  if type_value.length == 24
    find_group(group_id).cluster(cluster_id).snapshot(type_value).create_restorejob
  else
    datetime = (type_value == 'now' ? DateTime.now : DateTime.parse(type_value))
    raise('Invalid datetime. Correct `YYYY-MM-RRTH:m:sZ`') if datetime.nil?
    datetime_string = [[datetime.year, datetime.month, datetime.day].join('-'), 'T', [datetime.hour, datetime.minute, datetime.second].join(':'), 'Z'].join
    find_group(group_id).cluster(cluster_id).create_restorejob(datetime_string)
  end
end

#restorejobsArray<MMS::Resource::RestoreJob>

Returns:



142
143
144
145
146
147
148
# File 'lib/mms/agent.rb', line 142

def restorejobs
  restorejob_list = []
  clusters.each do |cluster|
    restorejob_list.concat cluster.restorejobs
  end
  restorejob_list.sort_by(&:created).reverse
end

#snapshotsArray<MMS::Resource::Snapshot>

Returns:



124
125
126
127
128
129
130
# File 'lib/mms/agent.rb', line 124

def snapshots
  snapshot_list = []
  clusters.each do |cluster|
    snapshot_list.concat cluster.snapshots
  end
  snapshot_list.sort_by(&:created_date).reverse
end