Defined Type: icinga2::object

Defined in:
manifests/object.pp

Summary

Define resource to used by this module only.

Overview

Parameters:

  • ensure (Enum['present', 'absent']) (defaults to: present)

    Set to present enables the object, absent disabled it.

  • object_name (String[1]) (defaults to: $title)

    Set the icinga2 name of the object.

  • template (Boolean) (defaults to: false)

    Set to true will define a template otherwise an object. Ignored if apply is set.

  • apply (Variant[Boolean, Pattern[/^.+\s+(=>\s+.+\s+)?in\s+.+$/]]) (defaults to: false)

    Dispose an apply instead an object if set to ‘true’. Value is taken as statement, i.e. ‘vhost => config in host.vars.vhosts’.

  • prefix (Variant[Boolean, String[1]]) (defaults to: false)

    Set object_name as prefix in front of ‘apply for’. Only effects if apply is a string.

  • apply_target (Optional[Enum['Host', 'Service']]) (defaults to: undef)

    Optional for an object type on which to target the apply rule. Valid values are ‘Host` and `Service`.

  • import (Array[String[1]]) (defaults to: [])

    A sorted list of templates to import in this object.

  • assign (Array[String[1]]) (defaults to: [])

    Array of assign rules.

  • ignore (Array[String[1]]) (defaults to: [])

    Array of ignore rules.

  • attrs (Hash[String[1], Any]) (defaults to: {})

    Hash for the attributes of this object. Keys are the attributes and values are there values.

  • object_type (String[1])

    Icinga 2 object type for this object.

  • target (Stdlib::Absolutepath)

    Destination config file to store in this object. File will be declared the first time.

  • order (Variant[String[1], Integer[0]])

    String or integer to set the position in the target file, sorted alpha numeric.

  • attrs_list (Array[String[1]]) (defaults to: [])

    Array of all possible attributes for this object type.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'manifests/object.pp', line 52

define icinga2::object (
  String[1]                                                   $object_type,
  Stdlib::Absolutepath                                        $target,
  Variant[String[1], Integer[0]]                              $order,
  Enum['present', 'absent']                                   $ensure       = present,
  String[1]                                                   $object_name  = $title,
  Boolean                                                     $template     = false,
  Variant[Boolean, Pattern[/^.+\s+(=>\s+.+\s+)?in\s+.+$/]]    $apply        = false,
  Array[String[1]]                                            $attrs_list   = [],
  Optional[Enum['Host', 'Service']]                           $apply_target = undef,
  Variant[Boolean, String[1]]                                 $prefix       = false,
  Array[String[1]]                                            $import       = [],
  Array[String[1]]                                            $assign       = [],
  Array[String[1]]                                            $ignore       = [],
  Hash[String[1], Any]                                        $attrs        = {},
) {
  assert_private()

  case $facts['os']['family'] {
    'windows': {
    } # windows
    default: {
      Concat {
        owner   => $icinga2::globals::user,
        group   => $icinga2::globals::group,
        seltype => 'icinga2_etc_t',
        mode    => '0640',
      }
    } # default
  }

  if $object_type == $apply_target {
    fail('The object type must be different from the apply target')
  }

  $_object = epp('icinga2/object.conf.epp',
    { 'attrs'        => $attrs,
      'attrs_list'   => $attrs_list,
      'apply'        => $apply,
      'apply_target' => $apply_target,
      'prefix'       => $prefix,
      'object_type'  => $object_type,
      'object_name'  => $object_name,
      'template'     => $template,
      'import'       => $import,
      'assign'       => $assign,
      'ignore'       => $ignore,
    }
  )

  if !defined(Concat[$target]) {
    concat { $target:
      ensure => present,
      tag    => 'icinga2::config::file',
      warn   => true,
    }
  }

  if $ensure != 'absent' {
    concat::fragment { $title:
      target  => $target,
      content => icinga::newline($_object),
      order   => $order,
    }
  }
}