Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API
Please note: This project is not an official product by synetics GmbH. synetics GmbH doesn't provide any commercial support.
i-doit is a software application for IT documentation and a CMDB (Configuration Management Database). This application is very useful to collect all your knowledge about the IT infrastructure you are dealing with. i-doit is a Web application and has an exhausting API which is very useful to automate your infrastructure.
This API client library provides a simple, but powerful abstraction layer to send requests to i-doit's API. It is written in pure PHP.
Why should you use this API client library? There are some good reasons:
- Easy to use
- There is a PHP function for each API method
- Supports batch requests (much faster)
- Sends user-defined requests
- Uploads files and images
- Supports login and logout methods to save sessions
- Follows redirects (HTTP 301/302) automatically
- Uses optional HTTP or SOCKS5 proxy
- Verifies TLS certificate chains
- Throws exception on error
- Many examples
- Well-documented
- Easy to install via Composer
- Well-tested with tons of integration tests
What's new? Take a look at the changelog.
Meet these simple requirements before using the client:
- A running instance of i-doit pro/open, version
1.18.1
or higher (older versions may work but are not supported) - i-doit API add-on, version
1.12.3
or higher (older versions may work but are not supported) - PHP, version
8.0
or higher (8.1
is recommended,7.4
should work but is deprecated) - PHP modules
curl
,date
,json
,openssl
andzlib
As a rule of thumb, always use the latest stable releases to benefit from new features, improvements and bug fixes.
It is recommended to install this client via Composer. Change to your project's root directory and fetch the latest stable version:
composer require idoit/apiclient
Instead of sticking to a specific/minimum version you may switch to the current development branch by using @DEV
:
composer require "idoit/apiclient=@DEV"
Composer has the great advantage (besides many others) that you can simply update the API client library by running:
composer update
If you use Composer you should use its own autoloader, too:
require_once 'vendor/autoload.php';
This is it. All other files will be auto-loaded on-the-fly if needed.
The API client library class requires a configuration:
use Idoit\APIClient\API;
$api = new API([
API::URL => 'https://demo.i-doit.com/src/jsonrpc.php',
API::PORT => 443,
API::KEY => 'c1ia5q',
API::USERNAME => 'admin',
API::PASSWORD => 'admin',
API::LANGUAGE => 'en',
API::PROXY => [
API::PROXY_ACTIVE => false,
API::PROXY_TYPE => 'HTTP', // 'HTTP' or 'SOCKS5'
API::PROXY_HOST => 'proxy.example.net',
API::PROXY_PORT => 8080,
API::PROXY_USERNAME => '',
API::PROXY_PASSWORD => ''
],
API::BYPASS_SECURE_CONNECTION => false
]);
API::URL
: URL to i-doit's API, probably the base URL appended bysrc/jsonrpc.php
API::PORT
: optional port on which the Web server listens; if not set port 80 will be used for HTTP and 443 for HTTPSAPI::KEY
: API keyAPI::USERNAME
andAPI::PASSWORD
: optional credentials if needed, otherwiseSystem API
user will be usedAPI::LANGUAGE
: requests to and responses from i-doit will be translated to this language (de
anden
supported); this is optional; defaults to user's prefered languageAPI::PROXY
: use a proxy between client and serverAPI::PROXY_ACTIVE
: iftrue
proxy settings will be usedAPI::PROXY_TYPE
: use a HTTP (API::PROXY_TYPE_HTTP
) or a SOCKS5 (API::PROXY_TYPE_SOCKS5
) proxyAPI::PROXY_HOST
: FQDN or IP address to proxyAPI::PROXY_PORT
: port on which the proxy server listensAPI::PROXY_USERNAME
andAPI::PROXY_PASSWORD
: optional credentials used to authenticate against the proxy
API::BYPASS_SECURE_CONNECTION
: Set totrue
to disable security-related cURL options; defaults tofalse
; do not set this in production!
A basic "Hello, World!" example is to fetch some basic information about your i-doit instance:
use Idoit\APIClient\API;
use Idoit\APIClient\Idoit;
require_once 'vendor/autoload.php';
$api = new API([
API::URL => 'https://demo.i-doit.com/src/jsonrpc.php',
API::KEY => 'c1ia5q',
API::USERNAME => 'admin',
API::PASSWORD => 'admin'
]);
$request = new Idoit($api);
$info = $request->readVersion();
var_dump($info);
It is simple like that. For more examples take a look at the next sub sections.
One sweet thing about i-doit's API you can (and should) use one user session for your stuff. This saves resources on the server side and allows you to perform a lot more calls in a short time.
The session handling is done by the API client library. You just need to login. And if you are nice you want to logout after your work is done.
use Idoit\APIClient\API;
$api = new API([/* … */]);
$api->login();
// Do your stuff…
$api->logout();
If you are unsure in which condition your session is try isLoggedIn()
:
$api->isLoggedIn(); // Returns true or false
For almost every case there is a remote procedure you may call to read from or manipulate i-doit's database through its API. Each remote procedure is assigned to a namespace to keep the API clean and smoothly. Furtunately, you do not need to call these remote procedures on your own. The API client library provides for each namespace a class and for each remote procedure a method. Here is a quick overview:
Namespace | Remote Procedure Call (RPC) | Class in API Client Library | Method |
---|---|---|---|
idoit |
idoit.addons |
Idoit |
getAddOns() |
idoit.constants |
readConstants() |
||
idoit.license |
getLicense() |
||
idoit.search |
search() |
||
idoit.version |
readVersion() |
||
idoit.login |
API |
login() |
|
idoit.logout |
logout() |
||
cmdb.object |
cmdb.object.create |
CMDBObject |
create() |
cmdb.object.read |
read() |
||
cmdb.object.update |
update() |
||
cmdb.object.archive |
archive() |
||
cmdb.object.delete |
delete() |
||
cmdb.object.purge |
purge() |
||
cmdb.objects |
cmdb.objects.read |
CMDBObjects |
read() |
cmdb.category |
cmdb.category.create |
CMDBCategory |
create() |
cmdb.category.read |
read() , readOneByID() , readFirst() |
||
cmdb.category.update |
update() |
||
cmdb.category.save |
save() |
||
cmdb.category.archive |
archive() |
||
cmdb.category.delete |
delete() |
||
cmdb.category.purge |
purge() |
||
cmdb.category_info |
cmdb.category_info.read |
CMDBCategoryInfo |
read() |
cmdb.condition |
cmdb.condition.read |
CMDBCondition |
read() |
cmdb.dialog |
cmdb.dialog.create |
CMDBDialog |
create() |
cmdb.dialog.read |
read() |
||
cmdb.dialog.delete |
delete() |
||
cmdb.impact |
cmdb.impact.read |
CMDBImpact |
readByID() , readByConst() |
cmdb.location_tree |
cmdb.location_tree.read |
CMDBLocationTree |
read() , readRecursively() |
cmdb.logbook |
cmdb.logbook.create |
CMDBLogbook |
create() |
cmdb.logbook.read |
read() |
||
cmdb.objects_by_relation |
cmdb.objects_by_relation.read |
CMDBObjectsByRelation |
readByID() , readByConst() |
cmdb.object_type_categories |
cmdb.object_type_categories.read |
CMDBObjectTypeCategories |
readByID() , readByConst() |
cmdb.object_type_groups |
cmdb.object_type_groups.read |
CMDBObjectTypeGroups |
read() |
cmdb.object_types |
cmdb.object_types.read |
CMDBObjectTypes |
read() , readOne() , readByTitle() |
cmdb.reports |
cmdb.reports.read |
CMDBReports |
read() , listReports() |
cmdb.workstation_components |
cmdb.workstation_components.read |
CMDBWorkstationComponents |
read() , readByEMail() , readByEMails() |
checkmk.statictag |
checkmk.statictag.create |
CheckMKStaticTag |
create() |
checkmk.statictag.read |
read() , readByID() , readByIDs() , readByTag() |
||
checkmk.statictag.update |
update() |
||
checkmk.statictag.delete |
delete() |
||
checkmk.tags |
checkmk.tags.read |
CheckMKTags |
read() |
monitoring.livestatus |
monitoring.livestatus.create |
MonitoringLivestatus |
createTCPConnection , createUNIXSocketConnection |
monitoring.livestatus.read |
read() , readByID() , readByIDs() , readByTitle() |
||
monitoring.livestatus.update |
update() |
||
monitoring.livestatus.delete |
deleteByID() , deleteByTitle() |
Additionally, this API client library is shipped with methods as workarounds for remote procedure calls you probably miss. The RPC cmdb.objects.create
does not exist but you may use CMDBObjects::create()
. It simulates the missing RPC and gives you an easier and faster way to manipulate your CMDB.
If it makes sense there are methods to perform batch requests for most RPCs. For example, CMDBCategory::batchRead()
fetches multiple category entries at once.
use Idoit\APIClient\API;
use Idoit\APIClient\Idoit;
$api = new API([/* … */]);
$idoit = new Idoit($api);
$result = $idoit->search('Server XY');
var_dump($result);
Perform more than one search at once:
use Idoit\APIClient\API;
use Idoit\APIClient\Idoit;
$api = new API([/* … */]);
$idoit = new Idoit($api);
$result = $idoit->batchSearch([
'Server XY',
'Client A',
'John Doe'
]);
var_dump($result);
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBObject;
$api = new API([/* … */]);
$object = new CMDBObject($api);
$objectID = $object->create(
'C__OBJTYPE__SERVER',
'Server XY'
);
var_dump($objectID);
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBObject;
$api = new API([/* … */]);
$object = new CMDBObject($api);
$objectInfo = $object->read(42);
var_dump($objectInfo);
This will fetch everything about an object: common data, assigned categories and category entries as well.
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBObject;
$api = new API([/* … */]);
$object = new CMDBObject($api);
$objectInfo = $object->load(42);
var_dump($objectInfo);
The method load()
triggers round about 4 API calls. So be aware if it is heavily used.
Currently, you are able to update an object's title:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBObject;
$api = new API([/* … */]);
$object = new CMDBObject($api);
$object->update(
42,
[
'title' => 'A shiny new object title'
]
);
You you like to get an identifier of an object but you are unsure whether or not it exists, try an upsert. This is an "update" and an "insert" at the same time. This means, if the object exists you will get its identifier directly. If not the object will be created and then you will get its identifier. Objects must match against type and title. Additional attributes will be stored.
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBObject;
$api = new API([/* … */]);
$object = new CMDBObject($api);
$object->upsert(
'C__OBJTYPE__SERVER',
'My little server',
[
'purpose' => 'Private stuff'
]
);
Fetch an object identifier by object title and (optional) type:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBObjects;
$api = new API([/* … */]);
$object = new CMDBObjects($api);
$objectID = $object->getID('My little server');
$objectID = $object->getID('My little server', 'C__OBJTYPE__SERVER');
An exception error will be thrown if there is either no object or more than one.
i-doit has the concept of archiving your IT documentation. Each object has an status (normal
, archived
, marked as deleted
). And last but not least, an object may be purged from the database.
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBObject;
$api = new API([/* … */]);
$object = new CMDBObject($api);
$objectID = 42;
// Archive:
$object->archive($objectID);
// Mark as deleted:
$object->delete($objectID);
// Purge from database:
$object->purge($objectID);
Create multiple objects at once:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBObjects;
$api = new API([/* … */]);
$cmdbObjects = new CMDBObjects($api);
$objectIDs = $cmdbObjects->create(
[
['type' => 'C__OBJTYPE__SERVER', 'title' => 'Server No. One'],
['type' => 'C__OBJTYPE__SERVER', 'title' => 'Server No. Two'],
['type' => 'C__OBJTYPE__SERVER', 'title' => 'Server No. Three']
]
);
var_dump($objectIDs);
Reading multiple objects at once is provided by several methods. Let's see:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBObjects;
$api = new API([/* … */]);
$cmdbObjects = new CMDBObjects($api);
// Fetch every object:
$objects = $cmdbObjects->read();
var_dump($objects);
// Fetch max. 10 servers and sort them descending by title:
$objects = $cmdbObjects->read(['type' => 'C__OBJTYPE__SERVER'], 10, 0, 'title', CMDBObjects::SORT_DESCENDING);
var_dump($objects);
// Get them by their identifiers:
$objects = $cmdbObjects->readByIDs([1, 2, 3]);
var_dump($objects);
// Get all servers:
$objects = $cmdbObjects->readByType('C__OBJTYPE__SERVER');
var_dump($objects);
// Get archived clients:
$objects = $cmdbObjects->readArchived('C__OBJTYPE__CLIENT');
var_dump($objects);
// Get clients marked as deleted:
$objects = $cmdbObjects->readDeleted('C__OBJTYPE__CLIENT');
var_dump($objects);
Update multiple objects at once:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBObjects;
$api = new API([/* … */]);
$cmdbObjects = new CMDBObjects($api);
// Rename objects 1, 2, 3:
$cmdbObjects->update([
['id' => 1, 'title' => 'New name'],
['id' => 2, 'title' => 'Another name'],
['id' => 3, 'title' => 'Just a name'],
]);
Archive objects, mark them as deleted or even purge them from database:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBObjects;
$api = new API([/* … */]);
$cmdbObjects = new CMDBObjects($api);
$cmdbObjects
->archive([1, 2, 3])
->delete([1, 2, 3])
->purge([1, 2, 3]);
Allowed comparison are '=', '!=', 'like', 'not like', '>', '>=', '<', '<=', '<>'.
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBCondition;
$api = new API([/* … */]);
$condition = new CMDBCondition($api);
$result = $condition->read(
[
[
'property' => "C__CATG__ACCOUNTING-order_no",
'comparison' => "=",
'value' => "ORDER4711",
]
]
);
You can use more than one condition and add an operator to them. Allowed operators are 'AND' and 'OR'.
$result = $condition->read(
[
[
'property' => "C__CATG__ACCOUNTING-order_no",
'comparison' => "=",
'value' => "ORDER4711",
],
[
'property' => "C__CATG__ACCOUNTING-order_no",
'comparison' => "=",
'value' => "ORDER0815",
'operator' => 'OR',
]
]
);
For more readable code you can use the condition helper class.
use Idoit\APIClient\Condition;
$conditions = [
new Condition("C__CATG__ACCOUNTING", "order_no", "=", "ORDER4711"),
new Condition("C__CATG__ACCOUNTING", "order_no", "=", "ORDER4711", Condition::OR),
];
$result = $condition->read($conditions);
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBCategory;
$api = new API([/* … */]);
$category = new CMDBCategory($api);
$entryID = $this->category->save(
42,
'C__CATG__IP',
[
'net' => 123,
'active' => 1,
'primary' => 0,
'net_type' => 1,
'ipv4_assignment' => 2,
'ipv4_address' => '10.20.10.100',
'description' => 'API TEST'
]
);
var_dump($entryID);
Alternatively, use method CMDBCategory::batchCreate()
for batch requests.
Read one or more category entries for one specific object:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBCategory;
$api = new API([/* … */]);
$category = new CMDBCategory($api);
$result = $category->read(42, 'C__CATG__IP');
var_dump($result);
Read one specific categoy entry for one specific object:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBCategory;
$api = new API([/* … */]);
$category = new CMDBCategory($api);
$result = $category->readOneByID(42, 'C__CATG__IP', 23);
var_dump($result);
Read just one category entry (easier than read()
when using single-valued categories):
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBCategory;
$api = new API([/* … */]);
$category = new CMDBCategory($api);
$result = $category->readFirst(42, 'C__CATG__IP');
var_dump($result);
Read data for multiple objects and categories at once:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBCategory;
$api = new API([/* … */]);
$category = new CMDBCategory($api);
$result = $category->batchRead(
[23, 42],
['C__CATG__IP', 'C__CATG__MODEL']
);
var_dump($result);
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBCategory;
$api = new API([/* … */]);
$category = new CMDBCategory($api);
$category->save(
42,
'C__CATG__GLOBAL',
[
'cmdb_status' => 10
]
);
Alternatively, use method CMDBCategory::batchUpdate()
for batch requests.
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBCategory;
$api = new API([/* … */]);
$category = new CMDBCategory($api);
// Archive:
$category->archive(42, 'C__CATG__CPU', 1);
// Mark as deleted:
$category->delete(42, 'C__CATG__CPU', 2);
// Purge from database:
$category->purge(42, 'C__CATG__CPU', 3);
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBDialog;
$api = new API([/* … */]);
$dialog = new CMDBDialog($api);
$entryID = $dialog->create('C__CATG__MODEL', 'title', 'My model');
var_dump($entryID);
$entryIDs = $dialog->batchCreate([
'C__CATG__MODEL' => [
'manufacturer' => 'My manufacturer',
'title' => 'My model'
],
'C__CATG__GLOBAL' => [
'category' => [
'cat 1',
'cat 2',
'cat 3'
],
'purpose' => 'API TEST'
]
]);
var_dump($entryIDs);
Drop-down menus in i-doit are called "dialog" (read-only) or "dialog+" (editable).
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBDialog;
$api = new API([/* … */]);
$dialog = new CMDBDialog($api);
$models = $dialog->read('C__CATG__MODEL', 'title');
var_dump($models);
$modelsAndManufacturers = $dialog->batchRead([
'C__CATG__MODEL' => [
'manufacturer',
'title'
]
]);
var_dump($modelsAndManufacturers);
Read objects located directly under an object:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBLocationTree;
$api = new API([/* … */]);
$locationTree = new CMDBLocationTree($api);
$result = $locationTree->read(1);
var_dump($result);
Read recursively objects located under an object:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBLocationTree;
$api = new API([/* … */]);
$locationTree = new CMDBLocationTree($api);
$result = $locationTree->readRecursively(1);
var_dump($result);
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBObjectsByRelation;
$api = new API([/* … */]);
$relation = new CMDBObjectsByRelation($api);
$result = $relation->read(
10,
'C__RELATION_TYPE__PERSON_ASSIGNED_GROUPS'
);
var_dump($result);
A Person may be assigned to a workplace with several components like a PC, a monitor and a telephone. These components can be fetched by the person. You either need the object ID or the email address. Even more than one workplaces are supported.
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBWorkstationComponents;
$api = new API([/* … */]);
$components = new CMDBWorkstationComponents($api);
$result = $components->read(111); // Person object with ID 111
var_dump($result);
$result = $components->batchRead([111, 222]); // Person objects with IDs 111 and 222
var_dump($result);
$result = $components->readByEMail('alice@example.org'); // Person object with email address
var_dump($result);
$result = $components->readByEMails(['alice@example.org', 'bob@example.org']); // Person objects with email addresses
var_dump($result);
List all reports:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBReports;
$api = new API([/* … */]);
$reports = new CMDBReports($api);
$result = $reports->listReports();
var_dump($result);
Fetch the result of a report:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBReports;
$api = new API([/* … */]);
$reports = new CMDBReports($api);
$result = $reports->read(1);
var_dump($result);
Fetch the result of one or more reports:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBReports;
$api = new API([/* … */]);
$reports = new CMDBReports($api);
$result = $reports->batchRead([1, 2]);
var_dump($result);
use Idoit\APIClient\API;
use Idoit\APIClient\Subnet;
$api = new API([/* … */]);
$subnet = new Subnet($api);
// Load subnet object by its identifier:
$nextIP = $subnet->load(123)->next();
echo 'Next IP address: ' . $nextIP . PHP_EOL;
This API client library is able to upload a file, create a new "File" object an assigned it to an existing object identified by its ID:
use Idoit\APIClient\API;
use Idoit\APIClient\File;
$api = new API([/* … */]);
$file = new File($api);
// Assign one file to object with identifier 100:
$file->add(100, '/path/to/file', 'my file');
// Assign many files to this object:
$file->batchAdd(
100,
[
'file1.txt' => 'File 1',
'file2.txt' => 'File 2',
'file3.txt' => 'File 3'
]
);
Each object may have an image gallery provided by assigned category "images". This is the way to upload image files and assign them to an existing object:
use Idoit\APIClient\API;
use Idoit\APIClient\Image;
$api = new API([/* … */]);
$image = new Image($api);
// Assign one image with a caption to object's gallery with identifier 100:
$image->add(100, '/path/to/flowers.jpg', 'nice picture of flowers');
// Assign many images to this object:
$file->batchAdd(
100,
[
'file1.jpg' => 'JPEG file',
'file2.png' => 'PNG file',
'file3.bmp' => 'BMP file',
'file3.gif' => 'Animated GIF file'
]
);
Sometimes it is better to define a request on your own instead of using pre-defined methods provided by this API client library. Here is the way to perform a self-defined request:
use Idoit\APIClient\API;
$api = new API([/* … */]);
$result = $api->request('idoit.version');
var_dump($result);
request()
takes the method and optional parameters.
Similar to a simple requests you may perform a batch requests with many sub-requests as you need:
use Idoit\APIClient\API;
$api = new API([/* … */]);
$result = $api->batchRequest([
[
'method' => 'idoit.version'
],
[
'method' => 'cmdb.object.read',
'params' => ['id' => 1]
]
]);
var_dump($result);
Fetch information about object types, object types per group, categories assigned to object types, and attributes available in categories:
use Idoit\APIClient\API;
use Idoit\APIClient\CMDBObjectTypes;
use Idoit\APIClient\CMDBObjectTypeGroups;
use Idoit\APIClient\CMDBObjectTypeCategories;
use Idoit\APIClient\CMDBCategoryInfo;
$api = new API([/* … */]);
// Object types:
$objectTypes = new CMDBObjectTypes($api);
$allObjectTypes = $objectTypes->read();
var_dump($allObjectTypes);
$server = $objectTypes->readOne('C__OBJTYPE__SERVER');
var_dump($server);
$someObjectTypes = $objectTypes->batchRead('C__OBJTYPE__SERVER', 'C__OBJTYPE__CLIENT');
var_dump($someObjectTypes);
$client = $objectTypes->readByTitle('LC__CMDB__OBJTYPE__CLIENT');
var_dump($client);
// Object types per group:
$objectTypesPerGroup = new CMDBObjectTypeGroups($api);
$objectTypes = $objectTypesPerGroup->read();
var_dump($objectTypes);
// Categories assigned to object types:
$assignedCategory = new CMDBObjectTypeCategories($api);
$serverCategories = $assignedCategory->readByConst('C__OBJTYPE__SERVER');
var_dump($serverCategories);
// Read by identifiers is also possible. And there are methods for batch requests.
// Attributes available in categories:
$categoryInfo = new CMDBCategoryInfo($api);
$modelCategory = $categoryInfo->read('C__CATG__MODEL');
var_dump($modelCategory);
$categories = $categoryInfo->batchRead([
'C__CATG__MODEL',
'C__CATG__FORMFACTOR',
'C__CATS__PERSON_MASTER'
]);
var_dump($categories);
use Idoit\APIClient\API;
use Idoit\APIClient\Idoit;
$api = new API([/* … */]);
$idoit = new Idoit($api);
$version = $idoit->readVersion();
$constants = $idoit->readConstants();
$addOns = $idoit->getAddOns();
$license = $idoit->getLicense();
var_dump($version, $constants, $addOns, $license);
Sometimes you need a fresh connection. You may explicitly disconnect from the i-doit server and re-connect to it:
use Idoit\APIClient\API;
$api = new API([/* … */]);
// Do your stuff…
$api->disconnect();
$api->isConnected(); // Returns false
$api->connect();
$api->isConnected(); // Returns true
For debugging purposes it is great to fetch some details about your API calls. This script uses some useful methods:
#!/usr/bin/env php
<?php
use Idoit\APIClient\API;
use Idoit\APIClient\Idoit;
$start = time();
require_once 'vendor/autoload.php';
$api = new API([/* … */]);
// @todo Insert your code here, for example:
$request = new Idoit($api);
$request->readVersion();
fwrite(STDERR, 'Last request:' . PHP_EOL);
fwrite(STDERR, '=============' . PHP_EOL);
fwrite(STDERR, $api->getLastRequestHeaders() . PHP_EOL);
fwrite(STDERR, json_encode($api->getLastRequestContent(), JSON_PRETTY_PRINT) . PHP_EOL);
fwrite(STDERR, PHP_EOL);
fwrite(STDERR, '--------------------------------------------------------------------------------' . PHP_EOL);
fwrite(STDERR, 'Last response:' . PHP_EOL);
fwrite(STDERR, '==============' . PHP_EOL);
fwrite(STDERR, $api->getLastResponseHeaders() . PHP_EOL);
fwrite(STDERR, json_encode($api->getLastResponse(), JSON_PRETTY_PRINT) . PHP_EOL);
fwrite(STDERR, PHP_EOL);
fwrite(STDERR, '--------------------------------------------------------------------------------' . PHP_EOL);
fwrite(STDERR, 'Last connection:' . PHP_EOL);
fwrite(STDERR, '================' . PHP_EOL);
$info = $api->getLastInfo();
unset($info['request_header']);
foreach ($info as $key => $value) {
if (is_array($value)) {
$value = '…';
}
fwrite(STDERR, $key . ': ' . $value . PHP_EOL);
}
fwrite(STDERR, '--------------------------------------------------------------------------------' . PHP_EOL);
fwrite(STDERR, 'Amount of requests: ' . $api->countRequests() . PHP_EOL);
$memoryUsage = memory_get_peak_usage(true);
fwrite(STDERR, sprintf('Memory usage: %s bytes', $memoryUsage) . PHP_EOL);
$duration = time() - $start;
fwrite(STDERR, sprintf('Duration: %s seconds', $duration) . PHP_EOL);
Please, report any issues to our issue tracker. Pull requests are very welcomed. If you like to get involved see file CONTRIBUTING.md
for details.
- i-doit CLI Tool – "Access your CMDB on the command line interface"
- i-doit Check_MK 2 add-on – "Share information between i-doit and Check_MK"
Send pull requests to add yours.
Copyright (C) 2022 synetics GmbH
Copyright (C) 2016-2022 Benjamin Heisig
Licensed under the GNU Affero GPL version 3 or later (AGPLv3+). This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.