idoit / checkmkwebapiclient
Easy-to-use, but feature-rich client library for Checkmk's Web API
Requires
- php: >=7.2.0
- ext-curl: *
- ext-date: *
- ext-json: *
- ext-openssl: *
- ext-spl: *
- ext-zlib: *
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.0
- j13k/yaml-lint: ^1.1
- php-parallel-lint/php-parallel-lint: ^1.0
- phpcompatibility/php-compatibility: *
- phploc/phploc: ^5.0
- phpmd/phpmd: ^2.8.2
- phpstan/phpstan: ^0.12.29
- phpunit/phpunit: ^8
- povils/phpmnd: ^2
- roave/security-advisories: dev-master
- sclable/xml-lint: ^0.3.0
- sebastian/phpcpd: ^4.1.0
- seld/jsonlint: ^1.7
- sensiolabs/security-checker: ^6
- sllh/composer-lint: ^1.0
- squizlabs/php_codesniffer: *
- symfony/dotenv: ^5.1
Suggests
- ext-xdebug: Needed for code coverage with phpunit
README
Easy-to-use, but feature-rich client for Checkmk Web API
Please note: This project is not an official product by synetics GmbH. synetics GmbH doesn't provide any commercial support.
About
Checkmk is a software application for network monitoring. The community edition ("raw") is licensed under the GPLv2.
This client communicates with Checkmk over its Web API. It provides a simple, but powerful abstraction layer for written in PHP. Feel free to use it as a library in your own projects.
Requirements
Meet these simple requirements before using the client:
- One or more Checkmk sites, version
1.4
or higher (most calls work since1.5
) - PHP, version
8.0
or higher (8.1
is recommended,7.4
should work but is deprecated) - PHP modules
curl
,date
,json
,openssl
,spl
andzlib
Installation
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/checkmkwebapiclient
This command installs the latest stable version. Instead of sticking to a specific/minimum version you may switch to the current development branch by using @DEV
:
composer require "idoit/checkmkwebapiclient=@DEV"
Updates
Composer has the great advantage (besides many others) that you can simply update the client by running:
composer update
Usage
Composer comes with its own autoloader. Include this line into your PHP code:
require_once 'vendor/autoload.php';
This is it. All other files will be auto-loaded on-the-fly if needed.
First call
This is a simple "Hello, world!" example. It fetches all configured hosts from Checkmk:
use Idoit\CheckmkWebAPIClient\API;
use Idoit\CheckmkWebAPIClient\Config;
use Idoit\CheckmkWebAPIClient\Host;
$config = new Config();
$config
->setURL('https://monitoring.example.org/mysite/check_mk/')
->setUsername('automation')
->setSecret('abc123');
$api = new API($config);
$request = new Host($api);
$hosts = $request->getAll();
var_dump($hosts);
Configuration
The API
class requires configuration settings passed to its constructor:
use Idoit\CheckmkWebAPIClient\API;
use Idoit\CheckmkWebAPIClient\Config;
$config = new Config();
$config
->setURL('https://monitoring.example.org/mysite/check_mk/')
->setPort(443)
->setUsername('automation')
->setSecret('abc123')
->enableProxy()
//->disableProxy()
->useHTTPProxy()
//->useSOCKS5Proxy()
->setProxyHost('proxy.example.net')
->setProxyPort(8080)
->setProxyUsername('proxyuser')
->setProxyPassword('verysecure');
$api = new API($config);
The Config
class has public methods which must be called to configure the API:
Optional proxy settings:
Hosts
Class Host
with public methods:
Sites
Class Site
with public methods:
Folders
Class Folder
with public methods:
Groups
Classes HostGroup
, ServiceGroup
and ContactGroup
with public methods:
Host Tags
Class HostTag
with public methods:
Users
Class Users
with public methods:
Rulesets
Class Ruleset
with public methods:
Agents
Class Agent
with public methods:
Activate Changes
Class Change
with public methods:
Metrics
Class Graph
with public method:
Inventory
Checkmk can collect various information about your hardware/software inventory.
Class Inventory
with public methods:
Contribute
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.
Copyright & License
Copyright (C) 2022 synetics GmbH
Copyright (C) 2018-22 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.