From f16568b4dbbab96ca6987a8867712dd9e206df3a Mon Sep 17 00:00:00 2001 From: Patrik Holmqvist Date: Tue, 25 Mar 2025 14:25:30 +0100 Subject: [PATCH] First commit of new telegraf class, SC-2522 --- .../puppet/modules/eid/manifests/telegraf2.pp | 55 +++++++++++++++++++ .../templates/telegraf2/95-telegraf.conf.erb | 17 ++++++ .../telegraf2/docker-compose.yml.erb | 25 +++++++++ 3 files changed, 97 insertions(+) create mode 100644 global/overlay/etc/puppet/modules/eid/manifests/telegraf2.pp create mode 100644 global/overlay/etc/puppet/modules/eid/templates/telegraf2/95-telegraf.conf.erb create mode 100644 global/overlay/etc/puppet/modules/eid/templates/telegraf2/docker-compose.yml.erb diff --git a/global/overlay/etc/puppet/modules/eid/manifests/telegraf2.pp b/global/overlay/etc/puppet/modules/eid/manifests/telegraf2.pp new file mode 100644 index 00000000..e1fb70e9 --- /dev/null +++ b/global/overlay/etc/puppet/modules/eid/manifests/telegraf2.pp @@ -0,0 +1,55 @@ +# This puppet manifest is used to configure Telegraf for Sweden Connect + +# @param version Version of the docker image to use. (referenced in compose file) +# @param server_fqdn The FQDN of the server. (referenced in compose file) +# @param ports Port mappings for container +# @param service_dir The directory where all related config and files are stored. (referenced in compose file) +class eid::telegraf2 ( + String $version = 'latest', + String $server_fqdn = $facts['networking']['fqdn'], + Array $ports = [], + String $service_dir = '/opt/telegraf', +) { + + # Get influx values + $influxdb2_token = hiera(influxdb2_token,NOT_SET_IN_HIERA) + $influx2_token = hiera(influx2_token,NOT_SET_IN_HIERA) + $influxdb2_org = hiera(influxdb2_org,NOT_SET_IN_HIERA) + $influxdb2_bucket = hiera(influxdb2_bucket,NOT_SET_IN_HIERA) + $influxdb2_bucket_proxy = hiera(influxdb2_bucket_proxy,NOT_SET_IN_HIERA) + + file {[$service_dir,"${service_dir}/telegraf.conf.d"]: ensure => directory } + concat {"${service_dir}/telegraf.conf": + owner => 'root', + group => 'root', + mode => '0644', + notify => Sunet::Docker_run['telegraf'] + } + + # Below not pretty but I'm piggy-backing on this class to add a secondary output to test the new influx2-server + if ($influx2_token != 'NOT_SET_IN_HIERA') { + file { "${service_dir}/telegraf.conf.d/95-telegraf.conf": + ensure => file, + owner => 'root', + group => 'root', + path => "${service_dir}/telegraf.conf.d/95-telegraf.conf", + mode => '0644', + content => template('eid/telegraf2/95-telegraf.conf.erb'), + } + } + + eid_glob(["${service_dir}/telegraf.conf.d/*.conf"]).each |String $file| { + concat::fragment { $file: + target => "${service_dir}/telegraf.conf", + source => $file, + } + } + + sunet::docker_compose { 'telegraf': + content => template('eid/telegraf2/docker-compose.yml.erb'), + service_name => 'telegraf', + compose_dir => '/opt/', + compose_filename => 'docker-compose.yml', + description => 'telegraf' + } +} diff --git a/global/overlay/etc/puppet/modules/eid/templates/telegraf2/95-telegraf.conf.erb b/global/overlay/etc/puppet/modules/eid/templates/telegraf2/95-telegraf.conf.erb new file mode 100644 index 00000000..78e685c8 --- /dev/null +++ b/global/overlay/etc/puppet/modules/eid/templates/telegraf2/95-telegraf.conf.erb @@ -0,0 +1,17 @@ +[[outputs.influxdb_v2]] + urls = ["https://metrics-external-1.sunet.se:8086"] + token = "$INFLUX2_TOKEN" + organization = "$INFLUXDB2_ORG" + bucket = "$INFLUXDB2_BUCKET" + insecure_skip_verify = true + [outputs.influxdb_v2.tagdrop] + influxdb_database = ["*"] +[[outputs.influxdb_v2]] + urls = ["https://metrics-external-1.sunet.se:8086"] + token = "$INFLUX2_TOKEN" + organization = "$INFLUXDB2_ORG" + bucket = "$INFLUXDB2_BUCKET_PROXY" + insecure_skip_verify = true + tagexclude = ["influxdb_database"] + [outputs.influxdb_v2.tagpass] + influxdb_database = ["proxy"] diff --git a/global/overlay/etc/puppet/modules/eid/templates/telegraf2/docker-compose.yml.erb b/global/overlay/etc/puppet/modules/eid/templates/telegraf2/docker-compose.yml.erb new file mode 100644 index 00000000..a08a0f4f --- /dev/null +++ b/global/overlay/etc/puppet/modules/eid/templates/telegraf2/docker-compose.yml.erb @@ -0,0 +1,25 @@ +--- +services: + telegraf: + image: docker.sunet.se/test-my-eid:<%= @version %> + container_name: telegraf + environment: + - INFLUXDB2_TOKEN=<%= @influxdb2_token %> + - INFLUXDB2_ORG=<%= @influxdb2_org %> + - INFLUXDB2_BUCKET=<%= @influxdb2_bucket %> + - INFLUXDB2_BUCKET_PROXY=<%= @influxdb2_bucket_proxy %> +<% if @influx2_token != 'NOT_SET_IN_HIERA' -%> + - INFLUX2_TOKEN=<%= @influx2_token" %> +<% end -%> + + hostname: <%= @server_fqdn %> + + volumes: + - '/etc/ssl:/etc/ssl' + - '/dev/log:/dev/log' + - '/var/log:/var/log' + - <%= @service_dir %>:<%= @service_dir %> + - '/var/run/utmp:/var/run/utmp:ro' + + ports: + - <%= @ports %> \ No newline at end of file