diff --git a/CHANGELOG.md b/CHANGELOG.md index f1165af..7a3ac51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ Phase 1 (NVIDIA through SNMP extend), first version 0.1.0. Not yet run on GPU ha ### Upgrade notes -- Schema version 3 adds the observation columns `ecc_corr_new`, `ecc_uncorr_new`, `retired_sbe`, `retired_dbe`, and `ecc_mode`. The upgrade runs when the Plugins page or a GPU page is opened. +- Schema version 3 adds the observation columns `ecc_corr_new`, `ecc_uncorr_new`, `retired_sbe`, `retired_dbe`, and `ecc_mode`. The upgrade runs when a signed-in user opens the Plugins page or a GPU page. - The metrics `extend` line now also asks for `ecc.mode.current`, `retired_pages.sbe`, and `retired_pages.dbe`. Update it on every node from [docs/node-setup.md](docs/node-setup.md); until then the node's collection fails with *Output rejected*. - Only on a node whose `nvidia-smi` is older than the clock event reasons rename, add the optional `cacti_gpu_legacy` extend line from the same page. A metrics line with the current field list that asks for `clocks_throttle_reasons.active` in the last position also works, because both names print the same bitmask there; a line with the earlier field list does not. - Re-import `templates/gpu_thold_templates.xml` in Thold to pick up template changes. Existing power threshold rows keep their stored settings after a template re-import; edit each existing power threshold or recreate it from the template to monitor the derived `power_pct` value. diff --git a/README.md b/README.md index 9077526..9e3f384 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ Out of scope: any command that changes a GPU or node (clocks, power limits, rese - **A collector after each poller cycle.** It reads each enabled node's agent, updates the identity records, and caches the latest sample. The script server input reads only that cache, so a Cacti poll never waits on a GPU node. - **Cacti objects** ([ADR 0010](docs/decisions/0010-attach-to-existing-node-devices.md)). The templates and the *GPU - Devices* data query ship as XML and are imported on install and upgrade. Saving a node attaches the data query to its existing device with reindex method None; GPU Nodes can create a device only when the node has none. Each GPU is an index keyed by vendor and UUID, with one data source shared by its Utilization, Memory, Temperature, Power, Power Percent, Clocks, Throttle, ECC Errors, New ECC Errors, Retired Pages, and Sample Age graphs. Every model field is drawn by some graph, because Cacti stores only the fields a graph uses. The plugin reindexes after every GPU change, keeps a reindex Cacti skipped while the device was Down or disabled and runs it once the device is Up, and creates graphs for new GPUs. - **History stays with the card.** An absent GPU stays an index, so its graphs show a gap and resume in the same RRD file when it returns. A replacement card in the same slot gets its own data source. **Remove from Data Query** on the node's page takes an absent GPU out of the listing; its RRD files and graphs are kept until you delete them. -- **Device permissions on GPU Nodes.** A GPU Admin sees, changes, exports, and moves only nodes and GPUs on devices they may see in Cacti; a GPU move needs both nodes. A node whose device was deleted can only be disabled. +- **Device permissions on GPU Nodes.** A GPU Admin sees, changes, exports, and moves only nodes and GPUs on devices they may see in Cacti; a GPU move needs both nodes. A node whose device was deleted can be disabled or deleted. - **The common metric model** ([ADR 0009](docs/decisions/0009-common-metric-core-with-vendor-extensions.md), [docs/metrics.md](docs/metrics.md)). Memory is in bytes, the clock event mask is decoded into `thr_*` indicators, and `age` is the age of the GPU's own sample time, or `U` when unknown. The installing (web server) user must be able to write `/resource/script_server/`, where the plugin places its data query XML; install and upgrade stop with a message otherwise and retry on the next attempt. Uninstall removes the templates and the XML only when *Remove the plugin's Cacti objects on uninstall* is checked, and never deletes RRD files, devices, graphs, or data sources ([docs/operations.md](docs/operations.md#uninstall)). Nodes on remote data collectors are not collected until phase 3. diff --git a/docs/i18n/ar-SA/README.md b/docs/i18n/ar-SA/README.md index 14aac4a..4d03305 100644 --- a/docs/i18n/ar-SA/README.md +++ b/docs/i18n/ar-SA/README.md @@ -1,4 +1,4 @@ - + [English](../../../README.md) | [简体中文](../zh-CN/README.md) | [हिन्दी](../hi-IN/README.md) | [Español (España)](../es-ES/README.md) | [Español (Latinoamérica)](../es-419/README.md) | [العربية](README.md) @@ -63,7 +63,7 @@ - **مجمّع بعد كل دورة مستطلع.** يقرأ وكيل كل عقدة مفعّلة ويحدّث سجلات الهوية ويخزّن آخر عينة مؤقتًا. يقرأ إدخال خادم السكربت هذه الذاكرة فقط، فلا ينتظر استطلاع Cacti عقدة GPU مطلقًا. - **كائنات Cacti** ([ADR 0010](../../decisions/0010-attach-to-existing-node-devices.md)). تُرفق القوالب واستعلام *GPU - Devices* كـXML وتُستورد عند التثبيت والترقية. يربط حفظ العقدة الاستعلام بجهازها الحالي بطريقة إعادة فهرسة None؛ ولا تستطيع عقد GPU إنشاء جهاز إلا إذا لم تملك العقدة جهازًا. كل GPU فهرس بمفتاح الشركة وUUID، مع مصدر بيانات واحد تشترك فيه رسوم الاستخدام والذاكرة والحرارة والطاقة ونسبة الطاقة والساعات وخفض التردد وأخطاء ECC وأخطاء ECC الجديدة والصفحات المتقاعدة وعمر العينة. يُرسم كل حقل نموذج في رسم ما، لأن Cacti لا يخزّن إلا حقولًا تستخدمها الرسوم. يعيد الملحق الفهرسة بعد كل تغيير GPU، ويحتفظ بإعادة فهرسة تخطاها Cacti حين كان الجهاز متوقفًا أو معطّلًا وينفذها عندما ينشط، وينشئ رسوم GPU الجديدة. - **يبقى التاريخ مع البطاقة.** تظل GPU الغائبة فهرسًا، فتظهر فجوة في رسومها وتستأنف في ملف RRD نفسه عند عودتها. تحصل البطاقة البديلة في الفتحة نفسها على مصدرها الخاص. يزيل **إزالة من استعلام البيانات** على صفحة العقدة GPU الغائبة من القائمة؛ تبقى ملفات RRD ورسومها حتى تحذفها. -- **صلاحيات الأجهزة في عقد GPU.** لا يرى GPU Admin ولا يغيّر ولا يصدّر ولا ينقل إلا عقد وGPU أجهزة يجوز له رؤيتها في Cacti؛ ويتطلب نقل GPU كلا العقدتين. العقدة التي حُذف جهازها لا يمكن إلا تعطيلها. +- **صلاحيات الأجهزة في عقد GPU.** لا يرى GPU Admin ولا يغيّر ولا يصدّر ولا ينقل إلا عقد وGPU أجهزة يجوز له رؤيتها في Cacti؛ ويتطلب نقل GPU كلا العقدتين. العقدة التي حُذف جهازها يمكن تعطيلها أو حذفها. - **نموذج المقاييس المشترك** ([ADR 0009](../../decisions/0009-common-metric-core-with-vendor-extensions.md)، [docs/metrics.md](docs/metrics.md)). الذاكرة بالبايت، ويُفك قناع أحداث الساعة إلى مؤشرات `thr_*`، و`age` عمر وقت العينة الخاصة بـGPU، أو `U` عند الجهل به. يجب أن يستطيع مستخدم التثبيت (خادم الويب) الكتابة إلى `/resource/script_server/` حيث يضع الملحق XML استعلام البيانات؛ وإلا يتوقف التثبيت والترقية برسالة ويعيدان المحاولة لاحقًا. لا تزيل الإزالة القوالب وXML إلا عند تحديد *إزالة كائنات Cacti الخاصة بالملحق عند الإزالة*، ولا تحذف ملفات RRD أو الأجهزة أو الرسوم أو مصادر البيانات مطلقًا ([docs/operations.md](docs/operations.md#uninstall)). لا تُجمع عقد المجمّعات البعيدة حتى المرحلة 3. diff --git a/docs/i18n/es-419/README.md b/docs/i18n/es-419/README.md index e01d48d..2c9c1f9 100644 --- a/docs/i18n/es-419/README.md +++ b/docs/i18n/es-419/README.md @@ -1,4 +1,4 @@ - + [English](../../../README.md) | [简体中文](../zh-CN/README.md) | [हिन्दी](../hi-IN/README.md) | [Español (España)](../es-ES/README.md) | [Español (Latinoamérica)](README.md) | [العربية](../ar-SA/README.md) @@ -63,7 +63,7 @@ Fuera de alcance: comandos que cambien una GPU o nodo (relojes, límites de pote - **Un recolector tras cada ciclo del sondeador.** Lee el agente de cada nodo habilitado, actualiza los registros de identidad y guarda la última muestra en caché. La entrada del servidor de scripts solo lee esa caché, por lo que un sondeo de Cacti nunca espera a un nodo GPU. - **Objetos Cacti** ([ADR 0010](../../decisions/0010-attach-to-existing-node-devices.md)). Las plantillas y la consulta *GPU - Devices* se distribuyen como XML y se importan al instalar y actualizar. Guardar un nodo vincula la consulta a su dispositivo existente con método de reindexación None; Nodos GPU solo puede crear un dispositivo si el nodo no tiene ninguno. Cada GPU es un índice por fabricante y UUID, con una fuente compartida por sus gráficos de Utilización, Memoria, Temperatura, Potencia, Porcentaje de potencia, Relojes, Limitación, Errores ECC, Errores ECC nuevos, Páginas retiradas y Antigüedad de muestra. Cada campo del modelo aparece en algún gráfico, porque Cacti solo guarda campos utilizados por gráficos. El plugin reindexa tras cada cambio de GPU, conserva una reindexación omitida por Cacti mientras el dispositivo estaba caído o desactivado y la ejecuta cuando vuelve a estar activo, y crea gráficos para GPU nuevas. - **El historial permanece con la tarjeta.** Una GPU ausente sigue siendo un índice, de modo que sus gráficos muestran un hueco y continúan en el mismo RRD cuando vuelve. Una tarjeta de sustitución en la misma ranura recibe su propia fuente. **Eliminar de la consulta de datos**, en la página del nodo, retira una GPU ausente de la lista; sus RRD y gráficos se conservan hasta que los borre. -- **Permisos de dispositivo en Nodos GPU.** GPU Admin solo ve, cambia, exporta y mueve nodos y GPU de dispositivos que puede ver en Cacti; un traslado de GPU requiere ambos nodos. Un nodo cuyo dispositivo se borró solo puede desactivarse. +- **Permisos de dispositivo en Nodos GPU.** GPU Admin solo ve, cambia, exporta y mueve nodos y GPU de dispositivos que puede ver en Cacti; un traslado de GPU requiere ambos nodos. Un nodo cuyo dispositivo se borró puede desactivarse o eliminarse. - **Modelo común de métricas** ([ADR 0009](../../decisions/0009-common-metric-core-with-vendor-extensions.md), [docs/metrics.md](docs/metrics.md)). La memoria está en bytes, la máscara de eventos de reloj se decodifica en indicadores `thr_*` y `age` es la antigüedad de la hora de muestra propia de la GPU, o `U` si se desconoce. El usuario que instala (servidor web) debe poder escribir en `/resource/script_server/`, donde el plugin coloca el XML de consulta; en caso contrario, instalación y actualización se detienen con un mensaje y reintentan la próxima vez. La desinstalación elimina plantillas y XML solo si se marca *Eliminar los objetos Cacti del plugin al desinstalar*, y nunca elimina RRD, dispositivos, gráficos ni fuentes de datos ([docs/operations.md](docs/operations.md#uninstall)). Los nodos de recolectores remotos no se recolectan hasta la fase 3. diff --git a/docs/i18n/es-ES/README.md b/docs/i18n/es-ES/README.md index 6127e21..67f053c 100644 --- a/docs/i18n/es-ES/README.md +++ b/docs/i18n/es-ES/README.md @@ -1,4 +1,4 @@ - + [English](../../../README.md) | [简体中文](../zh-CN/README.md) | [हिन्दी](../hi-IN/README.md) | [Español (España)](README.md) | [Español (Latinoamérica)](../es-419/README.md) | [العربية](../ar-SA/README.md) @@ -63,7 +63,7 @@ Fuera de alcance: comandos que cambien una GPU o nodo (relojes, límites de pote - **Un recolector tras cada ciclo del sondeador.** Lee el agente de cada nodo habilitado, actualiza los registros de identidad y guarda la última muestra en caché. La entrada del servidor de scripts solo lee esa caché, por lo que un sondeo de Cacti nunca espera a un nodo GPU. - **Objetos Cacti** ([ADR 0010](../../decisions/0010-attach-to-existing-node-devices.md)). Las plantillas y la consulta *GPU - Devices* se distribuyen como XML y se importan al instalar y actualizar. Guardar un nodo vincula la consulta a su dispositivo existente con método de reindexación None; Nodos GPU solo puede crear un dispositivo si el nodo no tiene ninguno. Cada GPU es un índice por fabricante y UUID, con una fuente compartida por sus gráficos de Utilización, Memoria, Temperatura, Potencia, Porcentaje de potencia, Relojes, Limitación, Errores ECC, Errores ECC nuevos, Páginas retiradas y Antigüedad de muestra. Cada campo del modelo aparece en algún gráfico, porque Cacti solo guarda campos utilizados por gráficos. El plugin reindexa tras cada cambio de GPU, conserva una reindexación omitida por Cacti mientras el dispositivo estaba caído o desactivado y la ejecuta cuando vuelve a estar activo, y crea gráficos para GPU nuevas. - **El historial permanece con la tarjeta.** Una GPU ausente sigue siendo un índice, de modo que sus gráficos muestran un hueco y continúan en el mismo RRD cuando vuelve. Una tarjeta de sustitución en la misma ranura recibe su propia fuente. **Eliminar de la consulta de datos**, en la página del nodo, retira una GPU ausente de la lista; sus RRD y gráficos se conservan hasta que los borre. -- **Permisos de dispositivo en Nodos GPU.** GPU Admin solo ve, cambia, exporta y mueve nodos y GPU de dispositivos que puede ver en Cacti; un traslado de GPU requiere ambos nodos. Un nodo cuyo dispositivo se borró solo puede desactivarse. +- **Permisos de dispositivo en Nodos GPU.** GPU Admin solo ve, cambia, exporta y mueve nodos y GPU de dispositivos que puede ver en Cacti; un traslado de GPU requiere ambos nodos. Un nodo cuyo dispositivo se borró puede desactivarse o eliminarse. - **Modelo común de métricas** ([ADR 0009](../../decisions/0009-common-metric-core-with-vendor-extensions.md), [docs/metrics.md](docs/metrics.md)). La memoria está en bytes, la máscara de eventos de reloj se decodifica en indicadores `thr_*` y `age` es la antigüedad de la hora de muestra propia de la GPU, o `U` si se desconoce. El usuario que instala (servidor web) debe poder escribir en `/resource/script_server/`, donde el plugin coloca el XML de consulta; en caso contrario, instalación y actualización se detienen con un mensaje y reintentan la próxima vez. La desinstalación elimina plantillas y XML solo si se marca *Eliminar los objetos Cacti del plugin al desinstalar*, y nunca elimina RRD, dispositivos, gráficos ni fuentes de datos ([docs/operations.md](docs/operations.md#uninstall)). Los nodos de recolectores remotos no se recogen hasta la fase 3. diff --git a/docs/i18n/hi-IN/README.md b/docs/i18n/hi-IN/README.md index 5b408cd..d9ee97e 100644 --- a/docs/i18n/hi-IN/README.md +++ b/docs/i18n/hi-IN/README.md @@ -1,4 +1,4 @@ - + [English](../../../README.md) | [简体中文](../zh-CN/README.md) | [हिन्दी](README.md) | [Español (España)](../es-ES/README.md) | [Español (Latinoamérica)](../es-419/README.md) | [العربية](../ar-SA/README.md) @@ -63,7 +63,7 @@ GPU नोड सामान्यतः CPU, मेमोरी और इं - **हर पोलर चक्र के बाद कलेक्टर।** हर सक्षम नोड का एजेंट पढ़ता है, पहचान रिकॉर्ड अपडेट करता है और नवीनतम नमूना कैश करता है। स्क्रिप्ट सर्वर इनपुट केवल कैश पढ़ता है, इसलिए Cacti पोल GPU नोड की प्रतीक्षा नहीं करता। - **Cacti ऑब्जेक्ट** ([ADR 0010](../../decisions/0010-attach-to-existing-node-devices.md))। टेम्पलेट और *GPU - Devices* डेटा क्वेरी XML रूप में शामिल हैं और इंस्टॉल तथा अपग्रेड पर आयात होते हैं। नोड सहेजने से डेटा क्वेरी मौजूदा डिवाइस पर रीइंडेक्स विधि None के साथ जुड़ती है; GPU नोड तभी डिवाइस बना सकता है जब नोड का कोई डिवाइस न हो। हर GPU विक्रेता और UUID की कुंजी वाला इंडेक्स है, जिसका एक डेटा स्रोत उपयोग, मेमोरी, तापमान, पावर, बिजली प्रतिशत, क्लॉक, थ्रॉटल, ECC त्रुटि, नई ECC त्रुटि, रिटायर पेज और नमूने की आयु ग्राफ़ साझा करते हैं। हर मॉडल फ़ील्ड किसी ग्राफ़ में है क्योंकि Cacti केवल ग्राफ़ द्वारा उपयोग फ़ील्ड रखता है। प्लगइन हर GPU बदलाव के बाद रीइंडेक्स करता है; डिवाइस Down या बंद होने से Cacti द्वारा छोड़ा रीइंडेक्स रखता और Up होने पर चलाता है; नए GPU के ग्राफ़ बनाता है। - **इतिहास कार्ड के साथ रहता है।** अनुपस्थित GPU इंडेक्स बना रहता है, इसलिए ग्राफ़ में अंतराल होता है और लौटने पर उसी RRD में जारी रहता है। उसी स्लॉट के नए कार्ड को अपना डेटा स्रोत मिलता है। नोड पृष्ठ का **डेटा क्वेरी से हटाएँ** अनुपस्थित GPU को सूची से हटाता है; RRD और ग्राफ़ आपके हटाने तक रहते हैं। -- **GPU नोड पर डिवाइस अनुमति।** GPU Admin केवल Cacti में देख सकने वाले डिवाइस के नोड और GPU देखता, बदलता, निर्यात तथा स्थानांतरित करता है; GPU स्थानांतरण में दोनों नोड की अनुमति चाहिए। जिसका डिवाइस हट गया वह नोड केवल बंद किया जा सकता है। +- **GPU नोड पर डिवाइस अनुमति।** GPU Admin केवल Cacti में देख सकने वाले डिवाइस के नोड और GPU देखता, बदलता, निर्यात तथा स्थानांतरित करता है; GPU स्थानांतरण में दोनों नोड की अनुमति चाहिए। जिसका डिवाइस हट गया वह नोड बंद या हटाया जा सकता है। - **सामान्य मेट्रिक मॉडल** ([ADR 0009](../../decisions/0009-common-metric-core-with-vendor-extensions.md), [docs/metrics.md](docs/metrics.md))। मेमोरी बाइट में है, क्लॉक इवेंट मास्क `thr_*` इंडिकेटर बनता है और `age` GPU के अपने नमूना समय की आयु है, अज्ञात हो तो `U`। इंस्टॉल करने वाला वेब सर्वर उपयोगकर्ता `/resource/script_server/` में लिख सके, जहाँ प्लगइन क्वेरी XML रखता है; नहीं तो इंस्टॉल और अपग्रेड संदेश देकर रुकते हैं और अगली कोशिश में फिर प्रयास करते हैं। अनइंस्टॉल टेम्पलेट और XML केवल *अनइंस्टॉल पर प्लगइन के Cacti ऑब्जेक्ट हटाएँ* चुने होने पर हटाता है, और RRD, डिवाइस, ग्राफ़ या डेटा स्रोत कभी नहीं हटाता ([docs/operations.md](docs/operations.md#uninstall))। दूरस्थ डेटा कलेक्टर के नोड चरण 3 तक संकलित नहीं होते। diff --git a/docs/i18n/zh-CN/README.md b/docs/i18n/zh-CN/README.md index 8893384..5059e21 100644 --- a/docs/i18n/zh-CN/README.md +++ b/docs/i18n/zh-CN/README.md @@ -1,4 +1,4 @@ - + [English](../../../README.md) | [简体中文](README.md) | [हिन्दी](../hi-IN/README.md) | [Español (España)](../es-ES/README.md) | [Español (Latinoamérica)](../es-419/README.md) | [العربية](../ar-SA/README.md) @@ -63,7 +63,7 @@ GPU 节点通常已在 Cacti 中监控 CPU、内存和接口。但 GPU 健康是 - **每个轮询器周期后的采集器。** 读取每个启用节点的代理,更新身份记录,缓存最新样本。脚本服务器输入只读取该缓存,因此 Cacti 轮询绝不等待 GPU 节点。 - **Cacti 对象**([ADR 0010](../../decisions/0010-attach-to-existing-node-devices.md))。模板和 *GPU - Devices* 数据查询以 XML 随附,在安装和升级时导入。保存节点时将数据查询附到其现有设备,重新索引方法设为 None;仅当节点没有设备时,GPU 节点页面才能创建设备。每 GPU 是按厂商和 UUID 建键的索引,共用一个数据源供利用率、内存、温度、功率、功率百分比、时钟、降频、ECC 错误、新增 ECC 错误、退役页面和样本年龄图表使用。每个模型字段均被某个图表绘制,因为 Cacti 只存储图表使用的字段。每次 GPU 变化后插件重新索引;设备 Down 或禁用时被 Cacti 跳过的重新索引会保留,在设备 Up 后执行,并为新 GPU 创建图表。 - **历史跟随卡。** 缺席 GPU 仍为索引,因此图表出现缺口,返回后在同一 RRD 文件中继续。同槽位的替换卡获得自己的数据源。节点页面上的 **从数据查询移除** 可将缺席 GPU 移出列表;其 RRD 文件和图表保留,直到您删除。 -- **GPU 节点的设备权限。** GPU Admin 只能查看、修改、导出和移动其在 Cacti 中有权查看设备上的节点及 GPU;GPU 移动需要两个节点的权限。设备已删除的节点只能禁用。 +- **GPU 节点的设备权限。** GPU Admin 只能查看、修改、导出和移动其在 Cacti 中有权查看设备上的节点及 GPU;GPU 移动需要两个节点的权限。设备已删除的节点可以禁用或删除。 - **通用指标模型**([ADR 0009](../../decisions/0009-common-metric-core-with-vendor-extensions.md)、[docs/metrics.md](docs/metrics.md))。内存以字节表示,时钟事件掩码解码为 `thr_*` 指示项,`age` 是 GPU 自身样本时间的年龄,未知时为 `U`。 执行安装的 Web 服务器用户必须能够写入 `/resource/script_server/`,插件在此放置数据查询 XML;否则安装和升级会显示消息并停止,下一次尝试时重试。仅当勾选 *卸载时移除插件的 Cacti 对象* 时,卸载才移除模板和 XML;绝不删除 RRD 文件、设备、图表或数据源([docs/operations.md](docs/operations.md#uninstall))。远程数据采集器上的节点要到阶段 3 才采集。 diff --git a/gpu_nodes.php b/gpu_nodes.php index 36f620c..549a23f 100644 --- a/gpu_nodes.php +++ b/gpu_nodes.php @@ -148,7 +148,7 @@ function gpu_nodes_attach(\Somethingwithproof\Gpu\Node $node): void { // A node whose device was deleted may be deleted too, by any GPU // Admin; see NodeAccess. - if (!$gpu_access->canRemove($gpu_node)) { + if ($gpu_node === null || !$gpu_access->canRemove($gpu_node)) { gpu_nodes_refuse(); } @@ -186,7 +186,7 @@ function gpu_nodes_attach(\Somethingwithproof\Gpu\Node $node): void { exit; case 'retire': $gpu_record = gpu_nodes_gpu($gpu_access, (int) get_filter_request_var('id'), false); - $gpu_user = isset($_SESSION[SESS_USER_ID]) ? (int) $_SESSION[SESS_USER_ID] : 0; + $gpu_user = is_numeric($_SESSION['sess_user_id'] ?? null) ? (int) $_SESSION['sess_user_id'] : 0; if ($gpu_gpus->retire($gpu_record->id, $gpu_record->nodeId, $gpu_user, $gpu_clock->now())) { $gpu_reindex->request($gpu_record->nodeId, 'GPU retired', $gpu_clock->now()); diff --git a/gpu_operator.php b/gpu_operator.php index 274b7fe..25d1955 100644 --- a/gpu_operator.php +++ b/gpu_operator.php @@ -28,14 +28,8 @@ } require_once('./plugins/gpu/include/operator.php'); -$user = (int) ($_SESSION['sess_user_id'] ?? 0); -$allowed = $user > 0 && api_plugin_user_realm_auth('gpu_operator.php'); - -if (!$allowed) { - http_response_code(403); - exit; -} -$actions = []; +// gpu_page_start() has checked the session and the Operator realm. +$user = is_numeric($_SESSION['sess_user_id'] ?? null) ? (int) $_SESSION['sess_user_id'] : 0; $action = (string) get_nfilter_request_var('action'); $session = $_SESSION['gpu_triage'] ?? []; $session = is_array($session) ? $session : []; @@ -46,8 +40,8 @@ $now = time(); if ($action !== '' && $action !== 'default') { - $method = $_SERVER['REQUEST_METHOD'] ?? ''; - $status = OperatorPage::actionStatus($allowed, $action, $method, $method === 'POST' && csrf_check(false), array_merge(['acknowledge'], array_keys($actions))); + $method = is_string($_SERVER['REQUEST_METHOD'] ?? null) ? $_SERVER['REQUEST_METHOD'] : ''; + $status = OperatorPage::actionStatus($user > 0, $action, $method, $method === 'POST' && csrf_check(false), ['acknowledge']); if ($status !== 200) { http_response_code($status); @@ -92,7 +86,7 @@ } top_header(); print '

