Trying to backport an rrd collectd-mod-nut plugin fix to 18.06

In the past, we fixed an issue with LuCI drawing broken icons instead of graphs when the UPS doesn't support certain measurements. Basically it was done by inserting an if((instances=find_instances(...))) to the nut.js file.

Now I want to backport that solution to a gl.iNet's fork of 18.06. But it seems that version/fork doesn't use the same approach of having such nut.js javascript file. Does anyone remembers how is implemented on that version?
EDIT: Maybe nut.lua instead of nut.js?

Wrong forum.

I understand your point, but still it's OpenWrt based, so I think it would be easier to find a solution here than on the "I don't know" kind of answers of GL.iNet forum.

In the meantime I've found a file on /overlay/upper/usr/lib/lua/luci/statistics/rrdtool/definitions that looks similar to what I want to modify. Here a part of nut.lua:

module("luci.statistics.rrdtool.definitions.nut",package.seeall)

function rrdargs( graph, plugin, plugin_instance, dtype )

	local voltages = {
		title = "%H: Voltages on UPS \"%pi\"",
		vlabel = "V",
		number_format = "%5.1lfV",
		data = {
			instances = {
				voltage = { "battery", "input", "output" }
			},

			options = {
				voltage_output  = { color = "00e000", title = "Output voltage", noarea=true, overlay=true },
				voltage_battery = { color = "0000ff", title = "Battery voltage", noarea=true, overlay=true },
				voltage_input   = { color = "ffb000", title = "Input voltage", noarea=true, overlay=true }
			}
		}
	}

And here the equivalent part of the nut.js I want to backport:

'use strict';
'require baseclass';

return baseclass.extend({
	title: _('UPS'),

	rrdargs: function(graph, host, plugin, plugin_instance, dtype) {
		var definitions = [];
		var instances;

		function find_instances(dtype, wanted) {
			var matching = graph.dataInstances(host, plugin, plugin_instance, dtype).filter(function(instance) {
				return wanted.indexOf(instance) > -1;
			});

			return matching.length ? { [dtype]: matching } : null;
		}

		if ((instances = find_instances('voltage', [ 'input', 'output' ])) != null) {
			definitions.push({
				title: "%H: AC voltages on UPS \"%pi\"",
				vlabel: "Vac",
				y_min: "90",
				y_max: "140",
				alt_autoscale_max: true,
				number_format: "%5.1lfV",
				data: {
					instances: instances,
					options: {
						voltage_output : { color: "00e000", title: "Output voltage", noarea: true, overlay: true },
						voltage_input  : { color: "ffb000", title: "Input voltage", noarea: true, overlay: true }
					}
				}
			});
		}

		if ((instances = find_instances('voltage', [ 'battery' ])) != null) {
			definitions.push({
				title: "%H: Battery voltage on UPS \"%pi\"",
				vlabel: "Vdc",
				y_min: "10",
				y_max: "14",
				alt_autoscale_max: true,
				number_format: "%5.1lfV",
				data: {
					instances: instances,
					options: {
						voltage: { color: "0000ff", title: "Battery voltage", noarea: true, overlay: true }
					}
				}
			});
		}

I'm not familiar on .lua, so I'm not sure on how to proceed.

If device is supported by openwrt.org system why would you go extra leap to try to revive a dinosaur system?

Please connect to your OpenWrt device using ssh and copy the output of the following commands and post it here using the "Preformatted text </> " button:
grafik
Remember to redact passwords, MAC addresses and any public IP addresses you may have:

ubus call system board

It's not officially supported by OpenWrt as is an GL-SFT1200 Opal (SiFlower-based). That's why I'm trying to backport the recently implemented fix.

However, if you look the previous post (we were writing at the same time), you can get a better idea of what I want to achieve.

You should ask in glinet forums, maybe somebody already did the backport, if not - probably you find the move from lua to js in openwrt changelog and can try and revert it.

1 Like

This topic was automatically closed after 25 hours. New replies are no longer allowed.