Class: ZabbixApi::Users

Inherits:
Object
  • Object
show all
Defined in:
lib/zabbixapi/users.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Users

Returns a new instance of Users.



4
5
6
7
# File 'lib/zabbixapi/users.rb', line 4

def initialize(options = {})
  @client = Client.new(options)
  @options = options
end

Instance Method Details

#add(data) ⇒ Object



14
15
16
# File 'lib/zabbixapi/users.rb', line 14

def add(data)
  create(data)
end

#create(data) ⇒ Object



9
10
11
12
# File 'lib/zabbixapi/users.rb', line 9

def create(data)
  result = @client.api_request(:method => "user.create", :params => data)
  result ? result['userids'][0].to_i : nil
end

#delete(data) ⇒ Object



18
19
20
21
# File 'lib/zabbixapi/users.rb', line 18

def delete(data)
  result = @client.api_request(:method => "user.delete", :params => [:userid => data])
  result ? result['userids'][0].to_i : nil
end

#get(data) ⇒ Object



35
36
37
# File 'lib/zabbixapi/users.rb', line 35

def get(data)
  get_full_data(data)
end

#get_full_data(data) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/zabbixapi/users.rb', line 23

def get_full_data(data)
  @client.api_request(
    :method => "user.get", 
    :params => {
      :filter => {
        :name => data[:name]
      },
      :output => "extend"
      }
    )
end

#get_id(data) ⇒ Object



39
40
41
42
43
44
# File 'lib/zabbixapi/users.rb', line 39

def get_id(data)
  result = get_full_data(data)
  userid = nil
  result.each { |usr| userid = usr['userid'].to_i if usr['name'] == data[:name] }
  userid
end

#update(data) ⇒ Object



46
47
48
49
# File 'lib/zabbixapi/users.rb', line 46

def update(data)
  result = @client.api_request(:method => "user.update", :params => data)
  result ? result['userids'][0].to_i : nil
end