6
0
Fork 0

Add initial __prometheus_yoctotemp_exporter type

This commit is contained in:
Timothée Floure 2020-11-04 10:27:44 +01:00
parent d2f70d85b4
commit e5f5477241
6 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,12 @@
[Unit]
Description=Prometheus YoctoTemperature exporter
After=network.target
[Service]
Type=simple
# FIXME: ugly workaround with potential side effects.
ExecStartPre=/usr/bin/chown -R root:dialout /dev/bus/usb/003
ExecStart=/opt/prometheus-yoctotemp-exporter/venv/bin/python /opt/prometheus-yoctotemp-exporter/prometheus-yoctotemp-exporter
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,20 @@
#!/bin/sh
VCS_TAG=$(cat "$__object/parameter/version")
VCS_URL="https://code.recycled.cloud/e-Durable/prometheus-yoctotemp-exporter/raw/tag/$VCS_TAG/prometheus-yoctotemp-exporter"
cat << EOF
cd /opt/prometheus-yoctotemp-exporter
# Fetch sources.
curl "$VCS_URL" -o prometheus-yoctotemp-exporter
# Install virtualenv and dependencies.
virtualenv venv
. venv/bin/activate
pip install prometheus_client
pip install yoctopuce
# Start service
service prometheus-yoctotemp-exporter start
EOF

View File

@ -0,0 +1,57 @@
cdist-type__prometheus_yoctotemp_exporter(7)
=====================
NAME
----
cdist-type__prometheus_yoctotemp_exporter - Deploy a Prometheus exporter for the YoctoTemperature sensor
DESCRIPTION
-----------
This (singleton) type deploys a Prometheus exporter for the YoctoTemperature sensor
NOTE
----
FIXME: this systemd service currently use an ugly hack to deal with
/dev/bus/usb permissions, with potential side effects. udev should be used
instead.
REQUIRED PARAMETERS
-------------------
version
Release tag used to fetch sources from upstream's VCS.
OPTIONAL PARAMETERS
-------------------
None.
BOOLEAN PARAMETERS
------------------
None.
EXAMPLES
--------
.. code-block:: sh
__prometheus_yoctotemp_expoter --version v0.1
SEE ALSO
--------
- `YoctoTemerature sensor <https://www.yoctopuce.com/EN/products/usb-environmental-sensors/yocto-temperature>`_
- `prometheus-yoctotemp-exporter VCS <https://code.recycled.cloud/e-Durable/prometheus-yoctotemp-exporter>`_
AUTHORS
-------
Timothée Floure <t.floure@e-durable.ch>
COPYING
-------
Copyright \(C) 2020 Timothée Floure. You can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

View File

@ -0,0 +1,22 @@
#!/bin/sh
os=$(cat "${__global:?}/explorer/os")
case "$os" in
debian|ubuntu)
__package python3-virtualenv
__package curl
;;
*)
echo "$os is not supported by this type. Exiting" >&2
exit 1
;;
esac
__directory /opt/prometheus-yoctotemp-exporter
# Make sure the prometheus user exist and belongs to dialout.
__user prometheus
require="__user/prometheus" __user_groups prometheus --group dialout
__systemd_unit prometheus-yoctotemp-exporter.service \
--source "$__type/files/prometheus-yoctotemp-exporter.service" \
--enablement-state enabled

View File

@ -0,0 +1 @@
version