Module: Icinga2::Hostgroups
- Included in:
- Client
- Defined in:
- lib/icinga2/hostgroups.rb
Instance Method Summary collapse
- #addHostgroup(params = {}) ⇒ Object
- #deleteHostgroup(params = {}) ⇒ Object
- #existsHostgroup?(name) ⇒ Boolean
- #listHostgroups(params = {}) ⇒ Object
Instance Method Details
#addHostgroup(params = {}) ⇒ Object
6 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 |
# File 'lib/icinga2/hostgroups.rb', line 6 def addHostgroup( params = {} ) name = params.dig(:name) displayName = params.dig(:display_name) if( name == nil ) return { :status => 404, :message => 'no name for the hostgroup' } end payload = { "attrs" => { "display_name" => displayName } } result = Network.put( { :url => sprintf( '%s/v1/objects/hostgroups/%s', @icingaApiUrlBase, name ), :headers => @headers, :options => , :payload => payload } ) return JSON.pretty_generate( result ) end |
#deleteHostgroup(params = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/icinga2/hostgroups.rb', line 37 def deleteHostgroup( params = {} ) name = params.dig(:name) if( name == nil ) return { :status => 404, :message => 'no name for the hostgroup' } end result = Network.delete( { :host => name, :url => sprintf( '%s/v1/objects/hostgroups/%s?cascade=1', @icingaApiUrlBase, name ), :headers => @headers, :options => } ) return JSON.pretty_generate( result ) end |
#existsHostgroup?(name) ⇒ Boolean
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/icinga2/hostgroups.rb', line 77 def existsHostgroup?( name ) result = self.listHostgroups( { :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 |
#listHostgroups(params = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/icinga2/hostgroups.rb', line 61 def listHostgroups( params = {} ) name = params.dig(:name) result = Network.get( { :host => name, :url => sprintf( '%s/v1/objects/hostgroups/%s', @icingaApiUrlBase, name ), :headers => @headers, :options => } ) return JSON.pretty_generate( result ) end |