Module: Icinga2::Hostgroups
- Included in:
- Client
- Defined in:
- lib/icinga2/hostgroups.rb
Overview
namespace for hostgroup handling
Instance Method Summary collapse
-
#add_hostgroup(params) ⇒ Hash
add a hostgroup.
-
#delete_hostgroup(params) ⇒ Hash
delete a hostgroup.
-
#exists_hostgroup?(host_group) ⇒ Bool
returns true if the hostgroup exists.
-
#hostgroups(params = {}) ⇒ Hash
returns all usersgroups.
Instance Method Details
#add_hostgroup(params) ⇒ Hash
add a hostgroup
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/icinga2/hostgroups.rb', line 20 def add_hostgroup( params ) raise ArgumentError.new('only Hash are allowed') unless( params.is_a?(Hash) ) raise ArgumentError.new('missing params') if( params.size.zero? ) host_group = params.dig(:host_group) display_name = params.dig(:display_name) raise ArgumentError.new('Missing host_group') if( host_group.nil? ) raise ArgumentError.new('Missing display_name') if( display_name.nil? ) Network.put( url: format('%s/objects/hostgroups/%s', @icinga_api_url_base, host_group), headers: @headers, options: @options, payload: { 'attrs' => { 'display_name' => display_name } } ) end |
#delete_hostgroup(params) ⇒ Hash
delete a hostgroup
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/icinga2/hostgroups.rb', line 49 def delete_hostgroup( params ) raise ArgumentError.new('only Hash are allowed') unless( params.is_a?(Hash) ) raise ArgumentError.new('missing params') if( params.size.zero? ) host_group = params.dig(:host_group) raise ArgumentError.new('Missing host_group') if( host_group.nil? ) Network.delete( url: format('%s/objects/hostgroups/%s?cascade=1', @icinga_api_url_base, host_group), headers: @headers, options: @options ) end |
#exists_hostgroup?(host_group) ⇒ Bool
returns true if the hostgroup exists
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/icinga2/hostgroups.rb', line 109 def exists_hostgroup?( host_group ) raise ArgumentError.new('only String are allowed') unless( host_group.is_a?(String) ) raise ArgumentError.new('Missing host_group') if( host_group.size.zero? ) result = hostgroups(host_group: host_group) result = JSON.parse( result ) if result.is_a?( String ) return true if !result.nil? && result.is_a?(Array) false end |
#hostgroups(params = {}) ⇒ Hash
returns all usersgroups
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/icinga2/hostgroups.rb', line 78 def hostgroups( params = {} ) host_group = params.dig(:host_group) url = if( host_group.nil? ) format( '%s/objects/hostgroups' , @icinga_api_url_base ) else format( '%s/objects/hostgroups/%s', @icinga_api_url_base, host_group ) end data = Network.api_data( url: url, headers: @headers, options: @options ) return data.dig('results') if( data.dig(:status).nil? ) nil end |