Class: Wavefront::Account

Inherits:
CoreApi
  • Object
show all
Includes:
Mixin::User
Defined in:
lib/wavefront-sdk/account.rb

Overview

Manage and query Wavefront accounts. ‘/account/serviceaccount’ API paths are covered in the Wavefront::ServiceAccount class.

Many of these methods are duplicated in the User class. This reflects the layout of the API.

Instance Attribute Summary

Attributes inherited from CoreApi

#api, #creds, #logger, #opts

Instance Method Summary collapse

Methods included from Mixin::User

#validate_account_list, #validate_role_list, #validate_user_list, #validate_usergroup_list

Methods inherited from CoreApi

#api_base, #api_path, #hash_for_update, #initialize, #setup_api, #time_to_ms

Methods included from Mixins

#log, #parse_relative_time, #parse_time, #relative_time, #time_multiplier, #valid_relative_time?

Methods included from Validators

#uuid?, #wf_account_id?, #wf_alert_id?, #wf_alert_severity?, #wf_apitoken_id?, #wf_aws_external_id?, #wf_cloudintegration_id?, #wf_dashboard_id?, #wf_derivedmetric_id?, #wf_distribution?, #wf_distribution_count?, #wf_distribution_interval?, #wf_distribution_values?, #wf_epoch?, #wf_event_id?, #wf_granularity?, #wf_ingestionpolicy_id?, #wf_integration_id?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_metricspolicy_id?, #wf_monitoredapplication_id?, #wf_monitoredcluster_id?, #wf_ms_ts?, #wf_name?, #wf_notificant_id?, #wf_permission?, #wf_point?, #wf_point_tag?, #wf_point_tags?, #wf_proxy_id?, #wf_role_id?, #wf_sampling_value?, #wf_savedsearch_entity?, #wf_savedsearch_id?, #wf_serviceaccount_id?, #wf_source_id?, #wf_spansamplingpolicy_id?, #wf_string?, #wf_tag?, #wf_trace?, #wf_ts?, #wf_user_id?, #wf_usergroup_id?, #wf_value?, #wf_version?, #wf_webhook_id?

Constructor Details

This class inherits a constructor from Wavefront::CoreApi

Instance Method Details

#add_ingestion_policy(policy_id, id_list) ⇒ Wavefront::Response

POST /api/v2/account/addingestionpolicy Add a specific ingestion policy to multiple accounts

Parameters:

  • policy_id (String)

    ID of the ingestion policy

  • id_list (Array[String])

    list of accounts to be put in policy

Returns:



177
178
179
180
181
182
183
184
# File 'lib/wavefront-sdk/account.rb', line 177

def add_ingestion_policy(policy_id, id_list)
  wf_ingestionpolicy_id?(policy_id)
  (id_list)
  api.post('addingestionpolicy',
           { ingestionPolicyId: policy_id,
             accounts: id_list },
           'application/json')
end

#add_roles(id, role_list) ⇒ Wavefront::Response

POST /api/v2/account/id/addRoles Add specific roles to the account (user or service account)

Parameters:

  • id (String)

    ID of the account

  • role_list (Array[String])

    list of roles to add

Returns:



81
82
83
84
85
# File 'lib/wavefront-sdk/account.rb', line 81

def add_roles(id, role_list)
  (id)
  validate_role_list(role_list)
  api.post([id, 'addRoles'].uri_concat, role_list, 'application/json')
end

#add_user_groups(id, group_list) ⇒ Wavefront::Response

POST /api/v2/account/id/addUserGroups Adds specific user groups to the account (user or service account)

Parameters:

  • id (String)

    ID of the account

  • group_list (Array[String])

    list of groups to add

Returns:



93
94
95
96
97
98
# File 'lib/wavefront-sdk/account.rb', line 93

def add_user_groups(id, group_list)
  (id)
  validate_usergroup_list(group_list)
  api.post([id, 'addUserGroups'].uri_concat, group_list,
           'application/json')
end

#adminsObject

GET /api/v2/account/user/admin Get all users with Accounts permission



50
51
52
# File 'lib/wavefront-sdk/account.rb', line 50

def admins
  api.get('user/admin')
end

#business_functions(id) ⇒ Wavefront::Response

GET /api/v2/account/id/businessFunctions Returns business functions of a specific account (user or service account).

Parameters:

Returns:



106
107
108
109
# File 'lib/wavefront-sdk/account.rb', line 106

