Module: Icinga2::Usergroups
- Included in:
- Client
- Defined in:
- lib/icinga2/usergroups.rb
Overview
namespace for usergroup handling
Instance Method Summary collapse
-
#add_usergroup(params) ⇒ Hash
add a usergroup.
-
#delete_usergroup(params) ⇒ Hash
delete a usergroup.
-
#exists_usergroup?(user_group) ⇒ Bool
returns true if the usergroup exists.
-
#usergroups(params = {}) ⇒ Hash
returns all usersgroups.
Instance Method Details
#add_usergroup(params) ⇒ Hash
add a usergroup
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/icinga2/usergroups.rb', line 20 def add_usergroup( params ) raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) ) raise ArgumentError.new('missing \'params\'') if( params.size.zero? ) user_group = params.dig(:user_group) display_name = params.dig(:display_name) raise ArgumentError.new('Missing user_group') if( user_group.nil? ) payload = { 'attrs' => { 'display_name' => display_name } } put( url: format( '%s/objects/usergroups/%s', @icinga_api_url_base, user_group ), headers: @headers, options: @options, payload: payload ) end |
#delete_usergroup(params) ⇒ Hash
delete a usergroup
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/icinga2/usergroups.rb', line 54 def delete_usergroup( params ) raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) ) raise ArgumentError.new('missing \'params\'') if( params.size.zero? ) user_group = params.dig(:user_group) raise ArgumentError.new('Missing user_group') if( user_group.nil? ) delete( url: format( '%s/objects/usergroups/%s?cascade=1', @icinga_api_url_base, user_group ), headers: @headers, options: @options ) end |
#exists_usergroup?(user_group) ⇒ Bool
returns true if the usergroup exists
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/icinga2/usergroups.rb', line 110 def exists_usergroup?( user_group ) raise ArgumentError.new(format('wrong type. \'user_group\' must be an String, given \'%s\'', user_group.class.to_s)) unless( user_group.is_a?(String) ) raise ArgumentError.new('Missing \'user_group\'') if( user_group.size.zero? ) result = usergroups( user_group: user_group ) result = JSON.parse( result ) if result.is_a?( String ) result = result.first if( result.is_a?(Array) ) return false if( result.is_a?(Hash) && result.dig('code') == 404 ) true end |
#usergroups(params = {}) ⇒ Hash
returns all usersgroups
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/icinga2/usergroups.rb', line 83 def usergroups( params = {} ) user_group = params.dig(:user_group) url = if( user_group.nil? ) format( '%s/objects/usergroups' , @icinga_api_url_base ) else format( '%s/objects/usergroups/%s', @icinga_api_url_base, user_group ) end api_data( url: url, headers: @headers, options: @options ) end |