-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
91 changed files
with
1,348 additions
and
596 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ let | |
"mikrotik" | ||
"modemmanager" | ||
"mongodb" | ||
"mqtt" | ||
"mysqld" | ||
"nats" | ||
"nextcloud" | ||
|
140 changes: 140 additions & 0 deletions
140
nixos/modules/services/monitoring/prometheus/exporters/mqtt.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
options, | ||
utils, | ||
}: | ||
|
||
let | ||
inherit (lib) | ||
mkIf | ||
mkEnableOption | ||
mkOption | ||
types | ||
; | ||
cfg = config.services.prometheus.exporters.mqtt; | ||
toConfigBoolean = x: if x then "True" else "False"; | ||
toConfigList = builtins.concatStringsSep ","; | ||
in | ||
{ | ||
# https://github.com/kpetremann/mqtt-exporter/tree/master?tab=readme-ov-file#configuration | ||
port = 9000; | ||
extraOpts = { | ||
keepFullTopic = mkEnableOption "Keep entire topic instead of the first two elements only. Usecase: Shelly 3EM"; | ||
logLevel = mkOption { | ||
type = types.enum [ | ||
"CRITICAL" | ||
"ERROR" | ||
"WARNING" | ||
"INFO" | ||
"DEBUG" | ||
]; | ||
default = "INFO"; | ||
example = "DEBUG"; | ||
description = "Logging level"; | ||
}; | ||
logMqttMessage = mkEnableOption "Log MQTT original message, only if `LOG_LEVEL` is set to DEBUG."; | ||
mqttIgnoredTopics = mkOption { | ||
type = types.listOf types.str; | ||
default = [ ]; | ||
description = "Lists of topics to ignore. Accepts wildcards."; | ||
}; | ||
mqttAddress = mkOption { | ||
type = types.str; | ||
default = "127.0.0.1"; | ||
description = "IP or hostname of MQTT broker."; | ||
}; | ||
mqttPort = mkOption { | ||
type = types.port; | ||
default = 1883; | ||
description = "TCP port of MQTT broker."; | ||
}; | ||
mqttTopic = mkOption { | ||
type = types.str; | ||
default = "#"; | ||
description = "Topic path to subscribe to."; | ||
}; | ||
mqttKeepAlive = mkOption { | ||
type = types.int; | ||
default = 60; | ||
example = 30; | ||
description = "Keep alive interval to maintain connection with MQTT broker."; | ||
}; | ||
mqttUsername = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
example = "mqttexporter"; | ||
description = "Username which should be used to authenticate against the MQTT broker."; | ||
}; | ||
mqttV5Protocol = mkEnableOption "Force to use MQTT protocol v5 instead of 3.1.1."; | ||
mqttClientId = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
description = "Set client ID manually for MQTT connection"; | ||
}; | ||
mqttExposeClientId = mkEnableOption "Expose the client ID as a label in Prometheus metrics."; | ||
prometheusPrefix = mkOption { | ||
type = types.str; | ||
default = "mqtt_"; | ||
description = "Prefix added to the metric name."; | ||
}; | ||
topicLabel = mkOption { | ||
type = types.str; | ||
default = "topic"; | ||
description = "Define the Prometheus label for the topic."; | ||
}; | ||
zigbee2MqttAvailability = mkEnableOption "Normalize sensor name for device availability metric added by Zigbee2MQTT."; | ||
zwaveTopicPrefix = mkOption { | ||
type = types.str; | ||
default = "zwave/"; | ||
description = "MQTT topic used for Zwavejs2Mqtt messages."; | ||
}; | ||
esphomeTopicPrefixes = mkOption { | ||
type = types.listOf types.str; | ||
default = [ ]; | ||
description = "MQTT topic used for ESPHome messages."; | ||
}; | ||
hubitatTopicPrefixes = mkOption { | ||
type = types.listOf types.str; | ||
default = [ "hubitat/" ]; | ||
description = "MQTT topic used for Hubitat messages."; | ||
}; | ||
environmentFile = mkOption { | ||
type = types.nullOr types.path; | ||
default = null; | ||
example = [ "/run/secrets/mqtt-exporter" ]; | ||
description = '' | ||
File to load as environment file. Useful for e.g. setting `MQTT_PASSWORD` | ||
without putting any secrets into the Nix store. | ||
''; | ||
}; | ||
}; | ||
serviceOpts = { | ||
environment = { | ||
KEEP_FULL_TOPIC = toConfigBoolean cfg.keepFullTopic; | ||
LOG_LEVEL = cfg.logLevel; | ||
LOG_MQTT_MESSAGE = toConfigBoolean cfg.logMqttMessage; | ||
MQTT_IGNORED_TOPIC = toConfigList cfg.mqttIgnoredTopics; | ||
MQTT_ADDRESS = cfg.mqttAddress; | ||
MQTT_PORT = toString cfg.mqttPort; | ||
MQTT_TOPIC = cfg.mqttTopic; | ||
MQTT_KEEPALIVE = toString cfg.mqttKeepAlive; | ||
MQTT_USERNAME = cfg.mqttUsername; | ||
MQTT_V5_PROTOCOL = toConfigBoolean cfg.mqttV5Protocol; | ||
MQTT_CLIENT_ID = mkIf (cfg.mqttClientId != null) cfg.mqttClientId; | ||
PROMETHEUS_ADDRESS = cfg.listenAddress; | ||
PROMETHEUS_PORT = toString cfg.port; | ||
PROMETHEUS_PREFIX = cfg.prometheusPrefix; | ||
TOPIC_LABEL = cfg.topicLabel; | ||
ZIGBEE2MQTT_AVAILABILITY = toConfigBoolean cfg.zigbee2MqttAvailability; | ||
ZWAVE_TOPIC_PREFIX = cfg.zwaveTopicPrefix; | ||
ESPHOME_TOPIC_PREFIXES = toConfigList cfg.esphomeTopicPrefixes; | ||
HUBITAT_TOPIC_PREFIXES = toConfigList cfg.hubitatTopicPrefixes; | ||
}; | ||
serviceConfig = { | ||
EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile; | ||
ExecStart = lib.getExe pkgs.mqtt-exporter; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
{ lib, ... }: | ||
let | ||
ocrContent = "Video Test"; | ||
videoFile = "test.webm"; | ||
in | ||
{ | ||
name = "lomiri-mediaplayer-app-standalone"; | ||
meta.maintainers = lib.teams.lomiri.members; | ||
|
||
nodes.machine = | ||
{ config, pkgs, ... }: | ||
{ | ||
imports = [ ./common/x11.nix ]; | ||
|
||
services.xserver.enable = true; | ||
|
||
environment = { | ||
# Setup video | ||
etc."${videoFile}".source = | ||
pkgs.runCommand videoFile | ||
{ | ||
nativeBuildInputs = with pkgs; [ | ||
ffmpeg # produce video for OCR | ||
(imagemagick.override { ghostscriptSupport = true; }) # produce OCR-able image | ||
]; | ||
} | ||
'' | ||
magick -size 400x400 canvas:white -pointsize 40 -fill black -annotate +100+100 '${ocrContent}' output.png | ||
ffmpeg -re -loop 1 -i output.png -c:v libvpx -b:v 100K -t 120 $out -loglevel fatal | ||
''; | ||
systemPackages = with pkgs.lomiri; [ | ||
suru-icon-theme | ||
lomiri-mediaplayer-app | ||
]; | ||
variables = { | ||
UITK_ICON_THEME = "suru"; | ||
}; | ||
}; | ||
|
||
i18n.supportedLocales = [ "all" ]; | ||
|
||
fonts = { | ||
packages = with pkgs; [ | ||
# Intended font & helps with OCR | ||
ubuntu-classic | ||
]; | ||
}; | ||
}; | ||
|
||
enableOCR = true; | ||
|
||
testScript = '' | ||
machine.wait_for_x() | ||
with subtest("lomiri mediaplayer launches"): | ||
machine.succeed("lomiri-mediaplayer-app >&2 &") | ||
machine.wait_for_text("Choose from") | ||
machine.screenshot("lomiri-mediaplayer_open") | ||
machine.succeed("pkill -f lomiri-mediaplayer-app") | ||
with subtest("lomiri mediaplayer plays video"): | ||
machine.succeed("lomiri-mediaplayer-app /etc/${videoFile} >&2 &") | ||
machine.wait_for_text("${ocrContent}") | ||
machine.screenshot("lomiri-mediaplayer_playback") | ||
machine.succeed("pkill -f lomiri-mediaplayer-app") | ||
with subtest("lomiri mediaplayer localisation works"): | ||
# OCR struggles with finding identifying the translated window title, and lomiri-content-hub QML isn't translated | ||
# Cause an error, and look for the error popup | ||
machine.succeed("touch invalid.mp4") | ||
machine.succeed("env LANG=de_DE.UTF-8 lomiri-mediaplayer-app invalid.mp4 >&2 &") | ||
machine.wait_for_text("Fehler") | ||
machine.screenshot("lomiri-mediaplayer_localised") | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.