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, #hash_equals?, #initialize, #keys, #log, #merge_params, #normalize_hash, #parse_keys, #symbolize_keys, #update

Constructor Details

This class inherits a constructor from ZabbixApi::Basic

Instance Method Details

#add_user(data) ⇒ Object

Update usergroup, add user

  • Args :

    • data -> Hash with :usrgrpids => id, :userids => []

  • Returns :

    • Integer


54
55
56
57
58
59
60
61
62
63
# File 'lib/zabbixapi/classes/usergroups.rb', line 54

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

#get_or_create(data) ⇒ Object

Return usrgrpid

  • Args :

    • data -> Hash with :name => “UserGroup”

  • Returns :

    • Integer


22
23
24
25
26
27
28
# File 'lib/zabbixapi/classes/usergroups.rb', line 22

def get_or_create(data)
  usrgrpid = get_id(data)
  if usrgrpid.nil?
    usrgrpid = create(data)
  end
  usrgrpid
end

#indentifyObject


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

def indentify
  "name"
end

#keyObject


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

def key
  "usrgrpid"
end

#method_nameObject


4
5
6
# File 'lib/zabbixapi/classes/usergroups.rb', line 4

def method_name
  "usergroup"
end

#set_perms(data) ⇒ Object

Set permission for usrgrp on some hostgroup

  • Args :

    • data -> Hash with :usrgrpids => id, :hostgroupids => [], :permission => 2,3 (read and read write)

  • Returns :

    • Integer


36
37
38
39
40
41
42
43
44
45
46
# File 'lib/zabbixapi/classes/usergroups.rb', line 36

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) ⇒ Object

Update usergroup, modify users

  • Args :

    • data -> Hash with :usrgrpids => id, :userids => []

  • Returns :

    • Integer


71
72
73
74
75
76
77
78
79
80
# File 'lib/zabbixapi/classes/usergroups.rb', line 71

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