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

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.



48
49
50
51
52
53
54
55
56
57
# File 'lib/zabbixapi/classes/usergroups.rb', line 48

def add_user(data)
  result = @client.api_request(
    :method => 'usergroup.massAdd',
    :params => {
      :usrgrpids => data[:usrgrpids],
      :userids => data[:userids],
    }
  )
  result ? result['usrgrpids'][0].to_i : nil
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

#set_perms(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 set_perms(data)
  permission = data[:permission] || 2
  result = @client.api_request(
    :method => 'usergroup.massAdd',
    :params => {
      :usrgrpids => [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.



65
66
67
68
69
70
71
72
73
74
# File 'lib/zabbixapi/classes/usergroups.rb', line 65

def update_users(data)
  result = @client.api_request(
    :method => 'usergroup.massUpdate',
    :params => {
      :usrgrpids => data[:usrgrpids],
      :userids => data[:userids],
    }
  )
  result ? result['usrgrpids'][0].to_i : nil
end