summaryrefslogtreecommitdiffstats
path: root/makefu/2configs/stats/telegraf/hamstats.nix
blob: 88c1b6d5d3d2217c9878d1be9b4e4e6c2101b54f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{ pkgs, ...}:

let
  genTopic = name: topic: tags: {
      servers = [ "tcp://localhost:1883" ];
      username = "stats";
      password = builtins.readFile <secrets/mqtt/stats>;
      qos = 0;
      connection_timeout = "30s";
      topics = [ topic ];
      tags = tags;
      persistent_session = false;
      name_override = name;
      data_format = "json";
      # json_query = tags.sensor; #TODO?
    };
  hamStat = host:
            sensor:
            (genTopic sensor
                      "/ham/${host}/${sensor}/tele/SENSOR"
                      {"host" = host;
                       "scope" = "ham";
                       "sensor" = sensor;
                      } );
  bme = host: [(hamStat host "BME280")];
in {
  services.telegraf.extraConfig.inputs.mqtt_consumer = (bme "schlafzimmer");
}