Class: Zabbix::User

Inherits:
API
  • Object
show all
Defined in:
lib/z2monitor/api/user.rb

Instance Attribute Summary collapse

Attributes inherited from API

#event, #server, #token, #trigger, #user, #verbose, #whoami

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ User

Returns a new instance of User.



6
7
8
9
# File 'lib/z2monitor/api/user.rb', line 6

def initialize(parent)
  @parent = parent
  @verbose = @parent.verbose
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/z2monitor/api/user.rb', line 5

def parent
  @parent
end

Instance Method Details

#call_api(message) ⇒ Object



10
11
12
# File 'lib/z2monitor/api/user.rb', line 10

def call_api(message)
  return @parent.call_api(message)
end

#get(options = {}) ⇒ Object

General user.get



14
15
16
17
# File 'lib/z2monitor/api/user.rb', line 14

def get( options = {} )
  request = { 'method' => 'user.get', 'params' => options }
  return call_api(request)
end

#get_fullnameObject

Get first and last name of currently logged in user



19
20
21
22
23
# File 'lib/z2monitor/api/user.rb', line 19

def get_fullname()
  request = { 'method' => 'user.get', 'output' => 'extend' }
  whoami = self.get({ 'output' => 'extend' })
  return whoami[0]["name"] + " " + whoami[0]["surname"]
end

#login(user, password) ⇒ Object

Perform a login procedure



25
26
27
28
29
30
31
# File 'lib/z2monitor/api/user.rb', line 25

def (user, password)
  request = { 'method' => 'user.login', 'params' => { 'user' => user, 'password' => password, }, 'id' => 1 }
  puts "[INFO] Logging in..." if @verbose
  result = call_api(request)
  puts "[INFO] Successfully logged in as #{user}! result => #{result}" if @verbose
  return result
end

#logoutObject

Perform a logout



33
34
35
36
37
38
# File 'lib/z2monitor/api/user.rb', line 33

def logout()
  request = { 'method' => 'user.logout' }
  puts "[INFO] Logging out..." if @verbose
  call_api(request)
  puts "[INFO] Successfully logged out." if @verbose
end