Quote from: Monviech on August 03, 2024, 05:42:05 AM
When widgets fail to load the console log in the browser is your friend.
Yes indeed - my new BEST friend.
Thanks for the pointers - got the plugin written and working.
Cheers
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts MenuQuote from: Monviech on August 03, 2024, 05:42:05 AM
When widgets fail to load the console log in the browser is your friend.
/usr/local/opnsense/www/js/widgets
/*
* Copyright (C) 2024 David Berry.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
import BaseTableWidget from "./BaseTableWidget.js";
export default class Apcupsd extends BaseTableWidget {
constructor() {
super();
this.dataError = false;
this.data = null;
this.statusColor = this.translations['t_statusColorWarning'];
this.statusText = this.translations['t_statusTextWaiting'];
this.statusName = this.translations['t_statusNameOffline'];
}
getGridOptions() {
return {
// trigger overflow-y:scroll after 650px height
sizeToContent: 650,
}
}
getMarkup() {
let $container = $('<div></div>');
let $apcupsdTable = this.createTable('apcupsd-table', {
headerPosition: 'left',
});
$container.append($apcupsdTable);
return $container;
}
async onWidgetTick() {
this.dataError = false;
this.statusColor = this.translations['t_statusColorSuccess'];
this.statusText = this.translations['t_statusNameOnline'];
this.statusName = this.translations['t_statusNameOnline'];
this.data = await this.ajaxCall('/api/apcupsd/service/getUpsStatus');
if (!this.data) {
$(`.${this.id}-chart-container`).html(`
<a href="/system_advanced_misc.php">${this.translations.t_unconfigured}</a>
`).css('margin', '2em auto')
this.dataError = true;
this.statusColor = this.translations['t_statusColorDanger'];
this.statusText = this.translations['t_statusTextError'];
this.statusName = this.translations['t_statusNameOffline'];
}
if (this.data.status === null) {
this.dataError = true;
this.statusColor = this.translations['t_statusColorDanger'];
this.statusText = this.translations['t_statusTextOffline'];
this.statusName = this.translations['t_statusNameOffline'];
}
else
{
this.statusName = this.data['status']['MODEL']['value'];
}
let rows = [];
let upsStatusLight = `<div>
<i class="fa fa-circle text-muted ${this.statusColor} ups-status-icon" style="font-size: 11px; cursor: pointer;"
data-toggle="tooltip" title=${this.statusText}>
</i>
${this.statusName}
</div>`
rows.push([upsStatusLight, '']);
if (this.dataError) {
rows.push([this.translations['t_unable_to_connect'], this.data['error']]);
}
else {
rows.push([this.translations['t_mode'], this.data['status']['UPSMODE']['value']]);
rows.push([this.translations['t_status'], this.data['status']['STATUS']['value']]);
rows.push([this.translations['t_battery_runtime'], this.data['status']['TIMELEFT']['value']]);
rows.push([this.translations['t_load'], this.data['status']['LOADPCT']['value']]);
rows.push([this.translations['t_int_temp'], this.data['status']['ITEMP']['value']]);
}
super.updateTable('apcupsd-table', rows);
}
}
/usr/local/opnsense/www/js/widgets/Metadata/Apcupsd.xml
<metadata>
<Apcupsd>
<filename>Apcupsd.js</filename>
<endpoints>
<endpoint>/api/Apcupsd/getUpsStatus</endpoint>
</endpoints>
<translations>
<title>APC UPS Status</title>
<t_unconfigured>APC UPS is not available or not configured.</t_unconfigured>
<t_statusColorSuccess>text-success</t_statusColorSuccess>
<t_statusColorWarning>text-warning</t_statusColorWarning>
<t_statusColorDanger>text-danger</t_statusColorDanger>
<t_statusTextWaiting>Waiting</t_statusTextWaiting>
<t_statusTextOffline>Offline</t_statusTextOffline>
<t_statusTextError>Data fetch error</t_statusTextError>
<t_statusNameOffline>Offline</t_statusNameOffline>
<t_statusNameOnline>Online</t_statusNameOnline>
<t_mode>Mode</t_mode>
<t_status>Status</t_status>
<t_battery_runtime>Battery Runtime</t_battery_runtime>
<t_load>Load</t_load>
<t_int_temp>Internal Temperature</t_int_temp>
<t_unable_to_connect>Unable to connect</t_unable_to_connect>
</translations>
</Apcupsd>
</metadata>
Quote from: mickgotwings on August 02, 2024, 03:43:05 PM
Could anyone say something on the new widgets support (>24.7)?
I updated my instance a few days ago and the widget is gone. Turns out you need a new kind of widget now.
Does this plugin even get support still? The latest commit was 2 years ago.
Could we maybe all contribute a little?
I'm a web dev, I could make the UI work, though I have no idea of how to develop opnsense plugins.
/usr/local/opnsense/scripts/OPNsense/Apcupsd
-rwxr-xr-x 1 root wheel 366 Jun 20 16:16 getNisStatus.py*
-rwxr-xr-x 1 root wheel 206 Jun 20 16:24 getServiceStatus.py*
root@firewall:/usr/local/opnsense/scripts/OPNsense/Apcupsd #
configctl apcupsd getNisStatus
root@firewall:/usr/local/etc/inc/plugins.inc.d # ll apcupsd.inc
-rw-r--r-- 1 root wheel 2358 Jun 20 18:25 apcupsd.inc
$ telnet 10.2.1.2 80
Trying 10.2.1.2...
Connected to 10.2.1.2.
Escape character is '^]'.
HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=utf-8
Content-Length: 110
Connection: close
<html><head><title>400 Bad Request</title></head><body><center><h1>400 Bad Request</h1></center></body></html>Connection closed by foreign host.
MODEM_ACCESS Jan 23 14:45:57 10.2.1.1:33765 10.2.1.2:80 tcp let out anything from firewall host itself
> telnet 10.2.1.2 80
Trying 10.2.1.2...
telnet: Unable to connect to remote host: Connection timed out
MODEM_ACCESS <- Jan 23 15:09:57 10.1.1.30:47270 10.2.1.2:80 tcp let out anything from firewall host itself
>ping 10.2.1.2
PING 10.2.1.2 (10.2.1.2) 56(84) bytes of data.
MODEM_ACCESS <- Jan 23 14:54:19 10.1.1.30 10.2.1.2 icmp let out anything from firewall host itself
lan -> Jan 23 14:54:19 10.1.1.30 10.2.1.2 icmp Allow ping ICMP traffic around the internal network