Class: ZabbixManager::Usergroups

Inherits:
Basic
  • Object
show all
Defined in:
lib/zabbix_manager/classes/usergroups.rb

Instance Method Summary collapse

Methods inherited from Basic

#add, #all, #create, #create_or_update, #default_options, #delete, #destroy, #dump_by_id, #get, #get_full_data, #get_id, #get_key_ids, #get_key_ids_by_identify, #get_or_create, #get_or_create_keys, #get_raw, #hash_equals?, #initialize, #keys, #log, #merge_params, #normalize_array, #normalize_hash, #parse_keys, #symbolize_keys, #update

Constructor Details

This class inherits a constructor from ZabbixManager::Basic

Instance Method Details

#add_user(data) ⇒ Integer, NilClass

Deprecated.

Zabbix has removed massAdd in favor of update.

Add users to usergroup using Zabbix API

Parameters:

  • data (Hash)

    Needs to include userids and usrgrpids to mass add users to groups

Returns:

  • (Integer, NilClass)

    Zabbix object id (usergroup)

Raises:

  • (ZbxError)

    Error returned when there is a problem with the Zabbix API call.

  • (HttpError)

    Error raised when HTTP status from Zabbix Server response is not a 200 OK.



51
52
53
# File 'lib/zabbix_manager/classes/usergroups.rb', line 51

def add_user(data)
  update_users(data)
end

#identifyString

The id field name used for identifying specific Usergroup objects via Zabbix API

Returns:

  • (String)


22
23
24
# File 'lib/zabbix_manager/classes/usergroups.rb', line 22

def identify
  "name"
end

#keyString

The key field name used for Usergroup objects via Zabbix API

Returns:

  • (String)


15
16
17
# File 'lib/zabbix_manager/classes/usergroups.rb', line 15

def key
  "usrgrpid"
end

#method_nameString

The method name used for interacting with Usergroups via Zabbix API

Returns:

  • (String)


8
9
10
# File 'lib/zabbix_manager/classes/usergroups.rb', line 8

def method_name
  "usergroup"
end

#permissions(data) ⇒ Integer, NilClass

Set permissions for usergroup using Zabbix API

Parameters:

  • data (Hash)

    Needs to include usrgrpids and hostgroupids along with permissions to set

Returns:

  • (Integer, NilClass)

    Zabbix object id (usergroup)

Raises:

  • (ZbxError)

    Error returned when there is a problem with the Zabbix API call.

  • (HttpError)

    Error raised when HTTP status from Zabbix Server response is not a 200 OK.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/zabbix_manager/classes/usergroups.rb', line 32

def permissions(data)
  permission = data[:permission] || 2
  result = @client.api_request(
    method: "usergroup.update",
    params: {
      usrgrpid: data[:usrgrpid],
      rights: data[:hostgroupids].map { |t| { permission: permission, id: t } }
    }
  )
  result ? result["usrgrpids"][0].to_i : nil
end

#update_users(data) ⇒ Integer, NilClass

Update users in usergroups using Zabbix API

Parameters:

  • data (Hash)

    Needs to include userids and usrgrpids to mass update users in groups

Returns:

  • (Integer, NilClass)

    Zabbix object id (usergroup)

Raises:

  • (ZbxError)

    Error returned when there is a problem with the Zabbix API call.

  • (HttpError)

    Error raised when HTTP status from Zabbix Server response is not a 200 OK.



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/zabbix_manager/classes/usergroups.rb', line 61

def update_users(data)
  user_groups = data[:usrgrpids].map do |t|
    {
      usrgrpid: t,
      userids: data[:userids]
    }
  end
  result = @client.api_request(
    method: "usergroup.update",
    params: user_groups
  )
  result ? result["usrgrpids"][0].to_i : nil
end