Module: Icinga2::Notifications
- Included in:
- Client
- Defined in:
- lib/icinga2/notifications.rb
Instance Method Summary collapse
- #disableHostgroupNotification(group) ⇒ Object
- #disableHostNotification(host) ⇒ Object
- #disableServiceNotification(host) ⇒ Object
- #enableHostgroupNotification(group) ⇒ Object
- #enableHostNotification(host) ⇒ Object
- #enableServiceNotification(params = {}) ⇒ Object
- #hostgroupNotification(params = {}) ⇒ Object
-
#hostNotification(params = {}) ⇒ Object
PRIVATE SECTION.
- #listNotifications(params = {}) ⇒ Object
- #serviceNotification(params = {}) ⇒ Object
Instance Method Details
#disableHostgroupNotification(group) ⇒ Object
48 49 50 51 |
# File 'lib/icinga2/notifications.rb', line 48 def disableHostgroupNotification( group ) return self.hostgroupNotification( { :host_group => group, :enable_notifications => false } ) end |
#disableHostNotification(host) ⇒ Object
13 14 15 16 |
# File 'lib/icinga2/notifications.rb', line 13 def disableHostNotification( host ) return self.hostNotification( { :name => host, :enable_notifications => false } ) end |
#disableServiceNotification(host) ⇒ Object
36 37 38 39 |
# File 'lib/icinga2/notifications.rb', line 36 def disableServiceNotification( host ) return self.serviceNotification( { :name => host, :enable_notifications => false } ) end |
#enableHostgroupNotification(group) ⇒ Object
42 43 44 45 |
# File 'lib/icinga2/notifications.rb', line 42 def enableHostgroupNotification( group ) return self.hostgroupNotification( { :host_group => group, :enable_notifications => true } ) end |
#enableHostNotification(host) ⇒ Object
7 8 9 10 |
# File 'lib/icinga2/notifications.rb', line 7 def enableHostNotification( host ) return hostNotification( { :name => host, :enable_notifications => true } ) end |
#enableServiceNotification(params = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/icinga2/notifications.rb', line 19 def enableServiceNotification( params = {} ) host = params.get(:host) service = params.get(:service) if( host == nil ) return { :status => 404, :message => 'missing host name' } end return self.serviceNotification( { :name => host, :service => service, :enable_notifications => true } ) end |
#hostgroupNotification(params = {}) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/icinga2/notifications.rb', line 98 def hostgroupNotification( params = {} ) group = params.dig(:host_group) notifications = params.dig(:enable_notifications) || false payload = { "filter" => sprintf( '"%s" in host.groups', group ), "attrs" => { "enable_notifications" => notifications } } result = Network.post( { :host => name, :url => sprintf( '%s/v1/objects/services', @icingaApiUrlBase ), :headers => @headers, :options => @options, :payload => payload } ) logger.debug( result.class.to_s ) return JSON.pretty_generate( result ) end |
#hostNotification(params = {}) ⇒ Object
PRIVATE SECTION
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/icinga2/notifications.rb', line 72 def hostNotification( params = {} ) name = params.dig(:name) notifications = params.dig(:enable_notifications) || false payload = { "attrs" => { "enable_notifications" => notifications } } result = Network.post( { :host => name, :url => sprintf( '%s/v1/objects/hosts/%s', @icingaApiUrlBase, name ), :headers => @headers, :options => @options, :payload => payload } ) logger.debug( result.class.to_s ) return JSON.pretty_generate( result ) end |
#listNotifications(params = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/icinga2/notifications.rb', line 54 def listNotifications( params = {} ) name = params.dig(:name) result = Network.get( { :host => name, :url => sprintf( '%s/v1/objects/notifications/%s', @icingaApiUrlBase, name ), :headers => @headers, :options => @options } ) return JSON.pretty_generate( result ) end |
#serviceNotification(params = {}) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/icinga2/notifications.rb', line 125 def serviceNotification( params = {} ) name = params.dig(:name) service = params.dig(:service) notifications = params.dig(:enable_notifications) || false payload = { "filter" => sprintf( 'host.name=="%s"', name ), "attrs" => { "enable_notifications" => notifications } } logger.debug( payload ) logger.debug( sprintf( '%s/v1/objects/services', @icingaApiUrlBase ) ) result = Network.post( { :host => name, :url => sprintf( '%s/v1/objects/services', @icingaApiUrlBase ), :headers => @headers, :options => @options, :payload => payload } ) logger.debug( result.class.to_s ) return JSON.pretty_generate( result ) end |