diff --git a/states/vector/config.sls b/states/vector/config.sls new file mode 100644 index 0000000..5a10111 --- /dev/null +++ b/states/vector/config.sls @@ -0,0 +1,30 @@ +--- +{%- from "vector/map.jinja" import vector with context %} +vector-default: + file.managed: + - name: /etc/default/vector + - source: salt://vector/templates/vector.default.j2 + - user: root + - group: root + - mode: 600 + - template: jinja + +vector-config-dir: + file.directory: + - name: /etc/vector + - user: root + - group: root + - mode: 700 + # - watch_in: + # - service: vector-service + +vector-config-file: + file.managed: + - name: /etc/vector/vector.conf + - source: salt://vector/templates/vector.toml.j2 + - user: root + - group: root + - mode: 600 + - template: jinja + # - watch_in: + # - service: vector-service diff --git a/states/vector/defaults.yaml b/states/vector/defaults.yaml new file mode 100644 index 0000000..fc0ce19 --- /dev/null +++ b/states/vector/defaults.yaml @@ -0,0 +1,14 @@ +--- +vector: + enabled: true + install_dir: /usr/local/apps + release_dir: /usr/local/apps/releases + mirror: https://github.com/vectordotdev/vector/releases/download + version: 0.32.1 + os: linux + arch: amd64 + variant: gnu + config: + sources: {} + transforms: {} + sinks: {} diff --git a/states/vector/init.sls b/states/vector/init.sls new file mode 100644 index 0000000..d1963eb --- /dev/null +++ b/states/vector/init.sls @@ -0,0 +1,5 @@ +--- +include: + - .install + - .config + #- .service diff --git a/states/vector/install.sls b/states/vector/install.sls new file mode 100644 index 0000000..d45c01c --- /dev/null +++ b/states/vector/install.sls @@ -0,0 +1,29 @@ +--- +{%- from "vector/map.jinja" import vector with context %} +vector-archive-extract: + archive.extracted: + - name: {{ vector.release_dir }}/vector-{{ vector.version }} + - source: {{ vector.mirror }}/v{{ vector.version }}/vector-{{ vector.version }}-{{ vector.arch }}-unknown-{{ vector.os }}-{{ vector.variant }}.tar.gz + - skip_verify: true + - enforce_toplevel: false + - options: > + --strip 2 + - if_missing: {{ vector.release_dir }}/vector-{{ vector.version }}/bin/vector + # - watch_in: + # - service: vector-service + +vector-binary-symlink: + file.symlink: + - name: /usr/local/bin/vector + - target: {{ vector.release_dir }}/vector-{{ vector.version }}/bin/vector + - force: true + - require: + - archive: vector-archive-extract + # - watch_in: + # - service: vector-service + +vector-cleanup: + software.cleanup: + - name: vector + - path: {{ vector.release_dir }} + - version: "v{{ vector.version }}" diff --git a/states/vector/kernelmap.yaml b/states/vector/kernelmap.yaml new file mode 100644 index 0000000..40943f2 --- /dev/null +++ b/states/vector/kernelmap.yaml @@ -0,0 +1,3 @@ +--- +Linux: + os: "linux" diff --git a/states/vector/map.jinja b/states/vector/map.jinja new file mode 100644 index 0000000..577e880 --- /dev/null +++ b/states/vector/map.jinja @@ -0,0 +1,14 @@ +{%- import_yaml "vector/defaults.yaml" as default_settings -%} + +{%- import_yaml "vector/kernelmap.yaml" as kernelmap -%} +{%- import_yaml "vector/osarchmap.yaml" as osarchmap -%} + +{%- set defaults = salt['grains.filter_by'](default_settings, + default='vector', + merge=salt['grains.filter_by'](osarchmap, grain='osarch', + merge=salt['grains.filter_by'](kernelmap, grain='kernel') + ) + ) +-%} + +{%- set vector = salt['pillar.get']('vector', default=defaults, merge=True) -%} diff --git a/states/vector/osarchmap.yaml b/states/vector/osarchmap.yaml new file mode 100644 index 0000000..1c30bdb --- /dev/null +++ b/states/vector/osarchmap.yaml @@ -0,0 +1,21 @@ +--- +amd64: + arch: "x86_64" + +x86_64: + arch: "x86_64" + +arm64: + arch: "aarch64" + +aarch64: + arch: "arm64" + +armv6l: + arch: "armv7" + +armv7l: + arch: "armv7" + +armhf: + arch: "armv7" diff --git a/states/vector/service.sls b/states/vector/service.sls new file mode 100644 index 0000000..c961ef1 --- /dev/null +++ b/states/vector/service.sls @@ -0,0 +1,16 @@ +--- +{%- from "vector/map.jinja" import vector with context %} +vector-service-file: + file.managed: + - name: /etc/systemd/system/vector.service + - source: salt://vector/templates/vector.service.j2 + - user: root + - group: root + - template: jinja + - watch_in: + - service: vector-service + +vector-service: + service.running: + - name: vector + - enable: true diff --git a/states/vector/templates/vector.default.j2 b/states/vector/templates/vector.default.j2 new file mode 100644 index 0000000..81d4ea4 --- /dev/null +++ b/states/vector/templates/vector.default.j2 @@ -0,0 +1,4 @@ +# /etc/default/vector +# This file can theoretically contain a bunch of environment variables +# for Vector. See https://vector.dev/docs/setup/configuration/#environment-variables +# for details. diff --git a/states/vector/templates/vector.service.j2 b/states/vector/templates/vector.service.j2 new file mode 100644 index 0000000..5098818 --- /dev/null +++ b/states/vector/templates/vector.service.j2 @@ -0,0 +1,24 @@ +{%- from "vector/map.jinja" import vector with context -%} +## {{ salt['pillar.get']('salt_managed', default='Salt Managed') }} +[Unit] +Description=A lightweight, ultra-fast tool for building observability pipelines +Documentation=https://vector.dev +After=network-online.target +Requires=network-online.target + +[Service] +User=vector +Group=vector +ExecStartPre=/usr/bin/vector validate +ExecStart=/usr/bin/vector +ExecReload=/usr/bin/vector validate +ExecReload=/bin/kill -HUP $MAINPID +Restart=always +AmbientCapabilities=CAP_NET_BIND_SERVICE +EnvironmentFile=-/etc/default/vector +# Since systemd 229, should be in [Unit] but in order to support systemd <229, +# it is also supported to have it here. +StartLimitInterval=10 +StartLimitBurst=5 +[Install] +WantedBy=multi-user.target diff --git a/states/vector/templates/vector.toml.j2 b/states/vector/templates/vector.toml.j2 new file mode 100644 index 0000000..80c44da --- /dev/null +++ b/states/vector/templates/vector.toml.j2 @@ -0,0 +1,25 @@ +## {{ salt['pillar.get']('salt_managed', default='Salt Managed') }} +{%- from "vector/map.jinja" import vector with context %} + +{% macro cfg(value) -%} +{% if value -%} +{% for paramname, paramvalue in value.items() -%} +{{ ' ' }}{{ paramname }} = {% if paramvalue is sameas True or paramvalue is sameas False %}{{ paramvalue|string|lower }}{% elif paramvalue is iterable and paramvalue is not string %}[{{ paramvalue|join(",") }}]{% else %}"{{ paramvalue }}"{% endif %} +{% endfor %} +{%- endif %} +{%- endmacro %} + +{% for name, value in vector.config.sources.items() -%} +[sources.{{ name }}] +{{ cfg(value) }} +{% endfor %} + +{% for name, value in vector.config.transforms.items() -%} +[transforms.{{ name }}] +{{ cfg(value) }} +{% endfor -%} + +{% for name, value in vector.config.sinks.items() -%} +[sinks.{{ name }}] +{{ cfg(value) }} +{% endfor -%}