Module: Icinga2::Servicegroups
- Included in:
- Client
- Defined in:
- lib/icinga2/servicegroups.rb
Instance Method Summary collapse
- #addServicegroup(params = {}) ⇒ Object
- #deleteServicegroup(params = {}) ⇒ Object
- #existsServicegroup?(name) ⇒ Boolean
- #listServicegroups(params = {}) ⇒ Object
Instance Method Details
#addServicegroup(params = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/icinga2/servicegroups.rb', line 7 def addServicegroup( params = {} ) name = params.dig(:name) displayName = params.dig(:display_name) if( name == nil ) return { :status => 404, :message => 'missing servicegroup name' } end payload = { "attrs" => { "display_name" => displayName } } result = Network.put( { :host => name, :url => sprintf( '%s/v1/objects/servicegroups/%s', @icingaApiUrlBase, name ), :headers => @headers, :options => @options, :payload => payload } ) return JSON.pretty_generate( result ) end |
#deleteServicegroup(params = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/icinga2/servicegroups.rb', line 39 def deleteServicegroup( params = {} ) name = params.dig(:name) if( name == nil ) return { :status => 404, :message => 'missing servicegroup name' } end result = Network.delete( { :host => name, :url => sprintf( '%s/v1/objects/servicegroups/%s?cascade=1', @icingaApiUrlBase, name ), :headers => @headers, :options => @options } ) return JSON.pretty_generate( result ) end |
#existsServicegroup?(name) ⇒ Boolean
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/icinga2/servicegroups.rb', line 79 def existsServicegroup?( name ) result = self.listServicegroups( { :name => name } ) if( result.is_a?( String ) ) result = JSON.parse( result ) end status = result.dig('status') if( status != nil && status == 200 ) return true end return false end |
#listServicegroups(params = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/icinga2/servicegroups.rb', line 63 def listServicegroups( params = {} ) name = params.dig(:name) result = Network.get( { :host => name, :url => sprintf( '%s/v1/objects/servicegroups/%s', @icingaApiUrlBase, name ), :headers => @headers, :options => @options } ) return JSON.pretty_generate( result ) end |