Module: Icinga2::Notifications

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

Overview

namespace for servicegroup handling

Instance Method Summary collapse

Instance Method Details

#disable_host_notification(host) ⇒ Hash

disable host notifications

Examples:

@icinga.disable_host_notification('icinga')

Parameters:

  • host (String)

Returns:

  • (Hash)


32
33
34
35
# File 'lib/icinga2/notifications.rb', line 32

def disable_host_notification( host )

  host_notification( name: host, enable_notifications: false )
end

#disable_hostgroup_notification(params = {}) ⇒ Hash

disable hostgroup notifications

Examples:

@icinga.disable_hostgroup_notification(host: 'icinga2', host_group: 'linux-servers')

Parameters:

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

Options Hash (params):

  • host (String)
  • host_group (String)

Returns:

  • (Hash)


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/icinga2/notifications.rb', line 124

def disable_hostgroup_notification( params = {} )

  host = params.dig(:host)
  host_group = params.dig(:host_group)

  if( host.nil? )
    return {
      status: 404,
      message: 'missing host name'
    }
  end

  if( host_group.nil? )
    return {
      status: 404,
      message: 'missing host_group name'
    }
  end

  hostgroup_notification( host: host, host_group: host_group, enable_notifications: false )
end

#disable_service_notification(host) ⇒ Hash

disable service notifications

Examples:

@icinga.disable_service_notification('icinga')

Parameters:

  • host (String)

Returns:

  • (Hash)


68
69
70
71
72
73
74
75
76
77
78
# File 'lib/icinga2/notifications.rb', line 68

def disable_service_notification( host )

  if( host.nil? )
    return {
      status: 404,
      message: 'missing host name'
    }
  end

  service_notification( name: host, enable_notifications: false )
end

#enable_host_notification(host) ⇒ Hash

enable host notifications

Examples:

@icinga.enable_host_notification('icinga')

Parameters:

  • host (String)

Returns:

  • (Hash)


18
19
20
21
# File 'lib/icinga2/notifications.rb', line 18

def enable_host_notification( host )

  host_notification( name: host, enable_notifications: true )
end

#enable_hostgroup_notification(params = {}) ⇒ Hash

enable hostgroup notifications

Examples:

@icinga.enable_hostgroup_notification(host: 'icinga2', host_group: 'linux-servers')

Parameters:

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

Options Hash (params):

  • host (String)
  • host_group (String)

Returns:

  • (Hash)


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/icinga2/notifications.rb', line 91

def enable_hostgroup_notification( params = {} )

  host = params.dig(:host)
  host_group = params.dig(:host_group)

  if( host.nil? )
    return {
      status: 404,
      message: 'missing host name'
    }
  end

  if( host_group.nil? )
    return {
      status: 404,
      message: 'missing host_group name'
    }
  end

  hostgroup_notification( host: host, host_group: host_group, enable_notifications: true )
end

#enable_service_notification(host) ⇒ Hash

enable service notifications

Examples:

@icinga.enable_service_notification('icinga')

Parameters:

  • host (String)

Returns:

  • (Hash)


46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/icinga2/notifications.rb', line 46

def enable_service_notification( host )

  if( host.nil? )

    return {
      status: 404,
      message: 'missing host name'
    }
  end

  service_notification( name: host, enable_notifications: true )
end

#notifications(params = {}) ⇒ Hash

return all notifications

Parameters:

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

Options Hash (params):

  • name (String)

Returns:

  • (Hash)


153
154
155
156
157
158
159
160
161
162
# File 'lib/icinga2/notifications.rb', line 153

def notifications( params = {} )

  name = params.dig(:name)

  Network.get(         host: name,
    url: format( '%s/v1/objects/notifications/%s', @icinga_api_url_base, name ),
    headers: @headers,
    options: @options )

end