Files
cacti/scripts/ss_esxi_vhosts.php
3e1dc3c886 fix: replace strtolower/strtoupper with locale-independent wrappers (#6717)
* cleanup: remove unreachable defensive error logs in aggregate graph item validation

* fix: replace strtolower/strtoupper with locale-independent wrappers

PHP 8.5 deprecates locale-sensitive strtolower() and strtoupper().
Add cacti_strtolower() and cacti_strtoupper() wrappers that use
mb_strtolower/mb_strtoupper with explicit UTF-8 encoding, then
replace all 185 call sites across 65 files.

Existing mb_strtolower() calls (email normalization) are left as-is
since they already specify encoding explicitly.

Includes 18 Pest tests covering ASCII, UTF-8, protocol names, config
values, hex strings, NaN detection, and file extension patterns.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix: correct docblock references and month_shift() strpos check

Fix docblocks to reference strtolower()/strtoupper() (the deprecated
PHP builtins) instead of the wrapper names. Fix month_shift() to use
strpos() !== false instead of > 0 so 'month' at position 0 is matched.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* chore: drop unrelated lib/api_aggregate changes

Keep PR scope focused on the issue for this branch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: TheWitness <thewitness@cacti.net>
2026-03-05 19:51:02 -05:00

67 lines
1.9 KiB
PHP

<?php
include_once(__DIR__ . '/../include/cli_check.php');
include_once(__DIR__ . '/../lib/snmp.php');
if (!isset($called_by_script_server)) {
array_shift($_SERVER['argv']);
print call_user_func_array('ss_esxi_vhosts', $_SERVER['argv']);
}
function ss_esxi_vhosts(int $device_id) : string {
$host = db_fetch_row_prepared('SELECT *
FROM host
WHERE id = ?',
[$device_id]);
if (!cacti_sizeof($host)) {
return ("vh:0 vh_state:0 tools_run:0 tools_nrun:0 tools_ninst:0\n");
}
$hostname = $host['hostname'];
$community = $host['snmp_community'];
$port = $host['snmp_port'];
$timeout = $host['snmp_timeout'];
$oids = [
'vh' => '.1.3.6.1.4.1.6876.2.1.1.2',
'vh_state' => '.1.3.6.1.4.1.6876.2.1.1.6',
'vh_tools' => '.1.3.6.1.4.1.6876.2.1.1.4'
];
$vh_tools_run = 0;
$vh_state = 0;
$vh_tools_ninst = 0;
$vh_tools_run = 0;
$vh_tools_nrun = 0;
$array = cacti_snmp_walk($hostname, $community, $oids['vh_state'], 1, '', '', '', '', '', '', $port, $timeout, 2, 20, SNMP_POLLER);
$vhosts = cacti_count($array);
$array = cacti_snmp_walk($hostname, $community, $oids['vh_state'], 1, '','', '','', '', '', $port, $timeout, 2, 20, SNMP_POLLER);
if (cacti_sizeof($array)) {
foreach ($array as $key => $value) {
if (cacti_strtolower(trim($value['value'])) == 'powered on' || cacti_strtolower(trim($value['value'])) == 'poweredon') {
$vh_state++;
}
}
}
$array = cacti_snmp_walk($hostname, $community, $oids['vh_tools'], 1, '', '', '', '', '', '', $port, $timeout, 2, 20, SNMP_POLLER);
if (cacti_sizeof($array)) {
foreach ($array as $key => $value) {
if (str_contains($value['value'], 'not installed')) {
$vh_tools_ninst++;
} elseif (str_contains($value['value'], 'not running')) {
$vh_tools_nrun++;
} else {
$vh_tools_run++;
}
}
}
return ("vh:$vhosts vh_state:$vh_state tools_run:$vh_tools_run tools_nrun:$vh_tools_nrun tools_ninst:$vh_tools_ninst\n");
}