Module: Icinga2::Servicegroups
- Included in:
- Client
- Defined in:
- lib/icinga2/servicegroups.rb
Overview
namespace for servicegroup handling
Instance Method Summary collapse
-
#add_servicegroup(params = {}) ⇒ Hash
add a servicegroup.
-
#delete_servicegroup(params = {}) ⇒ Hash
delete a servicegroup.
-
#exists_servicegroup?(name) ⇒ Bool
returns true if the servicegroup exists.
-
#servicegroups(params = {}) ⇒ Hash
returns all servicegroups.
Instance Method Details
#add_servicegroup(params = {}) ⇒ Hash
add a servicegroup
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/icinga2/servicegroups.rb', line 20 def add_servicegroup( params = {} ) name = params.dig(:name) display_name = params.dig(:display_name) if( name.nil? ) return { status: 404, message: 'missing servicegroup name' } end payload = { 'attrs' => { 'display_name' => display_name } } Network.put( host: name, url: format( '%s/v1/objects/servicegroups/%s', @icinga_api_url_base, name ), headers: @headers, options: @options, payload: payload ) end |
#delete_servicegroup(params = {}) ⇒ Hash
delete a servicegroup
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/icinga2/servicegroups.rb', line 52 def delete_servicegroup( params = {} ) name = params.dig(:name) if( name.nil? ) return { status: 404, message: 'missing servicegroup name' } end Network.delete( host: name, url: format( '%s/v1/objects/servicegroups/%s?cascade=1', @icinga_api_url_base, name ), headers: @headers, options: @options ) end |
#exists_servicegroup?(name) ⇒ Bool
returns true if the servicegroup exists
103 104 105 106 107 108 109 110 111 |
# File 'lib/icinga2/servicegroups.rb', line 103 def exists_servicegroup?( name ) result = servicegroups( name: name ) result = JSON.parse( result ) if result.is_a?( String ) status = result.dig(:status) return true if !status.nil? && status == 200 false end |
#servicegroups(params = {}) ⇒ Hash
returns all servicegroups
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/icinga2/servicegroups.rb', line 83 def servicegroups( params = {} ) name = params.dig(:name) Network.get( host: name, url: format( '%s/v1/objects/servicegroups/%s', @icinga_api_url_base, name ), headers: @headers, options: @options ) end |