d92693525a1b421e6fc709a28fcc16754f23a08f
10 fs
.list('/usr/lib/collectd'),
11 fs
.list('/usr/share/luci/statistics/plugins'),
12 uci
.load('luci_statistics')
13 ]).then(function(data
) {
14 var installed
= data
[0],
18 for (var i
= 0; i
< plugins
.length
; i
++) {
19 tasks
.push(fs
.read_direct('/usr/share/luci/statistics/plugins/' + plugins
[i
].name
, 'json').then(L
.bind(function(name
, spec
) {
20 return L
.resolveDefault(L
.require('view.statistics.plugins.' + name
)).then(function(form
) {
21 if (!uci
.get('luci_statistics', 'collectd_' + name
))
22 uci
.add('luci_statistics', 'statistics', 'collectd_' + name
);
28 installed
: installed
.filter(function(e
) { return e
.name
== name
+ '.so' }).length
> 0
31 }, this, plugins
[i
].name
.replace(/\.json$/, ''))));
34 return Promise
.all(tasks
);
38 render: function(plugins
) {
41 for (var i
= 0; i
< plugins
.length
; i
++)
42 plugins
[plugins
[i
].name
] = plugins
[i
];
44 m
= new form
.Map('luci_statistics', _('Collectd Settings'));
47 s
= m
.section(form
.NamedSection
, 'collectd', 'statistics', _('Collectd Settings'));
49 o
= s
.option(form
.Value
, 'Hostname', _('Hostname'));
51 return fs
.trimmed('/proc/sys/kernel/hostname').then(L
.bind(function(name
) {
52 this.placeholder
= name
;
53 return uci
.get('collectd', 'statistics', 'hostname');
57 o
= s
.option(form
.Value
, 'BaseDir', _('Base Directory'));
58 o
.default = '/var/run/collectd';
60 o
= s
.option(form
.Value
, 'Include', _('Directory for sub-configurations'));
61 o
.default = '/etc/collectd/conf.d/*.conf';
63 o
= s
.option(form
.Value
, 'PluginDir', _('Directory for collectd plugins'));
64 o
.default = '/usr/lib/collectd/';
66 o
= s
.option(form
.Value
, 'PIDFile', _('Used PID file'));
67 o
.default = '/var/run/collectd.pid';
69 o
= s
.option(form
.Value
, 'TypesDB', _('Datasets definition file'));
70 o
.default = '/etc/collectd/types.db';
72 o
= s
.option(form
.Value
, 'Interval', _('Data collection interval'), _('Seconds'));
75 o
= s
.option(form
.Value
, 'ReadThreads', _('Number of threads for data collection'));
78 o
= s
.option(form
.Flag
, 'FQDNLookup', _('Try to lookup fully qualified hostname'));
79 o
.default = o
.disabled
;
81 o
.depends('Hostname', '');
84 'general', _('General plugins'),
85 'network', _('Network plugins'),
86 'output', _('Output plugins')
89 for (var i
= 0; i
< groupNames
.length
; i
+= 2) {
90 s
= m
.section(form
.GridSection
, 'statistics_' + groupNames
[i
], groupNames
[i
+ 1]);
92 s
.cfgsections
= L
.bind(function(category
) {
93 return this.map
.data
.sections('luci_statistics', 'statistics')
94 .map(function(s
) { return s
['.name'] })
95 .filter(function(section_id
) {
96 var name
= section_id
.replace(/^collectd_/, ''),
97 plugin
= plugins
[name
];
99 return (section_id
.indexOf('collectd_') == 0 && plugin
!= null &&
100 plugin
.installed
&& plugin
.spec
.category
== category
);
102 }, s
, groupNames
[i
]);
104 s
.sectiontitle = function(section_id
) {
105 var name
= section_id
.replace(/^collectd_/, ''),
106 plugin
= plugins
[name
];
108 return plugin
? plugin
.spec
.title
: name
111 enabled
= s
.option(form
.Flag
, 'enable', _('Enabled'));
112 enabled
.editable
= true;
113 enabled
.modalonly
= false;
114 enabled
.renderWidget = function(section_id
, option_index
, cfgvalue
) {
115 var widget
= form
.Flag
.prototype.renderWidget
.apply(this, [section_id
, option_index
, cfgvalue
]);
117 widget
.querySelector('input[type="checkbox"]').addEventListener('click', L
.bind(function(section_id
, plugin
, ev
) {
118 if (ev
.target
.checked
&& plugin
&& plugin
.form
.addFormOptions
)
119 this.section
.renderMoreOptionsModal(section_id
);
120 }, this, section_id
, plugins
[section_id
.replace(/^collectd_/, '')]));
125 o
= s
.option(form
.DummyValue
, '_dummy', _('Status'));
128 o
.textvalue = function(section_id
) {
129 var name
= section_id
.replace(/^collectd_/, ''),
130 section
= uci
.get('luci_statistics', section_id
),
131 plugin
= plugins
[name
];
133 if (section
.enable
!= '1')
134 return E('em', {}, [_('Plugin is disabled')]);
136 var summary
= plugin
? plugin
.form
.configSummary(section
) : null;
137 return summary
|| E('em', _('none'));
140 s
.modaltitle = function(section_id
) {
141 var name
= section_id
.replace(/^collectd_/, ''),
142 plugin
= plugins
[name
];
144 return plugin
? plugin
.form
.title
: null;
147 s
.addModalOptions = function(s
) {
148 var name
= s
.section
.replace(/^collectd_/, ''),
149 plugin
= plugins
[name
];
154 s
.description
= plugin
.form
.description
;
156 plugin
.form
.addFormOptions(s
);
158 var opt
= s
.children
.filter(function(o
) { return o
.option
== 'enable' })[0];
160 opt
.cfgvalue = function(section_id
, set_value
) {
161 if (arguments
.length
== 2)
162 return form
.Flag
.prototype.cfgvalue
.apply(this, [section_id
, enabled
.formvalue(section_id
)]);
164 return form
.Flag
.prototype.cfgvalue
.apply(this, [section_id
]);
168 s
.renderRowActions = function(section_id
) {
169 var name
= section_id
.replace(/^collectd_/, ''),
170 plugin
= plugins
[name
];
172 var trEl
= this.super('renderRowActions', [ section_id
, _('Configureā¦') ]);
174 if (!plugin
|| !plugin
.form
.addFormOptions
)
175 L
.dom
.content(trEl
, null);