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('only Hash are allowed') 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 } } Network.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('only Hash are allowed') 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? ) Network.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
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/icinga2/usergroups.rb', line 114 def exists_usergroup?( user_group ) raise ArgumentError.new('only String are allowed') 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 ) return true if !result.nil? && result.is_a?(Array) false end |
#usergroups(params = {}) ⇒ Hash
returns all usersgroups
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# 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 data = Network.api_data( url: url, headers: @headers, options: @options ) return data.dig('results') if( data.dig(:status).nil? ) nil end |