summaryrefslogtreecommitdiffstats
path: root/makefu/2configs/stats/arafetch.nix
blob: c8ccbfbb9160f1019b2b90beaf9b5765b221e3f5 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{ pkgs, lib, ...}:
with import <stockholm/lib>;
let
  pkg = with pkgs.python3Packages;buildPythonPackage rec {
    rev = "56d41de8219adc";
    name = "arafetch-${rev}";
    propagatedBuildInputs = [
      requests
      docopt
      influxdb
      beautifulsoup4
      paho-mqtt
    ];
    src = pkgs.fetchgit {
      url = "http://cgit.euer.krebsco.de/arafetch";
      inherit rev;
      sha256 = "0hnwbmj0plynhv3h2idhrzf2zcqx3qnw6lq8zzyn9am74pmvza39";
    };
  };
  home = "/var/lib/arafetch";
in {
  users.users.arafetch = {
    uid = genid "arafetch";
    inherit home;
    createHome = true;
    isSystemUser = true;
  };

  systemd.services.ara2mqtt = {
    startAt = "05:00:00";
    after = [ "network-online.target" ];
    path = [ pkg ];
    serviceConfig = {
      User = "arafetch";
      # Restart = "always";
      WorkingDirectory = home;
      PrivateTmp = true;
      ExecStart = pkgs.writeDash "daily-mqtt" ''
        ara2mqtt db/thales-deutschland.json --cantine thales-deutschland --host localhost
      '';
    };
  };
  systemd.services.arafetch = {
    startAt = "Mon,Wed,Fri 09:15:00";
    wantedBy = [ "multi-user.target" ];
    after = [ "network-online.target" ];
    environment.OUTDIR = home;
    path = [ pkg  pkgs.git pkgs.wget ];
    serviceConfig = {
      User = "arafetch";
      # Restart = "always";
      WorkingDirectory = home;
      PrivateTmp = true;
      ExecStart = pkgs.writeDash "start-weekrun" ''
        weekrun || echo "weekrun failed!"
        find $OUTDIR/db -name \*.json | while read path;do
          file=''${path##*/}
          cantine=''${file%%.json}
          ara2influx $path --cantine $cantine --host wbob.r
        done
      '';
    };
  };
}