Commit version 24.12.13800

This commit is contained in:
2025-01-06 17:35:06 -05:00
parent b7f6a79c2c
commit 55d9218816
6133 changed files with 4239740 additions and 1374287 deletions

View File

@ -4,174 +4,172 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
$prt_supplies = snmpwalk_cache_oid($device, 'prtMarkerSuppliesTable', array(), 'Printer-MIB', NULL, OBS_SNMP_ALL_UTF8);
$prt_colorant = snmpwalk_cache_twopart_oid($device, 'prtMarkerColorantTable', array(), 'Printer-MIB', NULL, OBS_SNMP_ALL_UTF8);
$prt_supplies = snmpwalk_cache_oid($device, 'prtMarkerSuppliesTable', [], 'Printer-MIB', NULL, OBS_SNMP_ALL_UTF8);
$prt_colorant = snmpwalk_cache_twopart_oid($device, 'prtMarkerColorantTable', [], 'Printer-MIB', NULL, OBS_SNMP_ALL_UTF8);
print_debug_vars($prt_supplies);
print_debug_vars($prt_colorant);
// Count toner/ink, if Toner not has colorant table or name non informative (ie: TK-340) set to black for single toner
$toner_count = 0;
foreach ($prt_supplies as $entry)
{
switch ($entry['prtMarkerSuppliesType'])
{
case 'toner':
case 'tonerCartridge':
case 'ink':
case 'inkCartridge':
$toner_count++;
break;
}
foreach ($prt_supplies as $entry) {
switch ($entry['prtMarkerSuppliesType']) {
case 'toner':
case 'tonerCartridge':
case 'ink':
case 'inkCartridge':
$toner_count++;
break;
}
}
foreach ($prt_supplies as $index => $entry) {
// prtMarkerSuppliesMarkerIndex.1.1 = 1
// prtMarkerSuppliesMarkerIndex.1.8 = 1
// prtMarkerSuppliesMarkerIndex.1.9 = 1
// prtMarkerSuppliesColorantIndex.1.1 = 1
// prtMarkerSuppliesColorantIndex.1.8 = 4
// prtMarkerSuppliesColorantIndex.1.9 = 0
// prtMarkerSuppliesClass.1.1 = supplyThatIsConsumed
// prtMarkerSuppliesClass.1.8 = supplyThatIsConsumed
// prtMarkerSuppliesClass.1.9 = receptacleThatIsFilled
// prtMarkerSuppliesType.1.1 = toner
// prtMarkerSuppliesType.1.8 = opc
// prtMarkerSuppliesType.1.9 = wasteToner
// prtMarkerSuppliesDescription.1.1 = "Cyan Toner Cartridge"
// prtMarkerSuppliesDescription.1.8 = "Black Drum Cartridge"
// prtMarkerSuppliesDescription.1.9 = "Waste Toner Box"
// prtMarkerSuppliesSupplyUnit.1.1 = impressions
// prtMarkerSuppliesSupplyUnit.1.8 = impressions
// prtMarkerSuppliesSupplyUnit.1.9 = impressions
// prtMarkerSuppliesMaxCapacity.1.1 = 12000
// prtMarkerSuppliesMaxCapacity.1.8 = 50000
// prtMarkerSuppliesMaxCapacity.1.9 = 25000
// prtMarkerSuppliesLevel.1.1 = 12000
// prtMarkerSuppliesLevel.1.8 = 20000
// prtMarkerSuppliesLevel.1.9 = 25000
// prtMarkerSuppliesMarkerIndex.1.1 = 1
// prtMarkerSuppliesMarkerIndex.1.8 = 1
// prtMarkerSuppliesMarkerIndex.1.9 = 1
// prtMarkerSuppliesColorantIndex.1.1 = 1
// prtMarkerSuppliesColorantIndex.1.8 = 4
// prtMarkerSuppliesColorantIndex.1.9 = 0
// prtMarkerSuppliesClass.1.1 = supplyThatIsConsumed
// prtMarkerSuppliesClass.1.8 = supplyThatIsConsumed
// prtMarkerSuppliesClass.1.9 = receptacleThatIsFilled
// prtMarkerSuppliesType.1.1 = toner
// prtMarkerSuppliesType.1.8 = opc
// prtMarkerSuppliesType.1.9 = wasteToner
// prtMarkerSuppliesDescription.1.1 = "Cyan Toner Cartridge"
// prtMarkerSuppliesDescription.1.8 = "Black Drum Cartridge"
// prtMarkerSuppliesDescription.1.9 = "Waste Toner Box"
// prtMarkerSuppliesSupplyUnit.1.1 = impressions
// prtMarkerSuppliesSupplyUnit.1.8 = impressions
// prtMarkerSuppliesSupplyUnit.1.9 = impressions
// prtMarkerSuppliesMaxCapacity.1.1 = 12000
// prtMarkerSuppliesMaxCapacity.1.8 = 50000
// prtMarkerSuppliesMaxCapacity.1.9 = 25000
// prtMarkerSuppliesLevel.1.1 = 12000
// prtMarkerSuppliesLevel.1.8 = 20000
// prtMarkerSuppliesLevel.1.9 = 25000
// prtMarkerColorantMarkerIndex.1.1 = 1
// prtMarkerColorantRole.1.1 = process
// prtMarkerColorantValue.1.1 = "cyan"
// prtMarkerColorantTonality.1.1 = 256
// prtMarkerColorantMarkerIndex.1.1 = 1
// prtMarkerColorantRole.1.1 = process
// prtMarkerColorantValue.1.1 = "cyan"
// prtMarkerColorantTonality.1.1 = 256
//$descr = snmp_hexstring($entry['prtMarkerSuppliesDescription']); // Some HPs return a Hex-string.
$descr = rewrite_entity_name($entry['prtMarkerSuppliesDescription']); // Forced ASCII
$oid = ".1.3.6.1.2.1.43.11.1.1.9.$index";
$capacity_oid = ".1.3.6.1.2.1.43.11.1.1.8.$index";
//$descr = snmp_hexstring($entry['prtMarkerSuppliesDescription']); // Some HPs return a Hex-string.
$descr = rewrite_entity_name($entry['prtMarkerSuppliesDescription']); // Forced ASCII
$oid = ".1.3.6.1.2.1.43.11.1.1.9.$index";
$capacity_oid = ".1.3.6.1.2.1.43.11.1.1.8.$index";
/* .1.3.6.1.2.1.43.11.1.1.8 prtMarkerSuppliesMaxCapacity
* The value (-1) means other and specifically indicates that the sub-unit places
* no restrictions on this parameter. The value (-2) means unknown.
*
* .1.3.6.1.2.1.43.11.1.1.9 prtMarkerSuppliesLevel
* The value (-1) means other and specifically indicates that the sub-unit places
* no restrictions on this parameter. The value (-2) means unknown.
* A value of (-3) means that the printer knows that there is some supply/remaining space,
* respectively.
*/
/* .1.3.6.1.2.1.43.11.1.1.8 prtMarkerSuppliesMaxCapacity
* The value (-1) means other and specifically indicates that the sub-unit places
* no restrictions on this parameter. The value (-2) means unknown.
*
* .1.3.6.1.2.1.43.11.1.1.9 prtMarkerSuppliesLevel
* The value (-1) means other and specifically indicates that the sub-unit places
* no restrictions on this parameter. The value (-2) means unknown.
* A value of (-3) means that the printer knows that there is some supply/remaining space,
* respectively.
*/
$level = $entry['prtMarkerSuppliesLevel'];
$capacity = $entry['prtMarkerSuppliesMaxCapacity'];
$level = $entry['prtMarkerSuppliesLevel'];
$capacity = $entry['prtMarkerSuppliesMaxCapacity'];
if (($level < 0 || $capacity < 0) && is_device_mib($device, 'RicohPrivateMIB')) {
// Skip unknown toners on ricoh printers (use self mib)
continue;
}
if ($level == '-1' || $capacity == '-1') {
// Unlimited
$level = 100;
$capacity = 100;
}
if ($capacity > 0 && $level >= 0) {
$level = percent($level, $capacity, FALSE);
}
switch ($entry['prtMarkerSuppliesSupplyUnit']) {
// other(1), unknown(2), tenThousandthsOfInches(3), micrometers(4),
// impressions(7), sheets(8), hours(11), thousandthsOfOunces(12),
// tenthsOfGrams(13), hundrethsOfFluidOunces(14), tenthsOfMilliliters(15),
// feet(16), meters(17),
// -- Values for Finisher MIB
// items(18), percent(19)
default:
$unit = 'percent';
}
$update_array = [
'description' => $descr,
'index' => $index,
'oid' => $oid,
'mib' => 'jetdirect', // FIXME - this confuses, use correct mib name in the future
//'mib' => $mib,
'unit' => $unit,
'level' => $level,
'capacity' => $capacity,
'capacity_oid' => $capacity_oid
];
// Attach Colorant entry if exist
list($hrDeviceIndex, $prtMarkerSuppliesIndex) = explode('.', $index);
if (isset($entry['prtMarkerSuppliesColorantIndex']) &&
isset($prt_colorant[$hrDeviceIndex][$entry['prtMarkerSuppliesColorantIndex']])) {
$entry = array_merge($entry, $prt_colorant[$hrDeviceIndex][$entry['prtMarkerSuppliesColorantIndex']]);
if (isset($entry['prtMarkerColorantValue'])) {
//$update_array['colour'] = snmp_hexstring($entry['prtMarkerColorantValue']);
$update_array['colour'] = $entry['prtMarkerColorantValue']; // Forced ASCII
if (($level < 0 || $capacity < 0) && is_device_mib($device, 'RicohPrivateMIB')) {
// Skip unknown toners on ricoh printers (use self mib)
continue;
}
}
// Colorant table empty, try detect colour by description
if (!isset($update_array['colour'])) {
foreach ($GLOBALS['config']['toner'] as $colour => $strings) {
if (str_icontains_array($descr, (array)$strings)) {
$update_array['colour'] = $colour;
break;
}
if ($level == '-1' || $capacity == '-1') {
// Unlimited
$level = 100;
$capacity = 100;
}
}
switch ($entry['prtMarkerSuppliesType']) {
case 'toner':
case 'tonerCartridge':
case 'ink':
case 'inkCartridge':
if (!isset($update_array['colour']) && $toner_count === 1) {
$update_array['colour'] = 'black';
}
$update_array['type'] = str_replace('Cartridge', '', $entry['prtMarkerSuppliesType']);
break;
case 'opc':
// photo conductor
$update_array['type'] = 'drum';
break;
case 'wasteToner':
case 'wasteInk':
case 'transferUnit':
case 'cleanerUnit':
case 'fuser':
case 'developer':
case 'other':
// Known types
$update_array['type'] = strtolower($entry['prtMarkerSuppliesType']);
break;
default:
print_debug("Could not handle resource type " . $entry['prtMarkerSuppliesType']);
continue 2;
}
if ($capacity > 0 && $level >= 0) {
$level = percent($level, $capacity, FALSE);
}
// Skip duplicate toners, see: https://jira.observium.org/browse/OBS-3971
$update_array['skip_if_valid_exist'] = $update_array['type'].'->RicohPrivateMIB';
switch ($entry['prtMarkerSuppliesSupplyUnit']) {
// other(1), unknown(2), tenThousandthsOfInches(3), micrometers(4),
// impressions(7), sheets(8), hours(11), thousandthsOfOunces(12),
// tenthsOfGrams(13), hundrethsOfFluidOunces(14), tenthsOfMilliliters(15),
// feet(16), meters(17),
// -- Values for Finisher MIB
// items(18), percent(19)
default:
$unit = 'percent';
}
$update_array = [
'description' => $descr,
'index' => $index,
'oid' => $oid,
'mib' => 'jetdirect', // FIXME - this confuses, use correct mib name in the future
//'mib' => $mib,
'unit' => $unit,
'level' => $level,
'capacity' => $capacity,
'capacity_oid' => $capacity_oid
];
discover_printersupply($device, $update_array);
// Attach Colorant entry if exist
[$hrDeviceIndex, $prtMarkerSuppliesIndex] = explode('.', $index);
if (isset($entry['prtMarkerSuppliesColorantIndex']) &&
isset($prt_colorant[$hrDeviceIndex][$entry['prtMarkerSuppliesColorantIndex']])) {
$entry = array_merge($entry, $prt_colorant[$hrDeviceIndex][$entry['prtMarkerSuppliesColorantIndex']]);
if (isset($entry['prtMarkerColorantValue'])) {
//$update_array['colour'] = snmp_hexstring($entry['prtMarkerColorantValue']);
$update_array['colour'] = $entry['prtMarkerColorantValue']; // Forced ASCII
}
}
// Colorant table empty, try detect colour by description
if (!isset($update_array['colour'])) {
foreach ($GLOBALS['config']['toner'] as $colour => $strings) {
if (str_icontains_array($descr, (array)$strings)) {
$update_array['colour'] = $colour;
break;
}
}
}
switch ($entry['prtMarkerSuppliesType']) {
case 'toner':
case 'tonerCartridge':
case 'ink':
case 'inkCartridge':
if (!isset($update_array['colour']) && $toner_count === 1) {
$update_array['colour'] = 'black';
}
$update_array['type'] = str_replace('Cartridge', '', $entry['prtMarkerSuppliesType']);
break;
case 'opc':
// photo conductor
$update_array['type'] = 'drum';
break;
case 'wasteToner':
case 'wasteInk':
case 'transferUnit':
case 'cleanerUnit':
case 'fuser':
case 'developer':
case 'other':
// Known types
$update_array['type'] = strtolower($entry['prtMarkerSuppliesType']);
break;
default:
print_debug("Could not handle resource type " . $entry['prtMarkerSuppliesType']);
continue 2;
}
// Skip duplicate toners, see: https://jira.observium.org/browse/OBS-3971
$update_array['skip_if_valid_exist'] = $update_array['type'] . '->RicohPrivateMIB';
discover_printersupply($device, $update_array);
}
echo(PHP_EOL);

View File

@ -4,14 +4,14 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
//$prt_supplies = snmpwalk_oid_num($device, '.1.3.6.1.4.1.367.3.2.1.2.24.1.1', array(), 'RicohPrivateMIB');
$prt_supplies = snmpwalk_oid_num($device, 'ricohEngTonerName', array(), 'RicohPrivateMIB');
$prt_supplies = snmpwalk_oid_num($device, 'ricohEngTonerName', [], 'RicohPrivateMIB');
//$prt_supplies = snmpwalk_oid_num($device, 'ricohEngTonerDescr', $prt_supplies, 'RicohPrivateMIB');
$prt_supplies = snmpwalk_oid_num($device, 'ricohEngTonerType', $prt_supplies, 'RicohPrivateMIB');
$prt_supplies = snmpwalk_oid_num($device, 'ricohEngTonerLevel', $prt_supplies, 'RicohPrivateMIB');
@ -19,58 +19,58 @@ print_debug_vars($prt_supplies);
foreach ($prt_supplies as $index => $entry) {
$oid_num = ".1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.$index";
$update_array = array('description' => $entry['ricohEngTonerName'],
'index' => $index,
'oid' => $oid_num,
'mib' => $mib,
'unit' => 'percent',
'type' => 'toner',
'level' => $entry['ricohEngTonerLevel'],
'capacity' => 100);
$oid_num = ".1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.$index";
$update_array = ['description' => $entry['ricohEngTonerName'],
'index' => $index,
'oid' => $oid_num,
'mib' => $mib,
'unit' => 'percent',
'type' => 'toner',
'level' => $entry['ricohEngTonerLevel'],
'capacity' => 100];
if ($entry['ricohEngTonerLevel'] == '-100') {
// Toner near empty
$update_array['level'] = '5'; // ~ 1-20%
} elseif ($entry['ricohEngTonerLevel'] == '-3') {
$update_array['level'] = '80'; // ~ 10-100%
} elseif ($entry['ricohEngTonerLevel'] < '0') {
// Skip all other
continue;
}
if ($entry['ricohEngTonerLevel'] == '-100') {
// Toner near empty
$update_array['level'] = '5'; // ~ 1-20%
} elseif ($entry['ricohEngTonerLevel'] == '-3') {
$update_array['level'] = '80'; // ~ 10-100%
} elseif ($entry['ricohEngTonerLevel'] < '0') {
// Skip all other
continue;
}
if (str_icontains_array($entry['ricohEngTonerName'], 'Ink')) {
$update_array['type'] = 'ink';
}
if (str_icontains_array($entry['ricohEngTonerName'], 'Ink')) {
$update_array['type'] = 'ink';
}
switch ($entry['ricohEngTonerType']) {
case '3':
case 'blackTonerMono':
$update_array['colour'] = 'black';
break;
case '4':
case 'redTonerMono':
$update_array['colour'] = 'red';
break;
case '10':
case 'cyanToner4Color':
$update_array['colour'] = 'cyan';
break;
case '11':
case 'magentaToner4Color':
$update_array['colour'] = 'magenta';
break;
case '12':
case 'yellowToner4Color':
$update_array['colour'] = 'yellow';
break;
case '13':
case 'blackToner4Color':
$update_array['colour'] = 'black';
break;
}
switch ($entry['ricohEngTonerType']) {
case '3':
case 'blackTonerMono':
$update_array['colour'] = 'black';
break;
case '4':
case 'redTonerMono':
$update_array['colour'] = 'red';
break;
case '10':
case 'cyanToner4Color':
$update_array['colour'] = 'cyan';
break;
case '11':
case 'magentaToner4Color':
$update_array['colour'] = 'magenta';
break;
case '12':
case 'yellowToner4Color':
$update_array['colour'] = 'yellow';
break;
case '13':
case 'blackToner4Color':
$update_array['colour'] = 'black';
break;
}
discover_printersupply($device, $update_array);
discover_printersupply($device, $update_array);
}
echo(PHP_EOL);