Puppet Class: dynatrace::role::host_agent

Inherits:
dynatrace
Defined in:
manifests/role/host_agent.pp

Overview

host_agent

Parameters:

  • ensure (Any) (defaults to: 'present')
  • role_name (Any) (defaults to: 'Dynatrace Host Agent')
  • host_installer_prefix_dir (Any) (defaults to: $dynatrace::host_agent_installer_prefix_dir)
  • host_installer_file_name (Any) (defaults to: $dynatrace::host_agent_installer_file_name)
  • host_installer_file_url (Any) (defaults to: $dynatrace::host_agent_installer_file_url)
  • host_agent_name (Any) (defaults to: $dynatrace::host_agent_name)
  • host_collector_name (Any) (defaults to: $dynatrace::host_agent_collector_name)
  • dynatrace_owner (Any) (defaults to: $dynatrace::dynatrace_owner)
  • dynatrace_group (Any) (defaults to: $dynatrace::dynatrace_group)


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
# File 'manifests/role/host_agent.pp', line 2

class dynatrace::role::host_agent (
  $ensure               = 'present',
  $role_name            = 'Dynatrace Host Agent',

  $host_installer_prefix_dir = $dynatrace::host_agent_installer_prefix_dir,

  #Host Agent is installed with server; agents_package should be executed first to install configuration files

  # host_installer_file_name parameter for future useage
  $host_installer_file_name  = $dynatrace::host_agent_installer_file_name,
  # host_installer_file_url parameter for future useage
  $host_installer_file_url   = $dynatrace::host_agent_installer_file_url,

  $host_agent_name      = $dynatrace::host_agent_name,
  $host_collector_name  = $dynatrace::host_agent_collector_name,

  $dynatrace_owner      = $dynatrace::dynatrace_owner,
  $dynatrace_group      = $dynatrace::dynatrace_group

) inherits dynatrace {

#  include dynatrace::role::agents_package

  validate_re($ensure, ['^present$', '^absent$'])
  validate_string($host_agent_name, $host_collector_name)

  case $::kernel {
    'Linux': {
      $service = $dynatrace::dynaTraceHostagent
      $ini_file = "${host_installer_prefix_dir}/dynatrace/agent/conf/dthostagent.ini"
      $init_scripts = [$service]
    }
    default: {}
  }

  file { $ini_file :
    ensure => file,
  }

  $service_ensure = $ensure ? {
    'present' => 'running',
    'absent'  => 'stopped',
    default   => 'running',
  }

  $installer_cache_dir = "${settings::vardir}/dynatrace"
  $installer_cache_dir_tree = dirtree($installer_cache_dir)

  include dynatrace::role::dynatrace_user

  file_line { "Inject the Host Agent name '${host_agent_name}' into '${ini_file}'":
    ensure => $ensure,
    path   => $ini_file,
    line   => "Name ${host_agent_name}",
    match  => '^Name .*$'
  }

  file_line { "Inject the collector name '${host_collector_name}' into '${ini_file}'":
    ensure => $ensure,
    path   => $ini_file,
    line   => "Server ${host_collector_name}",
    match  => '^Server .*$'
  }

  # ln -s /opt/dynatrace/init.d/dynaTraceHostagent /etc/init.d/dynaTraceHostagent
  exec {"Creates link to execute service  ln -s ${host_installer_prefix_dir}/dynatrace/init.d/dynaTraceHostagent /etc/init.d/${service}":
    command => "ln -s ${host_installer_prefix_dir}/dynatrace/init.d/dynaTraceHostagent /etc/init.d/${service}",
    path    => ['/usr/bin', '/usr/sbin', '/bin'],
    unless  => ["test -L /etc/init.d/${service}"],
  }
  -> service { "Enable and stop the ${role_name}'s service: '${service}'":    #hack to ensure start service (enable and stop service then start it)
    ensure => running,
    name   => $service,
    enable => true
  }
}