Skip to content

Commit

Permalink
Fix for Zabbix 4.0: remove removed methods of Users - add_medias, upd…
Browse files Browse the repository at this point in the history
…ate_medias
  • Loading branch information
Greg Dubicki committed Dec 25, 2018
1 parent 7492db6 commit 42a0603
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 72 deletions.
22 changes: 3 additions & 19 deletions examples/MediaTypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,9 @@ zbx.mediatypes.create_or_update(
:smtp_email => "[email protected]"
)

zbx.users.add_medias(
:userids => [zbx.users.get_id(:alias => "user")],
:media => [
{
:mediatypeid => zbx.mediatypes.get_id(:description => "mediatype"),
:sendto => "test@test",
:active => 0,
:period => "1-7,00:00-24:00", # 1-7 days and 00:00-24:00 hours
:severity => "56"
}
]
)
```

## Update Media ###
```ruby
zbx.users.update_medias(
:userids => [zbx.users.get_id(:alias => "user")],
:media => [
zbx.users.update(
:userid => zbx.users.get_id(:alias => "user"),
:user_medias => [
{
:mediatypeid => zbx.mediatypes.get_id(:description => "mediatype"),
:sendto => "test@test",
Expand Down
33 changes: 0 additions & 33 deletions lib/zabbixapi/classes/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,5 @@ def indentify
'alias'
end

# Add media to users using Zabbix API
#
# @param data [Hash] Needs to include userids and media to mass add media to users
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
# @return [Integer] Zabbix object id (media)
def add_medias(data)
result = @client.api_request(
:method => 'user.addMedia',
:params => {
:users => data[:userids].map { |t| {:userid => t} },
:medias => data[:media],
}
)
result ? result['mediaids'][0].to_i : nil
end

# Update media for users using Zabbix API
#
# @param data [Hash] Needs to include userids and media to mass update media for users
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
# @return [Integer] Zabbix object id (user)
def update_medias(data)
result = @client.api_request(
:method => 'user.updateMedia',
:params => {
:users => data[:userids].map { |t| {:userid => t} },
:medias => data[:media],
}
)
result ? result['userids'][0].to_i : nil
end
end
end
28 changes: 8 additions & 20 deletions spec/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,16 @@ def media
end
end

describe 'add_medias' do
it 'should return integer media id' do
describe 'update by adding media' do
it 'should return id' do
expect(
zbx.users.add_medias(
:userids => [@userid],
:media => [media]
zbx.users.update(
:userid => @userid,
:user_medias => [
media,
]
)
).to be_kind_of(Integer)
end
end

describe 'update_medias' do
it 'should return the user id' do
# Call twice to ensure update_medias first successfully creates the media, then updates it
2.times do
returned_userid = zbx.users.update_medias(
:userids => [@userid],
:media => [media]
)

expect(returned_userid).to eq @userid
end
).to eq @userid
end
end

Expand Down

0 comments on commit 42a0603

Please sign in to comment.