cis-bv/netbox-client
Composer 安装命令:
composer require cis-bv/netbox-client
包简介
NetBox Client with supporting of GraphQl
README 文档
README
This is a simple fluent-based PHP client for the NetBox API.
Installation
composer require cis-bv/netbox-client
Create Client-Instance
The URL (with or without /api) and the NetBox-Token can either be provided directly by passing to the Class Constructor or via (OS-provided) Environment-Variables:
use Cis\NetBox\NetBoxApi; // direct passing $netBoxApi = new NetBoxApi('https://demo.netbox.dev', '3d7d31797de934a99a527a620514130980937b4c'); // using the Environment-Variables (OS or set) putenv(NETBOX_API_URL, 'https://demo.netbox.dev'); putenv(NETBOX_TOKEN, '3d7d31797de934a99a527a620514130980937b4c'); $netBoxApi = new NetBoxApi();
API
All API-calls are made fluently and are based on the URL of the endpoint. For Hypen-based paths you need to convert it to camelCase:
For retrieving data you omit the "Get"-Method. All filters ar passed in an array:
use Cis\NetBox\NetBoxApi; $netBoxApi = new NetBoxApi(); // Getting all Console-Ports $consolePorts = $netBoxApi->dcim()->consolePorts(); // Getting all Console-Ports for a specific device $consolePorts = $netBoxApi->dcim()->consolePorts(['device_id' => 12]);
For all Non-Get-Operations add the necessary Method to the End of the function name:
Createfor adding ModelsPutorPatchfor updating ModelsDeletefor deleting Models
// Creating a new Console Port $consolePorts = $netBoxApi->dcim()->consolePortsCreate([ 'device' => 245, 'name' => 'con' ]);
For Referencing a direct instance of a Model you need to add ById between the path and method and also reference the ID as the first parameter:
use Cis\NetBox\NetBoxApi; $netBoxApi = new NetBoxApi(); //Get a specific Interface: $netBoxApi->dcim()->interfacesById(12); //Delete a specific Console Port: $netBoxApi->dcim()->consolePortsByIdDelete(234);
GraphQL
To perform a GraphQL query you simply passing an Instance of the Cis\GqlBuilder\Query-Class or a simple string with the query.
use Cis\NetBox\NetBoxApi; use Cis\GqlBuilder\Query; $netBoxApi = new NetBoxApi(); $query = Query::create('device_list', selectionSet: ['id', 'name']); $allDevices = $netBoxApi->graphQl($query);
Return
All Functions return either an NetBoxResult or NetBoxGraphQlResult in case of a GraphQL-Query.
You can iterate over NetBoxResult and use it as Array, even if it is just on instance of a model.
It also holds additional information about the request:
use Cis\NetBox\NetBoxApi; $netBoxApi = new NetBoxApi(); $consolePorts = $netBoxApi->dcim()->consolePorts(); //Retrieve the status code of the request $statusCode = $consolePorts->getStatusCode(); //Retrieve the plain Body $body = $consolePorts->getBody(); //Retrieve the Result(s) always as array: $results = $consolePorts->getResults(); //Use Result as Array foreach ($consolePorts as $consolePort) { echo $consolePort->id . PHP_EOL; }
cis-bv/netbox-client 适用场景与选型建议
cis-bv/netbox-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 cis-bv/netbox-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cis-bv/netbox-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-21