Class: ZabbixApi::Usergroups

Inherits:
Basic
  • Object
show all
Defined in:
lib/zabbixapi/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_or_create, #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 ZabbixApi::Basic

Instance Method Details

#add_user(data) ⇒ Integer

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)

    Zabbix object id (usergroup)

Raises:

  • (ApiError)

    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.



49
50
51
# File 'lib/zabbixapi/classes/usergroups.rb', line 49

def add_user(data)
  update_users(data)
end

#indentifyString

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

Returns:

  • (String)


20
21
22
# File 'lib/zabbixapi/classes/usergroups.rb', line 20

def indentify
  'name'
end

#keyString

The key field name used for Usergroup objects via Zabbix API

Returns:

  • (String)


13
14
15
# File 'lib/zabbixapi/classes/usergroups.rb', line 13

def key
  'usrgrpid'
end

#method_nameString

The method name used for interacting with Usergroups via Zabbix API

Returns:

  • (String)


6
7
8
# File 'lib/zabbixapi/classes/usergroups.rb', line 6

def method_name
  'usergroup'
end

#permissions(data) ⇒ Integer

Set permissions for usergroup using Zabbix API

Parameters:

  • data (Hash)

    Needs to include usrgrpids and hostgroupids along with permissions to set

Returns:

  • (Integer)

    Zabbix object id (usergroup)

Raises:

  • (ApiError)

    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.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/zabbixapi/classes/usergroups.rb', line 30

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

Update users in usergroups using Zabbix API

Parameters:

  • data (Hash)

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

Returns:

  • (Integer)

    Zabbix object id (usergroup)

Raises:

  • (ApiError)

    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.



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/zabbixapi/classes/usergroups.rb', line 59

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