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_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_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:



149
150
151
152
153
154
155
156
# File 'lib/wavefront-sdk/account.rb', line 149

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:



53
54
55
56
57
# File 'lib/wavefront-sdk/account.rb', line 53

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:



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

def add_user_groups(id, group_list)
  (id)
  validate_usergroup_list(group_list)
  api.post([id, 'addUserGroups'].uri_concat, group_list,
           'application/json')
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:



78
79
80
81
# File 'lib/wavefront-sdk/account.rb', line 78

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:



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

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:



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

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:



165
166
167
168
169
170
171
172
# File 'lib/wavefront-sdk/account.rb', line 165

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:



89
90
91
92
93
# File 'lib/wavefront-sdk/account.rb', line 89

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:



101
102
103
104
105
106
# File 'lib/wavefront-sdk/account.rb', line 101

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:



135
136
137
138
139
140
141
# File 'lib/wavefront-sdk/account.rb', line 135

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

#user_create(body, send_email = false) ⇒ Object

Raises:

  • (ArgumentError)


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

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:



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

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)


238
239
240
241
242
243
# File 'lib/wavefront-sdk/account.rb', line 238

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:



191
192
193
# File 'lib/wavefront-sdk/account.rb', line 191

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)


211
212
213
214
215
216
217
218
219
# File 'lib/wavefront-sdk/account.rb', line 211

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)


251
252
253
254
255
# File 'lib/wavefront-sdk/account.rb', line 251

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

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