Skip to content

Commit

Permalink
fix: Fixed and improved toner discovery (librenms#8428)
Browse files Browse the repository at this point in the history
* fix: Fixed and improved toner discovery

* Update konica data
xerox tries to insert too long of descriptions.  Lets remove the part and serial number, they are ugly to look at in the ui.
  • Loading branch information
laf authored and TheMysteriousX committed May 20, 2018
1 parent 5aad260 commit de81d2b
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 35 deletions.
22 changes: 9 additions & 13 deletions includes/discovery/toner.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@

if ($device['os_group'] == 'printer') {
echo 'Toner: ';
$oids = snmpwalk_cache_oid($device, 'prtMarkerColorantMarkerIndex', array(), 'Printer-MIB');
if (empty($oids)) {
$oids = snmpwalk_cache_oid($device, 'prtMarkerSuppliesMarkerIndex', $oids, 'Printer-MIB');
}

$oids = snmpwalk_cache_oid($device, 'prtMarkerSuppliesLevel', $oids, 'Printer-MIB');
if (!empty($oids)) {
$oids = snmpwalk_cache_oid($device, 'prtMarkerSuppliesLevel', $oids, 'Printer-MIB');
$oids = snmpwalk_cache_oid($device, 'prtMarkerSuppliesMaxCapacity', $oids, 'Printer-MIB');
$oids = snmpwalk_cache_oid($device, 'prtMarkerSuppliesDescription', $oids, 'Printer-MIB', null, '-OQUsa');
$oids = snmpwalk_cache_oid($device, 'prtMarkerColorantValue', $oids, 'Printer-MIB', null, '-OQUsa');
}

foreach ($oids as $index => $data) {
$last_index = substr($index, strrpos($index, '.') + 1);

$raw_toner = $data['prtMarkerSuppliesLevel'];
$descr = $data['prtMarkerSuppliesDescription'];
$raw_capacity = $data['prtMarkerSuppliesMaxCapacity'];
Expand All @@ -31,17 +26,18 @@
$raw_toner = snmp_get($device, $toner_oid, '-Oqv');
}

if (empty($raw_toner)) {
$raw_toner = snmp_get($device, $toner_oid, '-Oqv');
}

if (empty($descr)) {
$descr_oid = ".1.3.6.1.4.1.367.3.2.1.2.24.1.1.3.$last_index";
$descr = snmp_get($device, $descr_oid, '-Oqva');
}

if (empty($raw_toner)) {
$raw_toner = snmp_get($device, $toner_oid, '-Oqv');
}

if (!empty($data['prtMarkerColorantValue'])) {
$descr = ucfirst($data['prtMarkerColorantValue']);
// trim part & serial number from devices that include it
if (str_contains($descr, ', PN')) {
$descr = explode(', PN', $descr)[0];
}

$type = 'jetdirect';
Expand Down
25 changes: 4 additions & 21 deletions tests/data/konica.json
Original file line number Diff line number Diff line change
Expand Up @@ -585,17 +585,15 @@
"discovery": {
"toner": [
{
"toner_id": "1",
"toner_index": "1",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.1",
"toner_descr": "Cyan",
"toner_descr": "Toner (Cyan)",
"toner_capacity": "100",
"toner_current": "29",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.1"
},
{
"toner_id": "10",
"toner_index": "10",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.10",
Expand All @@ -605,7 +603,6 @@
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.10"
},
{
"toner_id": "11",
"toner_index": "11",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.11",
Expand All @@ -615,7 +612,6 @@
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.11"
},
{
"toner_id": "12",
"toner_index": "12",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.12",
Expand All @@ -625,7 +621,6 @@
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.12"
},
{
"toner_id": "13",
"toner_index": "13",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.13",
Expand All @@ -635,7 +630,6 @@
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.13"
},
{
"toner_id": "14",
"toner_index": "14",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.14",
Expand All @@ -645,7 +639,6 @@
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.14"
},
{
"toner_id": "15",
"toner_index": "15",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.15",
Expand All @@ -655,7 +648,6 @@
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.15"
},
{
"toner_id": "16",
"toner_index": "16",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.16",
Expand All @@ -665,7 +657,6 @@
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.16"
},
{
"toner_id": "17",
"toner_index": "17",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.17",
Expand All @@ -675,37 +666,33 @@
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.17"
},
{
"toner_id": "2",
"toner_index": "2",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.2",
"toner_descr": "Magenta",
"toner_descr": "Toner (Magenta)",
"toner_capacity": "100",
"toner_current": "31",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.2"
},
{
"toner_id": "3",
"toner_index": "3",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.3",
"toner_descr": "Yellow",
"toner_descr": "Toner (Yellow)",
"toner_capacity": "100",
"toner_current": "58",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.3"
},
{
"toner_id": "4",
"toner_index": "4",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.4",
"toner_descr": "Black",
"toner_descr": "Toner (Black)",
"toner_capacity": "100",
"toner_current": "83",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.4"
},
{
"toner_id": "5",
"toner_index": "5",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.5",
Expand All @@ -715,7 +702,6 @@
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.5"
},
{
"toner_id": "6",
"toner_index": "6",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.6",
Expand All @@ -725,7 +711,6 @@
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.6"
},
{
"toner_id": "7",
"toner_index": "7",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.7",
Expand All @@ -735,7 +720,6 @@
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.7"
},
{
"toner_id": "8",
"toner_index": "8",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.8",
Expand All @@ -745,7 +729,6 @@
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.8"
},
{
"toner_id": "9",
"toner_index": "9",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.9",
Expand Down
155 changes: 155 additions & 0 deletions tests/data/xerox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"os": {
"discovery": {
"devices": [
{
"sysName": "<private>",
"sysObjectID": ".1.3.6.1.4.1.253.8.62.1.35.2.3.1.1",
"sysDescr": "Xerox AltaLink C8045; SS 100.002.057.09608, NC 100.002.09608, UI 100.002.09608, ME 063.022.000, CC 100.002.09608, DF 007.019.000, FI ------, FA 003.012.013, CCOS 100.007.09608, NCOS 100.007.09608, SC 013.014.002, SU 100.002.09608",
"sysContact": null,
"version": null,
"hardware": "",
"features": null,
"location": null,
"os": "xerox",
"type": "printer",
"serial": null,
"icon": "xerox.svg"
}
]
},
"poller": {
"devices": [
{
"sysName": "<private>",
"sysObjectID": ".1.3.6.1.4.1.253.8.62.1.35.2.3.1.1",
"sysDescr": "Xerox AltaLink C8045; SS 100.002.057.09608, NC 100.002.09608, UI 100.002.09608, ME 063.022.000, CC 100.002.09608, DF 007.019.000, FI ------, FA 003.012.013, CCOS 100.007.09608, NCOS 100.007.09608, SC 013.014.002, SU 100.002.09608",
"sysContact": "<private>",
"version": null,
"hardware": "Xerox AltaLink C8045",
"features": null,
"location": "<private>",
"os": "xerox",
"type": "printer",
"serial": null,
"icon": "xerox.svg"
}
]
}
},
"toner": {
"discovery": {
"toner": [
{
"toner_index": "1",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.1",
"toner_descr": "Black Toner",
"toner_capacity": "5300",
"toner_current": "20",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.1"
},
{
"toner_index": "10",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.10",
"toner_descr": "Waste Toner Container",
"toner_capacity": "100",
"toner_current": "5",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.10"
},
{
"toner_index": "11",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.11",
"toner_descr": "Transfer Belt Cleaner",
"toner_capacity": "100",
"toner_current": "65",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.11"
},
{
"toner_index": "12",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.12",
"toner_descr": "Second Bias Transfer Roll",
"toner_capacity": "100",
"toner_current": "86",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.12"
},
{
"toner_index": "2",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.2",
"toner_descr": "Cyan Toner",
"toner_capacity": "3000",
"toner_current": "66",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.2"
},
{
"toner_index": "3",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.3",
"toner_descr": "Magenta Toner",
"toner_capacity": "3000",
"toner_current": "72",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.3"
},
{
"toner_index": "4",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.4",
"toner_descr": "Yellow Toner",
"toner_capacity": "3050",
"toner_current": "60",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.4"
},
{
"toner_index": "5",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.5",
"toner_descr": "Drum Cartridge (R1)",
"toner_capacity": "100",
"toner_current": "50",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.5"
},
{
"toner_index": "6",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.6",
"toner_descr": "Drum Cartridge (R2)",
"toner_capacity": "100",
"toner_current": "92",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.6"
},
{
"toner_index": "7",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.7",
"toner_descr": "Drum Cartridge (R3)",
"toner_capacity": "100",
"toner_current": "93",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.7"
},
{
"toner_index": "8",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.8",
"toner_descr": "Drum Cartridge (R4)",
"toner_capacity": "100",
"toner_current": "93",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.8"
},
{
"toner_index": "9",
"toner_type": "jetdirect",
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.9",
"toner_descr": "Fuser",
"toner_capacity": "100",
"toner_current": "90",
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.9"
}
]
},
"poller": "matches discovery"
}
}
2 changes: 1 addition & 1 deletion tests/module_tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ storage:
excluded_fields: [device_id, storage_id]
toner:
toner:
excluded_fields: [device_id]
excluded_fields: [device_id, toner_id]
order_by: toner_oid, toner_index
wireless:
wireless_sensors:
Expand Down
Loading

0 comments on commit de81d2b

Please sign in to comment.