def business_functions(id)
  (id)
  api.get([id, 'businessFunctions'].uri_concat)
end

#delete(id) ⇒ Wavefront::Response

DELETE /api/v2/account/id Deletes an account (user or service account) identified by id

Parameters:

  • id (String)

    ID of the account

Returns:



32
33
34
35
# File 'lib/wavefront-sdk/account.rb', line 32

def delete(id)
  (id)
  api.delete(id)
end

#delete_accounts(id_list) ⇒ Wavefront::Response

POST /api/v2/account/deleteAccounts Deletes multiple accounts (users or service accounts)

Parameters:

  • id (String)

    ID of the account

  • group_list (Array[String])

    list of accounts to delete

Returns:



208
209
210
211
# File 'lib/wavefront-sdk/account.rb', line 208

def delete_accounts(id_list)
  (id_list)
  api.post('deleteAccounts', id_list, 'application/json')
end

#describe(id) ⇒ Wavefront::Response

GET /api/v2/account/id Get a specific account (user or service account)

Parameters:

  • id (String)

    ID of the proxy

Returns:



42
43
44
45
# File 'lib/wavefront-sdk/account.rb', line 42

def describe(id)
  (id)
  api.get(id)
end

#grant(id, permission) ⇒ Wavefront::Response

POST /api/v2/account/id/grant/permission Grants a specific permission to account (user or service account) POST /api/v2/account/grant/permission Grants a specific permission to multiple accounts (users or service accounts)

Parameters:

  • id_list (Array[String], String)

    single account ID or list of account IDs

  • permission (String)

    permission group to grant to user.

Returns:



146
147
148
149
150
151
152
# File 'lib/wavefront-sdk/account.rb', line 146

def grant(id, permission)
  if id.is_a?(String)
    grant_to_id(id, permission)
  else
    grant_to_multiple(id, permission)
  end
end

#list(offset = 0, limit = 100) ⇒ Wavefront::Response

GET /api/v2/account Get all accounts (users and service accounts) of a customer

Parameters:

  • offset (Int) (defaults to: 0)

    account at which the list begins

  • limit (Int) (defaults to: 100)

    the number of accounts to return

Returns:



23
24
25
# File 'lib/wavefront-sdk/account.rb', line 23

def list(offset = 0, limit = 100)
  api.get('', offset: offset, limit: limit)
end

#remove_ingestion_policy(policy_id, id_list) ⇒ Wavefront::Response

POST /api/v2/account/removeingestionpolicies Removes ingestion policies from multiple accounts. The API path says “policies” but I’ve made the method name “policy” for consistency.

Parameters:

  • policy_id (String)

    ID of the ingestion policy

  • id_list (Array[String])

    list of accounts to be put in policy

Returns:



193
194
195
196
197
198
199
200
# File 'lib/wavefront-sdk/account.rb', line 193

def remove_ingestion_policy(policy_id, id_list)
  wf_ingestionpolicy_id?(policy_id)
  (id_list)
  api.post('removeingestionpolicies',
           { ingestionPolicyId: policy_id,
             accounts: id_list },
           'application/json')
end

#remove_roles(id, role_list) ⇒ Wavefront::Response

POST /api/v2/account/id/removeRoles Removes specific roles from the account (user or service account)

Parameters:

  • id (String)

    ID of the account

  • role_list (Array[String])

    list of roles to remove

Returns:



117
118
119
120
121
# File 'lib/wavefront-sdk/account.rb', line 117

def remove_roles(id, role_list)
  (id)
  validate_role_list(role_list)
  api.post([id, 'removeRoles'].uri_concat, role_list, 'application/json')
end

#remove_user_groups(id, group_list) ⇒ Wavefront::Response

POST /api/v2/account/id/removeUserGroups Removes specific user groups from the account (user or service account)

Parameters:

  • id (String)

    ID of the account

  • group_list (Array[String])

    list of groups to remove

Returns:



129
130
131
132
133
134
# File 'lib/wavefront-sdk/account.rb', line 129

def remove_user_groups(id, group_list)
  (id)
  validate_usergroup_list(group_list)
  api.post([id, 'removeUserGroups'].uri_concat, group_list,
           'application/json')
end

#revoke(id, permission) ⇒ Wavefront::Response

