Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logout method #82

Merged
merged 1 commit into from
Dec 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ zbx = ZabbixApi.connect(
)
```

## Logout
```ruby
require "zabbixapi"

zbx = ZabbixApi.connect(
:url => 'http://localhost/zabbix/api_jsonrpc.php',
:user => 'Admin',
:password => 'zabbix'
)

# Do stuff

zbx.logout
```

## Create Host
```ruby
zbx.hosts.create(
Expand Down
6 changes: 6 additions & 0 deletions lib/zabbixapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def query(data)
@client.api_request(:method => data[:method], :params => data[:params])
end

# Invalidate current authentication token
# @return [Boolean]
def logout
@client.logout
end

# Initializes a new ZabbixApi object
#
# @param options [Hash]
Expand Down
10 changes: 10 additions & 0 deletions lib/zabbixapi/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ def auth
)
end

# Log out from the Zabbix Server
#
# @return [Boolean]
def logout
api_request(
:method => 'user.logout',
:params => []
)
end

# Initializes a new Client object
#
# @param options [Hash]
Expand Down