Class: IcingaResult::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/icinga_result/service.rb

Overview

Represents an Icinga2 service object

Constant Summary collapse

DEFAULT_OPTONS =
{ interval: 3600, description: '', groups: [] }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = DEFAULT_OPTONS) ⇒ Service

Returns a new instance of Service.



8
9
10
11
12
13
# File 'lib/icinga_result/service.rb', line 8

def initialize(name, options = DEFAULT_OPTONS)
  @name = name
  @interval = options[:interval] || DEFAULT_OPTONS[:interval]
  @description = options[:description] || DEFAULT_OPTONS[:description]
  @groups = options[:groups] || DEFAULT_OPTONS[:groups]
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/icinga_result/service.rb', line 4

def description
  @description
end

#groupsObject

Returns the value of attribute groups.



4
5
6
# File 'lib/icinga_result/service.rb', line 4

def groups
  @groups
end

#intervalObject

Returns the value of attribute interval.



4
5
6
# File 'lib/icinga_result/service.rb', line 4

def interval
  @interval
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/icinga_result/service.rb', line 4

def name
  @name
end

Instance Method Details

#dataObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/icinga_result/service.rb', line 19

def data
  {
    'templates' => ['generic-service'],
    'attrs' => {
      'check_command' => 'passive',
      'enable_active_checks' => true,
      'check_interval' => timeout,
      'vars.description' => @description,
      'groups' => @groups
    }
  }
end

#timeoutObject



15
16
17
# File 'lib/icinga_result/service.rb', line 15

def timeout
  3 * @interval + 120
end