summaryrefslogtreecommitdiffstats
path: root/applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_monitor.js
blob: cc34cd13a0859b5765fa8da9a70c9daa770d49e7 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'use strict';
'require form';
'require view';

function ESIFlags(o) {
	o.value('EXEC', _('Execute notify command'));
	o.value('SYSLOG', _('Write to syslog'));
	o.value('SYSLOG+EXEC', _('Write to syslog and execute notify command'))
	o.value('IGNORE', _('Ignore'));
	o.default = 'SYSLOG';
	o.optional = true;
	return o;
}

function MonitorUserOptions(s) {
		let o

		s.optional = true;
		s.addremove = true;
		s.anonymous = true;

		o = s.option(form.Value, 'upsname', _('Name of UPS'), _('As configured by NUT'));
		o.optional = false;

		o = s.option(form.Value, 'hostname', _('Hostname or address of UPS'));
		o.optional = false;
		o.datatype = 'or(host,ipaddr)';

		o = s.option(form.Value, 'port', _('Port'));
		o.optional = true;
		o.placeholder = 3493;
		o.datatype = 'port';

		o = s.option(form.Value, 'powervalue', _('Power value'));
		o.optional = false;
		o.datatype = 'uinteger';
		o.default = 1;

		o = s.option(form.Value, 'username', _('Username'));
		o.optional = false;

		o = s.option(form.Value, 'password', _('Password'));
		o.optional = false;
		o.password = true;

		return s;
}

return view.extend({
	render: function() {
		let m, s, o;

		m = new form.Map('nut_monitor', _('NUT Monitor'),
			_('Network UPS Tools Monitoring Configuration'));

		s = m.section(form.NamedSection, 'upsmon', 'upsmon', _('Global Settings'));
		s.addremove = true;
		s.optional = true;

		o = s.option(form.Value, 'minsupplies', _('Minimum required number or power supplies'));
		o.datatype = 'uinteger'
		o.placeholder = 1;
		o.optional = true;

		o = s.option(form.Value, 'pollfreq', _('Poll frequency'));
		o.datatype = 'uinteger'
		o.placeholder = 5;
		o.optional = true;

		o = s.option(form.Value, 'pollfreqalert', _('Poll frequency alert'));
		o.datatype = 'uinteger'
		o.optional = true;
		o.placeholder = 5;

		o = s.option(form.Value, 'hostsync', _('Host Sync'));
		o.optional = true;
		o.placeholder = 15;

		o = s.option(form.Value, 'deadtime', _('Deadtime'));
		o.datatype = 'uinteger'
		o.optional = true;
		o.placeholder = 15;

		s = m.section(form.TypedSection, 'notifications', _('Notifications settings'));
		s.optional = true;
		s.addremove = true;
		s.anonymous = false;

		o = s.option(form.Value, 'message', _('Custom notification message for message type'));
		o.optional = true

		o = s.option(form.ListValue, 'flag', _('Notification flags'));
		ESIFlags(o)

		s = m.section(form.TypedSection, 'monitor', _('UPS Monitor User Settings'));
		MonitorUserOptions(s);

		o = s.option(form.ListValue, 'type', _('User type (Primary/Auxiliary)'));
		o.optional = false;
		o.value('primary', 'Primary');
		o.value('secondary', 'Auxiliary');
		o.default = 'secondary'

		s = m.section(form.TypedSection, 'master', _('UPS Primary (Deprecated)'));
		MonitorUserOptions(s);

		s = m.section(form.TypedSection, 'slave', _('UPS Auxiliary (Deprecated)'));
		MonitorUserOptions(s);

		return m.render();
	}
});