Puppet Class: smart

Defined in:
modules/smart/manifests/init.pp

Overview

Parameters:

  • ensure (Any) (defaults to: present)


1
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
# File 'modules/smart/manifests/init.pp', line 1

class smart (
    $ensure = present,
) {
    require_package(['python3-prometheus-client', 'bsdutils'])

    $outfile = '/var/lib/prometheus/node.d/device_smart.prom'

    if $facts['is_virtual'] == true {
        fail('smart module is not supported on virtual hosts')
    }

    package { 'smartmontools':
        ensure => $ensure,
    }

    # smartd doesn't support enumerating devices on cciss/hpsa controllers and
    # fails to start. Since alerting is done via metrics from smart-data-dump,
    # mask smartd when needed. See also T246997.
    if os_version('debian >= buster') and 'hpsa' in $facts['raid'] {
        systemd::mask { 'smartd.service': }
    } else {
        base::service_auto_restart { 'smartd': }
    }

    # Make sure we send smart alerts from smartd via syslog and not email.
    file { '/etc/smartmontools/run.d/10mail':
        ensure  => absent,
        require => Package['smartmontools'],
    }

    file { '/etc/smartmontools/run.d/20logger':
        ensure  => $ensure,
        owner   => 'root',
        group   => 'root',
        mode    => '0544',
        source  => "puppet:///modules/${module_name}/20logger",
        require => Package['smartmontools'],
    }

    file { '/usr/local/sbin/smart-data-dump':
        ensure => $ensure,
        owner  => 'root',
        group  => 'root',
        mode   => '0544',
        source => "puppet:///modules/${module_name}/smart_data_dump.py",
    }

    cron { 'export_smart_data_dump':
        ensure  => $ensure,
        command => "/usr/local/sbin/smart-data-dump --syslog --outfile ${outfile}",
        user    => 'root',
        hour    => '*',
        minute  => fqdn_rand(60, 'export_smart_data_dump'),
        require => File['/usr/local/sbin/smart-data-dump'],
    }

    # Cleanup outfile only on ensure=absent, since on ensure=present the file gets created by cron.
    if $ensure == absent {
      file { $outfile:
          ensure => $ensure,
      }
    }
}