Class: Zabbix::User
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
Attributes inherited from API
#event, #server, #token, #trigger, #user, #verbose, #whoami
Instance Method Summary collapse
- #call_api(message) ⇒ Object
-
#get(options = {}) ⇒ Object
General user.get.
-
#get_fullname ⇒ Object
Get first and last name of currently logged in user.
-
#initialize(parent) ⇒ User
constructor
A new instance of User.
-
#login(user, password) ⇒ Object
Perform a login procedure.
-
#logout ⇒ Object
Perform a logout.
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
#parent ⇒ Object
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() return @parent.call_api() end |
#get(options = {}) ⇒ Object
General user.get
14 15 16 17 |
# File 'lib/z2monitor/api/user.rb', line 14 def get( = {} ) request = { 'method' => 'user.get', 'params' => } return call_api(request) end |
#get_fullname ⇒ Object
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 login(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 |
#logout ⇒ Object
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 |