Puppet Class: smart

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

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • ensure (Any) (defaults to: present)


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

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

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

    if $facts['is_virtual'] {
        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 'hpsa' in $facts['raid_mgmt_tools'] {
        systemd::mask { 'smartd.service': }
    } else {
        profile::auto_restarts::service { 'smartd': }
    }

    # Make systemd be a little more patient about waiting for smartd to
    # start up - on some nodes with a lot of disks it takes ~2 minutes,
    # more than the default systemd timeout of 90s.
    systemd::override { 'systemd-wait-longer-for-smartd':
        ensure  => $ensure,
        unit    => 'smartmontools',
        content => "[Service]\nTimeoutSec=300\n",
    }

    # 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",
    }

    $minute = fqdn_rand(60, 'export_smart_data_dump')
    systemd::timer::job { 'export_smart_data_dump':
        ensure      => $ensure,
        user        => 'root',
        description => 'Collect SMART information from all physical disks and report as Prometheus metrics',
        command     => "/usr/local/sbin/smart-data-dump --syslog --outfile ${outfile}",
        interval    => {
            'start'    => 'OnCalendar',
            'interval' => "*-*-* *:${minute}:00",
        },
        require     => File['/usr/local/sbin/smart-data-dump'],
    }

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