File tree Expand file tree Collapse file tree 8 files changed +167
-0
lines changed Expand file tree Collapse file tree 8 files changed +167
-0
lines changed Original file line number Diff line number Diff line change 1+ # Inventor
Original file line number Diff line number Diff line change 1+ # == Class inventor::config
2+ #
3+ # creates config files
4+ #
5+ class inventor::config {
6+
7+ $key = $inventor::key
8+ $url = $inventor::url
9+ $cron = $inventor::cron
10+ $config_manage = $inventor::config_manage
11+ $info = $inventor::info
12+
13+ if $config_manage {
14+
15+ file { '/opt/inventor' :
16+ ensure => ' directory' ,
17+ owner => ' root' ,
18+ group => ' root' ,
19+ mode => ' 0750' ,
20+ }->
21+
22+ file { '/opt/inventor/run.sh' :
23+ ensure => file ,
24+ owner => ' root' ,
25+ group => ' root' ,
26+ mode => ' 0750' ,
27+ content => epp(" ${module_name} /opt/inventor/run.sh.epp" , {
28+ url => $url ,
29+ key => $key ,
30+ info => $info ,
31+ }),
32+ }
33+
34+ file { '/etc/cron.d/inventor' :
35+ ensure => file ,
36+ owner => ' root' ,
37+ group => ' root' ,
38+ mode => ' 0640' ,
39+ content => epp(" ${module_name} /etc/cron.d/inventor.epp" , {
40+ cron => $cron ,
41+ }),
42+ }
43+
44+ $info .each | String $exporter , Hash $data | {
45+ file { "/opt/inventor/${exporter}.json" :
46+ ensure => file ,
47+ owner => ' root' ,
48+ group => ' root' ,
49+ mode => ' 0640' ,
50+ content => epp(" ${module_name} /opt/inventor/data.json.epp" , {
51+ data => $data ,
52+ }),
53+ }
54+ }
55+
56+ } else {
57+
58+ $files = [
59+ ' /opt/inventor/*' ,
60+ ' /etc/cron.d/inventor' ,
61+ ]
62+ file { $files:
63+ ensure => ' absent' ,
64+ }
65+
66+ }
67+ }
Original file line number Diff line number Diff line change 1+ # == Class: inventor
2+ #
3+ # This module installs and configures inventor
4+ #
5+ # === Parameters
6+
7+ class inventor (
8+ String $key = $inventor::params::key,
9+ String $url = $inventor::params::url,
10+ String $cron = $inventor::params::cron,
11+ Boolean $manage_package = $inventor::params::manage_package,
12+ Array[String] $package_name = $inventor::params::package_name,
13+ Boolean $config_manage = $inventor::params::config_manage,
14+ Hash $info = $inventor::params::info,
15+
16+ ) inherits inventor::params {
17+
18+ contain inventor::install
19+ contain inventor::config
20+
21+ Class[' inventor::install' ] ->
22+ Class[' inventor::config' ]
23+ }
Original file line number Diff line number Diff line change 1+ # == Class inventor::install
2+ #
3+ # This class is called from inventor for install.
4+ #
5+ class inventor::install {
6+
7+ $manage_package = $inventor::manage_package
8+ $package_ensure = $inventor::package_ensure
9+ $package_name = $inventor::package_name
10+
11+ # only do repo management when on a Debian-like system
12+ if $manage_package {
13+
14+ include apt
15+
16+ package { $package_name:
17+ ensure => $package_ensure ,
18+ }
19+
20+ }
21+
22+ }
Original file line number Diff line number Diff line change 1+ # == Class inventor::params
2+ #
3+ # default parameters definition
4+ #
5+ class inventor::params {
6+
7+ $key = ' secret'
8+ $url = ' NOT-CONFIGURED'
9+ $cron = ' 0 */3 * * *'
10+ $package_ensure = ' installed'
11+ $config_manage = true
12+ $manage_package = false
13+ $package_name = [ ' curl' ]
14+ $use_defaults = true
15+ # https://puppet.com/docs/puppet/7/core_facts.html#os
16+ $info = {}
17+
18+ }
Original file line number Diff line number Diff line change 1+ <%- |
2+ String $cron,
3+ | -%>
4+ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
5+ MAILTO=""
6+
7+ # inventor
8+ <%= $cron %> root bash /opt/inventor/run.sh
Original file line number Diff line number Diff line change 1+ <%- |
2+ Hash $data ,
3+ | -%>
4+ {
5+ "static_config": {
6+ "targets": ["<%= $data['target'] %>"],
7+ "labels": {
8+ <% if 'labels' in $data { -%>
9+ <% $data['labels'].each | String $key, String $val | { -%>
10+ "<%= $key %>": "<%= $val %>",
11+ <% } -%>
12+ <% } -%>
13+ "datacenter": "<%= $data['dc'] %>",
14+ "job": "<%= $data['job'] %>"
15+ },
16+ "target_group": "<%= $data['group'] %>"
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ <%- |
2+ String $key ,
3+ String $url,
4+ Hash $info,
5+ | -%>
6+ #!/usr/bin/env bash
7+ set -e
8+ <% $info.each | String $exporter, Hash $data | { -%>
9+ curl -XPUT -H "x-api-token: <%= $key %>" <%= $url %> -d @/opt/inventor/<%= $exporter %>.json
10+ <% } -%>
You can’t perform that action at this time.
0 commit comments