summaryrefslogtreecommitdiffstats
path: root/flake.lock
blob: 6aa7a6985c3388c52d5fcd950e8d81c1310a7150 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{
  "nodes": {
    "mozillapkgs": {
      "flake": false,
      "locked": {
        "lastModified": 1603906276,
        "narHash": "sha256-RsNPnEKd7BcogwkqhaV5kI/HuNC4flH/OQCC/4W5y/8=",
        "owner": "mozilla",
        "repo": "nixpkgs-mozilla",
        "rev": "8c007b60731c07dd7a052cce508de3bb1ae849b4",
        "type": "github"
      },
      "original": {
        "owner": "mozilla",
        "repo": "nixpkgs-mozilla",
        "type": "github"
      }
    },
    "naersk": {
      "inputs": {
        "nixpkgs": "nixpkgs"
      },
      "locked": {
        "lastModified": 1610392286,
        "narHash": "sha256-3wFl5y+4YZO4SgRYK8WE7JIS3p0sxbgrGaQ6RMw+d98=",
        "owner": "nmattia",
        "repo": "naersk",
        "rev": "d7bfbad3304fd768c0f93a4c3b50976275e6d4be",
        "type": "github"
      },
      "original": {
        "owner": "nmattia",
        "repo": "naersk",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1610850544,
        "narHash": "sha256-6GnsJuulJNdSrZNP98rRTRX/zJbxdC7m3qaH6WwsOuY=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "2fbc36f3d891c86ae34dc0414bc78e74e8911218",
        "type": "github"
      },
      "original": {
        "id": "nixpkgs",
        "type": "indirect"
      }
    },
    "nixpkgs_2": {
      "locked": {
        "lastModified": 1610850544,
        "narHash": "sha256-6GnsJuulJNdSrZNP98rRTRX/zJbxdC7m3qaH6WwsOuY=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "2fbc36f3d891c86ae34dc0414bc78e74e8911218",
        "type": "github"
      },
      "original": {
        "id": "nixpkgs",
        "type": "indirect"
      }
    },
    "root": {
      "inputs": {
        "mozillapkgs": "mozillapkgs",
        "naersk": "naersk",
        "nixpkgs": "nixpkgs_2",
        "utils": "utils"
      }
    },
    "utils": {
      "locked": {
        "lastModified": 1610051610,
        "narHash": "sha256-U9rPz/usA1/Aohhk7Cmc2gBrEEKRzcW4nwPWMPwja4Y=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "3982c9903e93927c2164caa727cd3f6a0e6d14cc",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    }
  },
  "root": "root",
  "version": 7
}
ighlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
'use strict';
// SPDX-License-Identifier: GPL-3.0-or-later

// This program will connect to one Stiebel Eltron ISG for heatpump heating
// to get the heat pump metrics.

// example configuration in netdata/conf.d/node.d/stiebeleltron.conf.md

require("url");
require("http");
var netdata = require("netdata");

netdata.debug("loaded " + __filename + " plugin");

var stiebeleltron = {
    name: "Stiebel Eltron",
    enable_autodetect: false,
    update_every: 10,
    base_priority: 60000,
    charts: {},
    pages: {},

    createBasicDimension: function (id, name, multiplier, divisor) {
        return {
            id: id,                                     // the unique id of the dimension
            name: name,                                 // the name of the dimension
            algorithm: netdata.chartAlgorithms.absolute,// the id of the netdata algorithm
            multiplier: multiplier,                     // the multiplier
            divisor: divisor,                           // the divisor
            hidden: false                               // is hidden (boolean)
        };
    },

    processResponse: function (service, html) {
        if (html === null) return;

        // add the service
        service.commit();

        var page = stiebeleltron.pages[service.name];
        var categories = page.categories;
        var categoriesCount = categories.length;
        while (categoriesCount--) {
            var context = {
                html: html,
                service: service,
                category: categories[categoriesCount],
                page: page,
                chartDefinition: null,
                dimension: null
            };
            stiebeleltron.processCategory(context);

        }
    },

    processCategory: function (context) {
        var charts = context.category.charts;
        var chartCount = charts.length;
        while (chartCount--) {
            context.chartDefinition = charts[chartCount];
            stiebeleltron.processChart(context);
        }
    },

    processChart: function (context) {
        var dimensions = context.chartDefinition.dimensions;
        var dimensionCount = dimensions.length;
        context.service.begin(stiebeleltron.getChartFromContext(context));

        while (dimensionCount--) {
            context.dimension = dimensions[dimensionCount];
            stiebeleltron.processDimension(context);
        }
        context.service.end();
    },

    processDimension: function (context) {
        var dimension = context.dimension;
        var match = new RegExp(dimension.regex).exec(context.html);
        if (match === null) return;
        var value = match[1].replace(",", ".");
        // most values have a single digit by default, which requires the values to be multiplied. can be overridden.
        if (stiebeleltron.isDefined(dimension.digits)) {
            value *= Math.pow(10, dimension.digits);
        } else {
            value *= 10;
        }
        context.service.set(stiebeleltron.getDimensionId(context), value);
    },

    getChartFromContext: function (context) {
        var chartId = this.getChartId(context);
        var chart = stiebeleltron.charts[chartId];
        if (stiebeleltron.isDefined(chart)) return chart;

        var chartDefinition = context.chartDefinition;
        var service = context.service;
        var dimensions = {};

        var dimCount = chartDefinition.dimensions.length;
        while (dimCount--) {
            var dim = chartDefinition.dimensions[dimCount];
            var multiplier = 1;
            var divisor = 10;
            if (stiebeleltron.isDefined(dim.digits)) divisor = Math.pow(10, Math.max(0, dim.digits));
            if (stiebeleltron.isDefined(dim.multiplier)) multiplier = dim.multiplier;
            if (stiebeleltron.isDefined(dim.divisor)) divisor = dim.divisor;
            context.dimension = dim;
            var dimId = this.getDimensionId(context);
            dimensions[dimId] = this.createBasicDimension(dimId, dim.name, multiplier, divisor);
        }

        chart = {
            id: chartId,
            name: '',
            title: chartDefinition.title,
            units: chartDefinition.unit,
            family: context.category.name,
            context: 'stiebeleltron.' + context.category.id + '.' + chartDefinition.id,
            type: chartDefinition.type,
            priority: stiebeleltron.base_priority + chartDefinition.prio,// the priority relative to others in the same family
            update_every: service.update_every,             // the expected update frequency of the chart
            dimensions: dimensions
        };
        chart = service.chart(chartId, chart);
        stiebeleltron.charts[chartId] = chart;

        return chart;
    },

    // module.serviceExecute()
    // this function is called only from this module
    // its purpose is to prepare the request and call
    // netdata.serviceExecute()
    serviceExecute: function (name, uri, update_every) {
        netdata.debug(this.name + ': ' + name + ': url: ' + uri + ', update_every: ' + update_every);

        var service = netdata.service({
            name: name,
            request: netdata.requestFromURL(uri),
            update_every: update_every,
            module: this
        });
        service.execute(this.processResponse);
    },


    configure: function (config) {
        if (stiebeleltron.isUndefined(config.pages)) return 0;
        var added = 0;
        var pageCount = config.pages.length;
        while (pageCount--) {
            var page = config.pages[pageCount];
            // some validation
            if (stiebeleltron.isUndefined(page.categories) || page.categories.length < 1) {
                netdata.error("Your Stiebel Eltron config is invalid. Disabling plugin.");
                return 0;
            }
            if (stiebeleltron.isUndefined(page.update_every)) page.update_every = this.update_every;
            this.pages[page.name] = page;
            this.serviceExecute(page.name, page.url, page.update_every);
            added++;
        }
        return added;
    },

    // module.update()
    // this is called repeatedly to collect data, by calling
    // netdata.serviceExecute()
    update: function (service, callback) {
        service.execute(function (serv, data) {
            service.module.processResponse(serv, data);
            callback();
        });
    },

    getChartId: function (context) {
        return "stiebeleltron_" + context.page.id +
            "." + context.category.id +
            "." + context.chartDefinition.id;
    },

    getDimensionId: function (context) {
        return context.dimension.id;
    },

    isUndefined: function (value) {
        return typeof value === 'undefined';
    },

    isDefined: function (value) {
        return typeof value !== 'undefined';
    }
};

module.exports = stiebeleltron;