From fa05f66eb2416212dfa382b25666cee5ce66aa10 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Wed, 28 Jan 2026 11:18:25 +0100 Subject: [PATCH 1/9] Feat(Format): handle PDU --- inventory.schema.json | 31 +++++++++++++++++++-- lib/php/Converter.php | 1 + tests/Glpi/Inventory/tests/units/Schema.php | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/inventory.schema.json b/inventory.schema.json index 222cb4d..6101bbc 100644 --- a/inventory.schema.json +++ b/inventory.schema.json @@ -2838,7 +2838,7 @@ }, "type": { "type": "string", - "pattern": "^(Unmanaged|Computer|Networking|Printer|Storage|Power|Phone|Video|KVM)$" + "pattern": "^(Unmanaged|Computer|Networking|Printer|Storage|Power|Phone|Video|KVM|Pdu)$" }, "uptime": { "type": "string", @@ -2850,6 +2850,33 @@ "Cisco" ] }, + "pdu": { + "type": "object", + "title": "Power Distribution Unit inventory", + "properties": { + "type": { + "type": "string", + "title": "PDU type" + }, + "plugs": { + "title": "List of plugs of pdu", + "type": "array", + "items": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, "contact": { "type": "string" }, @@ -2967,7 +2994,7 @@ "type": "string", "title": "Item type", "default": "Unmanaged", - "pattern": "^(Unmanaged|Computer|Phone|NetworkEquipment|Printer)$" + "pattern": "^(Unmanaged|Computer|Phone|NetworkEquipment|Printer|Pdu)$" }, "partial": { "type": "boolean", diff --git a/lib/php/Converter.php b/lib/php/Converter.php index 470b607..6b6b037 100644 --- a/lib/php/Converter.php +++ b/lib/php/Converter.php @@ -1303,6 +1303,7 @@ public function convertNetworkInventory(array $data): array case 'Phone': case 'Printer': case 'Unmanaged': + case 'Pdu': $itemtype = $device_info['type']; break; case 'Networking': diff --git a/tests/Glpi/Inventory/tests/units/Schema.php b/tests/Glpi/Inventory/tests/units/Schema.php index bda21a5..103ee7d 100644 --- a/tests/Glpi/Inventory/tests/units/Schema.php +++ b/tests/Glpi/Inventory/tests/units/Schema.php @@ -51,7 +51,7 @@ public function testValidateUnknownItemtype(): void $json = json_decode(json_encode(['deviceid' => 'myid', 'itemtype' => $itemtype, 'content' => ['versionclient' => 'GLPI-Agent_v1.0', 'hardware' => ['name' => 'my inventory']]])); $instance = new \Glpi\Inventory\Schema(); $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('\\\\Glpi\\\\Custom\\\\Asset\\\\Mine" does not match to ^(Unmanaged|Computer|Phone|NetworkEquipment|Printer)$'); + $this->expectExceptionMessage('\\\\Glpi\\\\Custom\\\\Asset\\\\Mine" does not match to ^(Unmanaged|Computer|Phone|NetworkEquipment|Printer|Pdu)$'); $this->assertFalse($instance->validate($json)); } From a0a400ce97f2eecd0ec7ad68b53bf90afacef392 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Thu, 29 Jan 2026 16:01:24 +0100 Subject: [PATCH 2/9] fix --- inventory.schema.json | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/inventory.schema.json b/inventory.schema.json index 6101bbc..93fdf55 100644 --- a/inventory.schema.json +++ b/inventory.schema.json @@ -2850,33 +2850,33 @@ "Cisco" ] }, - "pdu": { - "type": "object", - "title": "Power Distribution Unit inventory", - "properties": { - "type": { - "type": "string", - "title": "PDU type" - }, - "plugs": { - "title": "List of plugs of pdu", - "type": "array", - "items": { - "type": "object", - "required": [ - "name" - ], - "properties": { - "name": { - "type": "string" - } - } + "pdu": { + "type": "object", + "title": "Power Distribution Unit inventory", + "properties": { + "type": { + "type": "string", + "title": "PDU type" }, - "additionalProperties": false - } + "plugs": { + "title": "List of plugs of pdu", + "type": "array", + "items": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false }, - "additionalProperties": false - }, "contact": { "type": "string" }, From 6e78bef126a28ca6baf1af31c3272515d5738357 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Thu, 29 Jan 2026 16:04:17 +0100 Subject: [PATCH 3/9] fix --- lib/php/Converter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/php/Converter.php b/lib/php/Converter.php index 6b6b037..3a347d5 100644 --- a/lib/php/Converter.php +++ b/lib/php/Converter.php @@ -1436,6 +1436,7 @@ public function convertNetworkInventory(array $data): array case "pagecounters": case "drives": case "error": + case "pdu": $data['content'][$key] = $device_data; break; default: From 66393edd7ef19e15b7911a0c8e3230daed0f20d2 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Thu, 29 Jan 2026 16:22:12 +0100 Subject: [PATCH 4/9] fix schema --- inventory.schema.json | 54 +++++++++++++++++++++---------------------- lib/php/Converter.php | 4 ++-- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/inventory.schema.json b/inventory.schema.json index 93fdf55..a02b44f 100644 --- a/inventory.schema.json +++ b/inventory.schema.json @@ -2850,33 +2850,6 @@ "Cisco" ] }, - "pdu": { - "type": "object", - "title": "Power Distribution Unit inventory", - "properties": { - "type": { - "type": "string", - "title": "PDU type" - }, - "plugs": { - "title": "List of plugs of pdu", - "type": "array", - "items": { - "type": "object", - "required": [ - "name" - ], - "properties": { - "name": { - "type": "string" - } - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, "contact": { "type": "string" }, @@ -2885,6 +2858,33 @@ } } }, + "pdu": { + "type": "object", + "title": "Power Distribution Unit inventory", + "properties": { + "type": { + "type": "string", + "title": "PDU type" + }, + "plugs": { + "title": "List of plugs of pdu", + "type": "array", + "items": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, "databases_services": { "type": "array", "items": { diff --git a/lib/php/Converter.php b/lib/php/Converter.php index 3a347d5..c36725e 100644 --- a/lib/php/Converter.php +++ b/lib/php/Converter.php @@ -352,7 +352,7 @@ private function convertTo01(array $data): array 'remote_mgmt', 'cartridges', 'cameras', - 'user' + 'user', ]; foreach ($arrays as $array) { @@ -366,7 +366,7 @@ private function convertTo01(array $data): array 'versionprovider/comments', 'cameras/resolution', 'cameras/imageformats', - 'cameras/resolutionvideo' + 'cameras/resolutionvideo', ]; foreach ($sub_arrays as $array) { From 16fb1e5940f820c867a7aef85cfc806f784168ad Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Thu, 29 Jan 2026 16:23:21 +0100 Subject: [PATCH 5/9] revert useless change --- lib/php/Converter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/php/Converter.php b/lib/php/Converter.php index c36725e..3a347d5 100644 --- a/lib/php/Converter.php +++ b/lib/php/Converter.php @@ -352,7 +352,7 @@ private function convertTo01(array $data): array 'remote_mgmt', 'cartridges', 'cameras', - 'user', + 'user' ]; foreach ($arrays as $array) { @@ -366,7 +366,7 @@ private function convertTo01(array $data): array 'versionprovider/comments', 'cameras/resolution', 'cameras/imageformats', - 'cameras/resolutionvideo', + 'cameras/resolutionvideo' ]; foreach ($sub_arrays as $array) { From 8ad7a348038299bbad56d3f8d9e6cb1757f53df3 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Tue, 10 Feb 2026 15:52:31 +0100 Subject: [PATCH 6/9] implement orther fields --- inventory.schema.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/inventory.schema.json b/inventory.schema.json index a02b44f..760a18d 100644 --- a/inventory.schema.json +++ b/inventory.schema.json @@ -2876,7 +2876,16 @@ ], "properties": { "name": { - "type": "string" + "type": "string", + "title": "Plug name" + }, + "number": { + "type": "string", + "title": "Plug number" + }, + "type": { + "type": "string", + "title": "Plug type" } } }, From bbf648d22bd44af2cd68f54c16a5604c2f056c3f Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Tue, 10 Feb 2026 16:00:44 +0100 Subject: [PATCH 7/9] set as number --- inventory.schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inventory.schema.json b/inventory.schema.json index 760a18d..0f5ca21 100644 --- a/inventory.schema.json +++ b/inventory.schema.json @@ -2880,7 +2880,7 @@ "title": "Plug name" }, "number": { - "type": "string", + "type": "integer", "title": "Plug number" }, "type": { From 6257281105b36aa7e37563a6ae408733d8eba71b Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Thu, 12 Feb 2026 10:44:51 +0100 Subject: [PATCH 8/9] fix schema and converter --- inventory.schema.json | 64 +++++++++++++++++++++---------------------- lib/php/Converter.php | 4 ++- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/inventory.schema.json b/inventory.schema.json index 0f5ca21..62236b2 100644 --- a/inventory.schema.json +++ b/inventory.schema.json @@ -2855,44 +2855,44 @@ }, "credentials": { "type": "integer" - } - } - }, - "pdu": { - "type": "object", - "title": "Power Distribution Unit inventory", - "properties": { - "type": { - "type": "string", - "title": "PDU type" }, - "plugs": { - "title": "List of plugs of pdu", - "type": "array", - "items": { - "type": "object", - "required": [ - "name" - ], - "properties": { - "name": { - "type": "string", - "title": "Plug name" - }, - "number": { - "type": "integer", - "title": "Plug number" + "pdu": { + "type": "object", + "title": "Power Distribution Unit inventory", + "properties": { + "type": { + "type": "string", + "title": "PDU type" + }, + "plugs": { + "title": "List of plugs of pdu", + "type": "array", + "items": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "title": "Plug name" + }, + "number": { + "type": "integer", + "title": "Plug number" + }, + "type": { + "type": "string", + "title": "Plug type" + } + } }, - "type": { - "type": "string", - "title": "Plug type" - } + "additionalProperties": false } }, "additionalProperties": false } - }, - "additionalProperties": false + } }, "databases_services": { "type": "array", diff --git a/lib/php/Converter.php b/lib/php/Converter.php index 3a347d5..7103419 100644 --- a/lib/php/Converter.php +++ b/lib/php/Converter.php @@ -1436,9 +1436,11 @@ public function convertNetworkInventory(array $data): array case "pagecounters": case "drives": case "error": - case "pdu": $data['content'][$key] = $device_data; break; + case "pdu": + // put pdu into network_device + $data['content']['network_device'][$key] = $device_data; default: throw new RuntimeException('Key ' . $key . ' is not handled in network devices conversion'); } From 521e05a317b1d9f08a4396ba567418365d706130 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Thu, 12 Feb 2026 11:52:55 +0100 Subject: [PATCH 9/9] fix CS --- lib/php/Converter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/php/Converter.php b/lib/php/Converter.php index 7103419..4f9d759 100644 --- a/lib/php/Converter.php +++ b/lib/php/Converter.php @@ -1438,9 +1438,10 @@ public function convertNetworkInventory(array $data): array case "error": $data['content'][$key] = $device_data; break; - case "pdu": + case "pdu": // put pdu into network_device $data['content']['network_device'][$key] = $device_data; + break; default: throw new RuntimeException('Key ' . $key . ' is not handled in network devices conversion'); }