Puppet Class: wh31e

Defined in:
manifests/init.pp

Summary

Configure wh31e metrics

Overview

Parameters:

  • sensor_names (Hash[Integer, String])

    sets the mapping between sensor ID and human name

  • sample_rate (String) (defaults to: '250k')

    sets the polling speed for new data

  • version (String) (defaults to: 'v0.1.0')

    sets the version of wh31e to install

  • binfile (String) (defaults to: '/usr/local/bin/wh31e')

    sets the install path for the wh31e binary

  • prometheus_server_ip (String) (defaults to: '0.0.0.0/0')

    sets the IP range to allow for prometheus connections

  • port (Integer) (defaults to: 9131)

    to serve the wh31e metrics on



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
79
80
81
82
83
84
# File 'manifests/init.pp', line 9

class wh31e (
  Hash[Integer, String] $sensor_names,
  String $sample_rate = '250k',
  String $version = 'v0.1.0',
  String $binfile = '/usr/local/bin/wh31e',
  String $prometheus_server_ip = '0.0.0.0/0',
  Integer $port = 9131,
) {
  class { 'sdr': }

  -> file { '/usr/local/etc/rtl_433/rtl_433.conf':
    ensure  => file,
    content => template('wh31e/rtl_433.conf.erb'),
    notify  => Service['rtl_433'],
  }

  -> file { '/var/lib/wh31e':
    ensure => directory,
  }

  -> file { '/etc/systemd/system/rtl_433.service':
    ensure => file,
    source => 'puppet:///modules/wh31e/rtl_433.service',
  }

  ~> service { 'rtl_433':
    ensure => running,
    enable => true,
  }

  $kernel = downcase($facts['kernel'])
  $arch = $facts['os']['architecture'] ? {
    'x86_64'  => 'amd64',
    'arm64'   => 'arm64',
    'aarch64' => 'arm64',
    'arm'     => 'arm',
    default   => 'error',
  }

  $filename = "wh31e_${kernel}_${arch}"
  $url = "https://github.com/akerl/wh31e/releases/download/${version}/${filename}"

  file { $binfile:
    ensure => file,
    source => $url,
    mode   => '0755',
    owner  => 'root',
    group  => 'root',
    notify => Service['wh31e'],
  }

  -> file { '/usr/local/etc/wh31e.conf':
    ensure  => file,
    mode    => '0644',
    content => template('wh31e/wh31e.conf.erb'),
    notify  => Service['wh31e'],
  }

  -> file { '/etc/systemd/system/wh31e.service':
    ensure => file,
    source => 'puppet:///modules/wh31e/wh31e.service',
  }

  ~> service { 'wh31e':
    ensure => running,
    enable => true,
    notify => Service['rtl_433'],
  }

  firewall { '100 allow prometheus wh31e metrics':
    source => $prometheus_server_ip,
    dport  => $port,
    proto  => 'tcp',
    action => 'accept',
  }
}