POST /api/v2/account/id/revoke/permission Revokes a specific permission from account (user or service account) POST /api/v2/account/revoke/permission Revokes a specific permission from multiple accounts (users or service accounts

Parameters:

  • id (String, Array[String])

    ID of the user, or list of user IDs

  • permission (String)

    permission group to revoke from user.

Returns:



163
164
165
166
167
168
169
# File 'lib/wavefront-sdk/account.rb', line 163

def revoke(id, permission)
  if id.is_a?(String)
    revoke_from_id(id, permission)
  else
    revoke_from_multiple(id, permission)
  end
end

#update_perms(id, body, modify = true) ⇒ Wavefront::Response

PUT /api/v2/account/user/id Update user with given user groups and permissions.

Parameters:

  • id (String)

    a Wavefront account ID

  • body (Hash)

    key-value hash of the parameters you wish to change

  • modify (true, false) (defaults to: true)

    if true, use #describe() to get a hash describing the existing object, and modify that with the new body. If false, pass the new body straight through.

Returns:

Raises:

  • (ArgumentError)


65
66
67
68
69
70
71
72
73
# File 'lib/wavefront-sdk/account.rb', line 65

def update_perms(id, body, modify = true)
  (id)
  raise ArgumentError unless body.is_a?(Hash)

  return api.put(['user', id], body, 'application/json') unless modify

  api.put(['user', id], hash_for_update(describe(id).response, body),
          'application/json')
end

#user_create(body, send_email = false) ⇒ Object

Raises:

  • (ArgumentError)


223
224
225
226
227
228
229
# File 'lib/wavefront-sdk/account.rb', line 223

def user_create(body, send_email = false)
  raise ArgumentError unless body.is_a?(Hash)

  uri = send_email ? "?sendEmail=#{send_email}" : 'user'

  api.post(uri, body, 'application/json')
end

#user_describe(id) ⇒ Wavefront::Response

GET /api/v2/account/user/id Retrieves a user by identifier (email address)

Parameters:

  • id (String)

    ID of the proxy

Returns:



254
255
256
257
# File 'lib/wavefront-sdk/account.rb', line 254

def user_describe(id)
  wf_user_id?(id)
  api.get(['user', id].uri_concat)
end

#user_invite(body) ⇒ Wavefront::Response

POST /api/v2/account/user/invite Invite user accounts with given user groups and permissions.

Parameters:

  • body (Array[Hash])

    array of hashes, each hash describing a user. See API docs for more details. It is your responsibility to validate the data which describes each user.

Returns:

Raises:

  • (ArgumentError)


266
267
268
269
270
271
# File 'lib/wavefront-sdk/account.rb', line 266

def user_invite(body)
  raise ArgumentError unless body.is_a?(Array)
  raise ArgumentError unless body.first.is_a?(Hash)

  api.post('user/invite', body, 'application/json')
end

#user_list(offset = 0, limit = 100) ⇒ Wavefront::Response

GET /api/v2/account/user Get all user accounts

Parameters:

  • offset (Int) (defaults to: 0)

    user account at which the list begins

  • limit (Int) (defaults to: 100)

    the number of user accounts to return

Returns:



219
220
221
# File 'lib/wavefront-sdk/account.rb', line 219

def user_list(offset = 0, limit = 100)
  api.get('user', offset: offset, limit: limit)
end

#user_update(body, modify = true) ⇒ Wavefront::Response

POST /api/v2/account/user Creates or updates a user account

Parameters:

  • id (String)

    a Wavefront user ID

  • body (Hash)

    key-value hash of the parameters you wish to change

  • modify (true, false) (defaults to: true)

    if true, use #describe() to get a hash describing the existing object, and modify that with the new body. If false, pass the new body straight through.

Returns:

Raises:

  • (ArgumentError)


239
240
241
242
243
244
245
246
247
# File 'lib/wavefront-sdk/account.rb', line 239

def user_update(body, modify = true)
  raise ArgumentError unless body.is_a?(Hash)

  return api.post('user', body, 'application/json') unless modify

  api.post('user',
           hash_for_update(describe(id).response, body),
           'application/json')
end

#validate_accounts(id_list) ⇒ Wavefront::Response

POST /api/v2/account/validateAccounts Returns valid accounts (users and service accounts), also invalid identifiers from the given list

Parameters:

Returns:

Raises:

  • (ArgumentError)


279
280
281
282
283
# File 'lib/wavefront-sdk/account.rb', line 279

def validate_accounts(id_list)
  raise ArgumentError unless id_list.is_a?(Array)

  api.post('validateAccounts', id_list, 'application/json')
end