' . html_escape(__('Monitoring view', 'gpu')) . '

'; - OperatorPage::render($rows, $session, $user, $now, $actions); + OperatorPage::render($rows, $session, $user, $now, []); bottom_footer(); } catch (Throwable $error) { cacti_log('Operator page failed (' . get_class($error) . ')', false, 'GPU'); diff --git a/include/operator.php b/include/operator.php index 6350f27..ff1a4cd 100644 --- a/include/operator.php +++ b/include/operator.php @@ -32,7 +32,7 @@ function gpu_operator_rows(): array { $rows[] = [ 'id' => (string) $node->id, 'name' => $node->description, - 'state' => $node->enabled() ? ($h->state->value ?? 'never') : 'disabled', + 'state' => $node->enabled() ? ($h?->state?->label() ?? __('Never', 'gpu')) : __('Disabled', 'gpu'), 'observed' => $h->finishedAt ?? 0, 'interval' => max(60, (int) read_config_option('poller_interval')), 'detail' => __('Compare sample age, ECC and throttle state on GPU Health with the device graphs. Escalate identity changes and node configuration to an administrator.', 'gpu') diff --git a/lib/NodesPage.php b/lib/NodesPage.php index d9460b4..33d6508 100644 --- a/lib/NodesPage.php +++ b/lib/NodesPage.php @@ -69,7 +69,7 @@ public function renderList(): void { . '' . html_escape($this->collection($statuses[$node->id] ?? null)) . '' . '' . ($counts[$node->id][Presence::Present->value] ?? 0) . '' . '' . ($counts[$node->id][Presence::Absent->value] ?? 0) . '' - . '' . ($this->access->canManage($node) ? $this->actionForm($node->id, 'delete', __('Delete', 'gpu')) : '') . '' + . '' . ($this->access->canRemove($node) ? $this->actionForm($node->id, 'delete', __('Delete', 'gpu')) : '') . '' . ''; } @@ -191,7 +191,13 @@ public function renderEdit(?Node $node, int $hostId = 0, ?bool $enabled = null, if ($node !== null && $this->access->canManage($node)) { $this->renderRetire($node); - } elseif ($canCreateDevice) { + } + + if ($node !== null && $this->access->canRemove($node)) { + print $this->actionForm($node->id, 'delete', __('Delete', 'gpu')); + } + + if ($canCreateDevice && ($node === null || !$this->access->canRemove($node))) { $this->renderCreateDevice(); } } diff --git a/locales/po/ar-SA.po b/locales/po/ar-SA.po index f1881af..55c53cc 100644 --- a/locales/po/ar-SA.po +++ b/locales/po/ar-SA.po @@ -106,6 +106,14 @@ msgstr "عرض المراقبة" msgid "Observations could not be read. Ask an administrator to check the plugin log." msgstr "تعذرت قراءة الملاحظات. اطلب من مسؤول مراجعة سجل الإضافة." +#: include/operator.php lib/HealthPage.php lib/NodesPage.php +msgid "Disabled" +msgstr "معطل" + +#: include/operator.php lib/InventoryPage.php lib/OperatorPage.php +msgid "Never" +msgstr "مطلقًا" + #: include/operator.php msgid "Compare sample age, ECC and throttle state on GPU Health with the device graphs. Escalate identity changes and node configuration to an administrator." msgstr "قارن عمر العينة وحالة ECC وخفض الأداء في GPU Health برسوم الجهاز. أحِل تغييرات الهوية وإعداد العقدة إلى مسؤول." @@ -283,10 +291,6 @@ msgstr "سلامة وحدات GPU" msgid "No GPUs recorded yet. GPUs appear here once a node's collection reports them." msgstr "لا توجد وحدات GPU مسجلة بعد. تظهر هنا عندما يبلغ جمع بيانات العقدة عنها." -#: lib/HealthPage.php lib/NodesPage.php -msgid "Disabled" -msgstr "معطل" - #: lib/HealthPage.php lib/NodesPage.php msgid "Enabled" msgstr "مفعّل" @@ -385,10 +389,6 @@ msgstr "رُصدت في %s، ولم يُؤكد النقل" msgid "seen at another node, move not confirmed" msgstr "رُصدت في عقدة أخرى، ولم يُؤكد النقل" -#: lib/InventoryPage.php lib/OperatorPage.php -msgid "Never" -msgstr "مطلقًا" - #: lib/NodesPage.php lib/Pages.php msgid "GPU Nodes" msgstr "عقد GPU" diff --git a/locales/po/cacti.pot b/locales/po/cacti.pot index 6bb00ca..3b6e12b 100644 --- a/locales/po/cacti.pot +++ b/locales/po/cacti.pot @@ -108,6 +108,14 @@ msgstr "" msgid "Observations could not be read. Ask an administrator to check the plugin log." msgstr "" +#: include/operator.php lib/HealthPage.php lib/NodesPage.php +msgid "Disabled" +msgstr "" + +#: include/operator.php lib/InventoryPage.php lib/OperatorPage.php +msgid "Never" +msgstr "" + #: include/operator.php msgid "Compare sample age, ECC and throttle state on GPU Health with the device graphs. Escalate identity changes and node configuration to an administrator." msgstr "" @@ -285,10 +293,6 @@ msgstr "" msgid "No GPUs recorded yet. GPUs appear here once a node's collection reports them." msgstr "" -#: lib/HealthPage.php lib/NodesPage.php -msgid "Disabled" -msgstr "" - #: lib/HealthPage.php lib/NodesPage.php msgid "Enabled" msgstr "" @@ -387,10 +391,6 @@ msgstr "" msgid "seen at another node, move not confirmed" msgstr "" -#: lib/InventoryPage.php lib/OperatorPage.php -msgid "Never" -msgstr "" - #: lib/NodesPage.php lib/Pages.php msgid "GPU Nodes" msgstr "" diff --git a/locales/po/es-419.po b/locales/po/es-419.po index 6e8483f..01a1106 100644 --- a/locales/po/es-419.po +++ b/locales/po/es-419.po @@ -106,6 +106,14 @@ msgstr "Vista de supervisión" msgid "Observations could not be read. Ask an administrator to check the plugin log." msgstr "No se pudieron leer las observaciones. Pida a un administrador que revise el registro del complemento." +#: include/operator.php lib/HealthPage.php lib/NodesPage.php +msgid "Disabled" +msgstr "Desactivado" + +#: include/operator.php lib/InventoryPage.php lib/OperatorPage.php +msgid "Never" +msgstr "Nunca" + #: include/operator.php msgid "Compare sample age, ECC and throttle state on GPU Health with the device graphs. Escalate identity changes and node configuration to an administrator." msgstr "Compare la antigüedad de las muestras, ECC y la limitación de rendimiento en GPU Health con los gráficos del dispositivo. Remita los cambios de identidad y la configuración de nodos a un administrador." @@ -283,10 +291,6 @@ msgstr "Estado de las GPU" msgid "No GPUs recorded yet. GPUs appear here once a node's collection reports them." msgstr "Todavía no hay GPU registradas. Aparecerán aquí cuando la recopilación de un nodo las detecte." -#: lib/HealthPage.php lib/NodesPage.php -msgid "Disabled" -msgstr "Desactivado" - #: lib/HealthPage.php lib/NodesPage.php msgid "Enabled" msgstr "Activado" @@ -385,10 +389,6 @@ msgstr "Detectada en %s; traslado sin confirmar" msgid "seen at another node, move not confirmed" msgstr "Detectada en otro nodo; traslado sin confirmar" -#: lib/InventoryPage.php lib/OperatorPage.php -msgid "Never" -msgstr "Nunca" - #: lib/NodesPage.php lib/Pages.php msgid "GPU Nodes" msgstr "Nodos GPU" diff --git a/locales/po/es-ES.po b/locales/po/es-ES.po index b634e4e..940c0cd 100644 --- a/locales/po/es-ES.po +++ b/locales/po/es-ES.po @@ -106,6 +106,14 @@ msgstr "Vista de supervisión" msgid "Observations could not be read. Ask an administrator to check the plugin log." msgstr "No se pudieron leer las observaciones. Pida a un administrador que revise el registro del complemento." +#: include/operator.php lib/HealthPage.php lib/NodesPage.php +msgid "Disabled" +msgstr "Desactivado" + +#: include/operator.php lib/InventoryPage.php lib/OperatorPage.php +msgid "Never" +msgstr "Nunca" + #: include/operator.php msgid "Compare sample age, ECC and throttle state on GPU Health with the device graphs. Escalate identity changes and node configuration to an administrator." msgstr "Compare la antigüedad de las muestras, ECC y la limitación de rendimiento en GPU Health con los gráficos del dispositivo. Remita los cambios de identidad y la configuración de nodos a un administrador." @@ -283,10 +291,6 @@ msgstr "Estado de las GPU" msgid "No GPUs recorded yet. GPUs appear here once a node's collection reports them." msgstr "Todavía no hay GPU registradas. Aparecerán aquí cuando la recopilación de un nodo las detecte." -#: lib/HealthPage.php lib/NodesPage.php -msgid "Disabled" -msgstr "Desactivado" - #: lib/HealthPage.php lib/NodesPage.php msgid "Enabled" msgstr "Activado" @@ -385,10 +389,6 @@ msgstr "Detectada en %s; traslado sin confirmar" msgid "seen at another node, move not confirmed" msgstr "Detectada en otro nodo; traslado sin confirmar" -#: lib/InventoryPage.php lib/OperatorPage.php -msgid "Never" -msgstr "Nunca" - #: lib/NodesPage.php lib/Pages.php msgid "GPU Nodes" msgstr "Nodos GPU" diff --git a/locales/po/hi-IN.po b/locales/po/hi-IN.po index 60f865c..49b9c39 100644 --- a/locales/po/hi-IN.po +++ b/locales/po/hi-IN.po @@ -106,6 +106,14 @@ msgstr "निगरानी दृश्य" msgid "Observations could not be read. Ask an administrator to check the plugin log." msgstr "अवलोकन पढ़े नहीं जा सके। प्रशासक से प्लगइन लॉग जाँचने को कहें।" +#: include/operator.php lib/HealthPage.php lib/NodesPage.php +msgid "Disabled" +msgstr "अक्षम" + +#: include/operator.php lib/InventoryPage.php lib/OperatorPage.php +msgid "Never" +msgstr "कभी नहीं" + #: include/operator.php msgid "Compare sample age, ECC and throttle state on GPU Health with the device graphs. Escalate identity changes and node configuration to an administrator." msgstr "GPU Health में नमूने की आयु, ECC और थ्रॉटल स्थिति की तुलना डिवाइस ग्राफ़ से करें। पहचान परिवर्तन और नोड कॉन्फ़िगरेशन के लिए प्रशासक से संपर्क करें।" @@ -283,10 +291,6 @@ msgstr "GPU स्वास्थ्य" msgid "No GPUs recorded yet. GPUs appear here once a node's collection reports them." msgstr "अभी कोई GPU रिकॉर्ड नहीं है। नोड के संग्रह में GPU मिलने पर वे यहाँ दिखाई देंगे।" -#: lib/HealthPage.php lib/NodesPage.php -msgid "Disabled" -msgstr "अक्षम" - #: lib/HealthPage.php lib/NodesPage.php msgid "Enabled" msgstr "सक्षम" @@ -385,10 +389,6 @@ msgstr "%s पर देखा गया, स्थानांतरण की msgid "seen at another node, move not confirmed" msgstr "दूसरे नोड पर देखा गया, स्थानांतरण की पुष्टि नहीं हुई" -#: lib/InventoryPage.php lib/OperatorPage.php -msgid "Never" -msgstr "कभी नहीं" - #: lib/NodesPage.php lib/Pages.php msgid "GPU Nodes" msgstr "GPU नोड" diff --git a/locales/po/zh-CN.po b/locales/po/zh-CN.po index 7f632d8..b2ad87a 100644 --- a/locales/po/zh-CN.po +++ b/locales/po/zh-CN.po @@ -106,6 +106,14 @@ msgstr "监控视图" msgid "Observations could not be read. Ask an administrator to check the plugin log." msgstr "无法读取观测结果。请联系管理员检查插件日志。" +#: include/operator.php lib/HealthPage.php lib/NodesPage.php +msgid "Disabled" +msgstr "已禁用" + +#: include/operator.php lib/InventoryPage.php lib/OperatorPage.php +msgid "Never" +msgstr "从未" + #: include/operator.php msgid "Compare sample age, ECC and throttle state on GPU Health with the device graphs. Escalate identity changes and node configuration to an administrator." msgstr "将 GPU 健康页面上的样本时效、ECC 和限频状态与设备图表进行比较。身份变更和节点配置请交由管理员处理。" @@ -283,10 +291,6 @@ msgstr "GPU 健康" msgid "No GPUs recorded yet. GPUs appear here once a node's collection reports them." msgstr "尚无 GPU 记录。节点采集报告 GPU 后会在此显示。" -#: lib/HealthPage.php lib/NodesPage.php -msgid "Disabled" -msgstr "已禁用" - #: lib/HealthPage.php lib/NodesPage.php msgid "Enabled" msgstr "已启用" @@ -385,10 +389,6 @@ msgstr "发现于 %s,移动尚未确认" msgid "seen at another node, move not confirmed" msgstr "发现于另一节点,移动尚未确认" -#: lib/InventoryPage.php lib/OperatorPage.php -msgid "Never" -msgstr "从未" - #: lib/NodesPage.php lib/Pages.php msgid "GPU Nodes" msgstr "GPU 节点" diff --git a/phpstan.neon b/phpstan.neon index c732e07..3fbd278 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -25,6 +25,12 @@ parameters: - setup.php - include/operator.php - include/unbooted-uninstall.php + - gpu_nodes.php + - gpu_operator.php + - gpu_health.php + - gpu_inventory.php + - poller_gpu.php + - ss_gpu.php scanDirectories: - %env.CACTI_PATH%/lib - %env.CACTI_PATH%/include @@ -37,3 +43,23 @@ parameters: - %env.CACTI_PATH%/include/js/* - %env.CACTI_PATH%/include/themes/* treatPhpDocTypesAsCertain: false + ignoreErrors: + # Cacti pages and CLI scripts chdir() to the Cacti root before + # including core files, so the relative paths resolve only at runtime. + - + identifiers: [include.fileNotFound, includeOnce.fileNotFound] + paths: [gpu_*.php] + - + identifier: requireOnce.fileNotFound + path: gpu_operator.php + - + identifier: require.fileNotFound + path: poller_gpu.php + # $config comes from core's cli_check.php. + - + identifier: variable.undefined + path: poller_gpu.php + # csrf-magic is in include/vendor, which is not scanned. + - + message: '#^Function csrf_check not found\.$#' + path: gpu_operator.php diff --git a/setup.php b/setup.php index ce1f94e..3343017 100644 --- a/setup.php +++ b/setup.php @@ -482,7 +482,16 @@ function gpu_config_arrays(): void { $menu[__('Management')]['plugins/gpu/' . $file] = $title; } - if (in_array(get_current_page(), \Somethingwithproof\Gpu\Pages::upgradeTriggers(), true)) { + // Cacti has not checked the session yet; a repair that keeps failing + // must not rerun, and log, on every anonymous request. A guest visit to + // graph_view.php leaves the guest ID in the session, so exclude it. + $sessionUser = $_SESSION['sess_user_id'] ?? 0; + + if ( + is_numeric($sessionUser) && (int) $sessionUser > 0 + && in_array(get_current_page(), \Somethingwithproof\Gpu\Pages::upgradeTriggers(), true) + && (int) $sessionUser !== (int) get_guest_account() + ) { plugin_gpu_upgrade(); } } diff --git a/ss_gpu.php b/ss_gpu.php index 5fc9e54..b12be40 100644 --- a/ss_gpu.php +++ b/ss_gpu.php @@ -32,18 +32,20 @@ include_once(__DIR__ . '/../../include/cli_check.php'); include_once(__DIR__ . '/setup.php'); + // Set by PHP for CLI scripts; PHPStan on PHP 8.5 does not know it here. + /** @var list $argv */ array_shift($argv); - print call_user_func_array('ss_gpu', $argv); + print ss_gpu(...$argv); } else { include_once(__DIR__ . '/setup.php'); } /** - * @param mixed $host_id - * @param mixed $cmd - * @param mixed $arg1 - * @param mixed $arg2 + * @param int|string $host_id + * @param int|string $cmd + * @param int|string $arg1 + * @param int|string $arg2 */ function ss_gpu($host_id = '', $cmd = '', $arg1 = '', $arg2 = ''): string { $fallback = $cmd === 'get' ? 'U' : ''; diff --git a/tests/Unit/InventoryPageTest.php b/tests/Unit/InventoryPageTest.php index cd76e8f..612c758 100644 --- a/tests/Unit/InventoryPageTest.php +++ b/tests/Unit/InventoryPageTest.php @@ -64,3 +64,39 @@ function page_node(int $id): Node { expect($html)->toContain('') ->and($html)->toContain(''); }); + +it('offers Delete for a node whose device was deleted, in the list and on the edit page', function () { + $GLOBALS['__gpu_db_rows'] = ['FROM plugin_gpu_node' => [ + ['id' => 4, 'host_id' => 101, 'admin_state' => 'enabled', 'description' => null, 'device_id' => null, 'created_at' => 1, 'updated_at' => 1], + ['id' => 5, 'host_id' => 5, 'admin_state' => 'enabled', 'description' => 'hidden device', 'device_id' => 5, 'created_at' => 1, 'updated_at' => 1], + ]]; + + $page = new NodesPage(new NodeRepository(false, new FixedClock(0)), new GpuRepository(false), new NodeAccess(fn (int $id): bool => false)); + + ob_start(); + $page->renderList(); + $list = (string) ob_get_clean(); + + ob_start(); + $page->renderEdit(new Node(4, 101, AdminState::Enabled, '', false, 0, 0)); + $edit = (string) ob_get_clean(); + + $GLOBALS['__gpu_db_rows'] = []; + + expect($list)->toContain('name="id" value="4"') + ->and($list)->toContain('value="Delete"') + ->and($list)->not->toContain('name="id" value="5"') + ->and($edit)->toContain('name="action" value="delete"'); +}); + +it('offers Delete on the edit page of a node the user may manage', function () { + $GLOBALS['__gpu_db_rows'] = []; + + $page = new NodesPage(new NodeRepository(false, new FixedClock(0)), new GpuRepository(false), new NodeAccess(fn (int $id): bool => true)); + + ob_start(); + $page->renderEdit(new Node(4, 101, AdminState::Enabled, '', true, 0, 0)); + $edit = (string) ob_get_clean(); + + expect($edit)->toContain('name="action" value="delete"'); +});