Module: Icinga2::Servicegroups

Included in:
Client
Defined in:
lib/icinga2/servicegroups.rb

Overview

namespace for servicegroup handling

Instance Method Summary collapse

Instance Method Details

#add_servicegroup(params = {}) ⇒ Hash

add a servicegroup

Examples:

@icinga.add_servicegroup(name: 'foo', display_name: 'FOO')

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :name (String)

    servicegroup to create

  • :display_name (String)

    the displayed name

Returns:

  • (Hash)

    result



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

Examples:

@icinga.delete_servicegroup(name: 'foo')

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :name (String)

    servicegroup to delete

Returns:

  • (Hash)

    result



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

Examples:

@icinga.exists_servicegroup?('disk')

Parameters:

  • name (String)

    the name of the servicegroups

Returns:

  • (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

Examples:

to get all users

@icinga.servicegroups

to get one user

@icinga.servicegroups(name: 'disk')

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :name (String) — default: ''

    optional for a single servicegroup

Returns:

  • (Hash)

    returns a hash with 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