Skip to content
Merged
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ ChangeLog
* issue: Fix the Summary tab dropping the data-query graph links on PHP 8 because a device id of 0 was treated as a device filter
* security: Bind the stored sysObjectID and sysDescr patterns in the OS type rescan and limit the match to devices that are still unclassified
* security: Bind the SNMP index as a query parameter in the graph link builder used by the Summary Processes view
* issue: Fix the Graphs tab failing with a fatal error on Cacti 1.2.x, where the graph filter calls a function that core declares only in graph_view.php
* issue: Speed up the OS type rescan by trying each stored type once against all unclassified devices instead of once per stored type and per distinct reported sysObjectID and sysDescr pair
* issue: Fix the Fleet Dashboard Uptime Distribution showing all zeros by falling back to SNMP sysUpTime when the Host Resources hrSystemUptime is not reported, and apply the same fallback to the per-device Dashboard
* issue: Stop the Dashboard card header from changing height when hovering the drag handle or tool buttons by reserving space for the theme's button hover border
* feature: Make the Fleet Dashboard the first tab and the default landing view on the Host MIB interface
Expand Down
1 change: 1 addition & 0 deletions hmib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3868,6 +3868,7 @@ function hmib_view_graphs(): void {

include('./lib/timespan_settings.php');
include('./lib/html_graph.php');
require_once(__DIR__ . '/includes/compat.php');

html_graph_validate_preview_request_vars();

Expand Down
26 changes: 3 additions & 23 deletions hmib_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
chdir('../../');
include('./include/auth.php');
include_once('./lib/snmp.php');
require_once(__DIR__ . '/includes/types.php');

$host_types_actions = [
1 => __('Delete', 'hmib'),
Expand Down Expand Up @@ -544,30 +545,9 @@ function rescan_types(): void {
WHERE name='" . $new_name . "'
AND version='" . $new_version . "'");

// get all known devices types from the device type database
$known_types = db_fetch_assoc('SELECT id, sysDescrMatch, sysObjectID FROM plugin_hmib_hrSystemTypes');

// loop through all device rows and look for a matching type
// look for a matching type for the devices that have none
if (cacti_sizeof($unknown_host_types)) {
foreach ($unknown_host_types as $type) {
$found = false;

if (cacti_sizeof($known_types)) {
foreach ($known_types as $known) {
db_execute_prepared('UPDATE plugin_hmib_hrSystem SET host_type = ?
WHERE host_type = 0
AND sysObjectID LIKE ?
AND sysDescr LIKE ?',
[$known['id'], '%' . $known['sysObjectID'] . '%', '%' . $known['sysDescrMatch'] . '%']);

if (db_affected_rows() > 0) {
$found = true;

break;
}
}
}
}
hmib_assign_host_types();
}

// update the host types from unknown_host_types that have a value of 0
Expand Down
49 changes: 49 additions & 0 deletions includes/compat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/

/*
* Cacti 1.2.x builds the Graph Template filter in lib/html_graph.php with
* graph_view_has_untemplated_graphs(), but declares that function in
* graph_view.php, which a plugin page never loads. Declare the same function
* here when core has not, so html_graph_preview_filter() works on the Graphs
* tab. Cacti develop has no such function and does not call it.
*/
if (!function_exists('graph_view_has_untemplated_graphs')) {
/**
* Whether the current Device filter has at least one allowed graph that
* uses no Graph Template. Same contract as core's function of this name.
*
* @param string $templates_where The device restriction, or an empty string.
*
* @return bool True when an allowed untemplated graph exists.
*/
function graph_view_has_untemplated_graphs($templates_where = '') {
$sql_where = '(gl.graph_template_id = 0)' . ($templates_where != '' ? ' AND ' . $templates_where : '');
$total_rows = 0;

get_allowed_graphs($sql_where, '', '1', $total_rows);

return $total_rows > 0;
}
}
59 changes: 59 additions & 0 deletions includes/types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/

/**
* Assigns a host type to the devices that have none. The stored host types
* are tried in id order, one UPDATE each, and a device takes the first type
* whose sysObjectID and sysDescr patterns it matches as LIKE substrings.
* Only devices whose host_type is 0 are
* touched, so a device that has a type keeps it and a type that comes later
* cannot take over a device an earlier type has claimed.
*
* Called from rescan_types() when at least one device with a reported
* sysObjectID and sysDescr has no host type.
*
* @return void
*/
function hmib_assign_host_types(): void {
$known_types = db_fetch_assoc('SELECT id, sysDescrMatch, sysObjectID
FROM plugin_hmib_hrSystemTypes
ORDER BY id');

if (!cacti_sizeof($known_types)) {
return;
}

foreach ($known_types as $known) {
db_execute_prepared('UPDATE plugin_hmib_hrSystem
SET host_type = ?
WHERE host_type = 0
AND sysObjectID LIKE ?
AND sysDescr LIKE ?',
[
$known['id'],
'%' . $known['sysObjectID'] . '%',
'%' . $known['sysDescrMatch'] . '%'
]);
}
}
2 changes: 2 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<include>
<file>setup.php</file>
<file>includes/database.php</file>
<file>includes/compat.php</file>
<file>includes/types.php</file>
<file>associate_os_type.php</file>
</include>
</source>
Expand Down
4 changes: 0 additions & 4 deletions tests/E2E/DevicesPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ function hmib_e2e_links($body, $action) {
});

it('shows a user graphs of the selected devices on the Graphs tab', function () {
if (hmib_e2e_core_lacks_graph_filter()) {
$this->markTestSkipped('Cacti 1.2.x declares graph_view_has_untemplated_graphs() in graph_view.php only, so its graph filter cannot be used from a plugin page.');
}

$ids = hmib_fx_templates();

hmib_test_sql('INSERT INTO graph_local (id, host_id, snmp_query_id, snmp_index, graph_template_id) VALUES (604, 9001, ?, ?, ?)', array($ids['cpu_dq'], '1', $ids['users_gt']));
Expand Down
Loading