Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion net/vnstat/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PLUGIN_NAME= vnstat
PLUGIN_VERSION= 1.3
PLUGIN_REVISION= 1
PLUGIN_REVISION= 2
PLUGIN_COMMENT= Network traffic monitor
PLUGIN_DEPENDS= vnstat
PLUGIN_MAINTAINER= m.muenz@gmail.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,42 @@ public function yearlyAction()
return array("response" => $response);
}

/**
* list interfaces tracked by vnstat
* @return array
*/
public function dbiflistAction()
{
$backend = new Backend();
$response = trim($backend->configdRun("vnstat dbiflist"));
if (empty($response)) {
return array("interfaces" => array());
}
$interfaces = array_map('trim', explode("\n", $response));
$interfaces = array_values(array_filter($interfaces, function ($v) {
return !empty($v);
}));
return array("interfaces" => $interfaces);
}

/**
* retrieve vnstat data as structured JSON for a specific interface
* @return array
*/
public function jsonAction()
{
$iface = $this->request->get('iface');
if (empty($iface) || !preg_match('/^[a-zA-Z0-9_.]+$/', $iface)) {
return array("error" => "Invalid or missing interface name");
}
$backend = new Backend();
$response = json_decode($backend->configdRun("vnstat json " . escapeshellarg($iface)), true);
if ($response === null) {
return array("error" => "Failed to retrieve vnstat data");
}
return $response;
}

/**
* remove database folder
* @return array
Expand Down
12 changes: 12 additions & 0 deletions net/vnstat/src/opnsense/service/conf/actions.d/actions_vnstat.conf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ parameters:
type:script_output
message:request Vnstat yearly status

[dbiflist]
command:/usr/local/bin/vnstat --dbiflist 1
parameters:
type:script_output
message:request Vnstat interface list

[json]
command:/usr/local/bin/vnstat --json --iface %s
parameters:%s
type:script_output
message:request Vnstat json status

[resetdb]
command:rm -rf /var/lib/vnstat
parameters:
Expand Down
25 changes: 25 additions & 0 deletions net/vnstat/src/opnsense/www/js/widgets/Metadata/Vnstat.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<metadata>
<vnstat>
<filename>Vnstat.js</filename>
<endpoints>
<endpoint>/api/vnstat/service/dbiflist</endpoint>
<endpoint>/api/vnstat/service/json</endpoint>
</endpoints>
<translations>
<title>Vnstat Traffic</title>
<h_date>Date</h_date>
<h_rx>RX</h_rx>
<h_tx>TX</h_tx>
<h_total>Total</h_total>
<h_avg_rate>Avg Rate</h_avg_rate>
<period_hourly>Hourly</period_hourly>
<period_daily>Daily</period_daily>
<period_monthly>Monthly</period_monthly>
<period_yearly>Yearly</period_yearly>
<msg_no_data>No vnstat data available</msg_no_data>
<excluded_interfaces>Excluded Interfaces</excluded_interfaces>
<refresh_interval>Refresh Interval (minutes)</refresh_interval>
<show_avg_rate>Show Average Rate</show_avg_rate>
</translations>
</vnstat>
</metadata>
Loading