Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic support for Travis CI #39

Merged
merged 1 commit into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
test.php
/vendor/
/src/
122 changes: 122 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
language: php

dist: bionic
sudo: false

git:
depth: 1

php:
- 7.1
- 7.2
- 7.3
- 7.4

env:
- ZABBIX_VERSION=2.4.0
- ZABBIX_VERSION=2.4.8
- ZABBIX_VERSION=3.0.0
- ZABBIX_VERSION=3.4.15
- ZABBIX_VERSION=4.0.0
- ZABBIX_VERSION=4.4.4

jobs:
fast_finish: true
include:
- php: 5.3
dist: precise
env: ZABBIX_VERSION=2.4.0
- php: 5.3
dist: precise
env: ZABBIX_VERSION=2.4.8
- php: 5.4
dist: trusty
env: ZABBIX_VERSION=2.4.0
- php: 5.4
dist: trusty
env: ZABBIX_VERSION=2.4.8
- php: 5.4
dist: precise
env: ZABBIX_VERSION=3.0.0
- php: 5.4
dist: precise
env: ZABBIX_VERSION=3.4.15
- php: 5.4
dist: precise
env: ZABBIX_VERSION=4.0.0
- php: 5.4
dist: precise
env: ZABBIX_VERSION=4.4.4
- php: 5.5
dist: trusty
env: ZABBIX_VERSION=2.4.0
- php: 5.5
dist: trusty
env: ZABBIX_VERSION=2.4.8
- php: 5.5
dist: precise
env: ZABBIX_VERSION=3.0.0
- php: 5.5
dist: precise
env: ZABBIX_VERSION=3.4.15
- php: 5.5
dist: precise
env: ZABBIX_VERSION=4.0.0
- php: 5.5
dist: precise
env: ZABBIX_VERSION=4.4.4
- php: 5.6
dist: trusty
env: ZABBIX_VERSION=2.4.0
- php: 5.6
dist: trusty
env: ZABBIX_VERSION=2.4.8
- php: 5.6
dist: precise
env: ZABBIX_VERSION=3.0.0
- php: 5.6
dist: precise
env: ZABBIX_VERSION=3.4.15
- php: 5.6
dist: precise
env: ZABBIX_VERSION=4.0.0
- php: 5.6
dist: precise
env: ZABBIX_VERSION=4.4.4
- php: 7.0
dist: trusty
env: ZABBIX_VERSION=2.4.0
- php: 7.0
dist: trusty
env: ZABBIX_VERSION=2.4.8
- php: 7.0
dist: precise
env: ZABBIX_VERSION=3.0.0
- php: 7.0
dist: precise
env: ZABBIX_VERSION=3.4.15
- php: 7.0
dist: precise
env: ZABBIX_VERSION=4.0.0
- php: 7.0
dist: precise
env: ZABBIX_VERSION=4.4.4

cache:
directories:
- $HOME/.composer

before_install:
- |
# General configuration
stty cols 120
mkdir -p /opt/zabbix
wget -qO- https://repo.zabbix.com/zabbix/$(echo $ZABBIX_VERSION | cut -d. -f-2)/ubuntu/pool/main/z/zabbix/zabbix_$ZABBIX_VERSION.orig.tar.gz | tar xvz -C /opt/zabbix
ln -s /opt/zabbix/zabbix-$ZABBIX_VERSION/frontends/php/ /opt/zabbix/frontend

install:
- php ./build/build.php
- composer install --prefer-dist --optimize-autoloader --classmap-authoritative --no-interaction --no-scripts

script:
- ./vendor/bin/phpunit
58 changes: 31 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
## PhpZabbixApi

[![Build Status](https://travis-ci.org/confirm/PhpZabbixApi.svg?branch=master)](https://travis-ci.org/confirm/PhpZabbixApi)

> __I'M LOOKING FOR CONTRIBUTORS, [CLICK HERE FOR MORE INFORMATIONS](https://github.com/confirm/PhpZabbixApi/issues/28)__

### About

PhpZabbixApi is an open-source PHP class library to communicate with the Zabbix™ JSON-RPC API.

Because PhpZabbixApi is generated directly from the origin Zabbix™ 2.0 PHP front-end source code / files, each real Zabbix™ JSON-RPC API method is implemented (hard-coded) directly as an own PHP method. This means PhpZabbixApi is IDE-friendly, because you've a PHP method for each API method, and there are no PHP magic functions or alike.
Because PhpZabbixApi is generated directly from the origin Zabbix™ PHP front-end source code / files, each real Zabbix™ JSON-RPC API method is implemented (hard-coded) directly as an own PHP method. This means PhpZabbixApi is IDE-friendly, because you've a PHP method for each API method, and there are no PHP magic functions or alike.

### License

Expand All @@ -30,28 +32,28 @@ You might want to point `PATH_ZABBIX` to your Zabbix™ installation directory.
If you setup everything correctly, you should be able to create the library by executing:

```bash
php build.php
php build/build.php
```

There are also pre-built libraries available in the `build/` directory, if you don't want to build it yourself.
There are also pre-built libraries available in the `src/` directory, if you don't want to build it yourself.

### Download

[Download a release](https://github.com/domibarton/PhpZabbixApi/releases) and extract the pre-built PHP library from the `build/` directory.
[Download a release](https://github.com/domibarton/PhpZabbixApi/releases) and extract the pre-built PHP library from the `src/` directory.

Make sure you've downloaded the following files and stored them in the same directory:

* `ZabbixApi.class.php`
* `ZabbixApiAbstract.class.php`
* `ZabbixApi.php`
* `AbstractZabbixApi.php`

For example:

```
my_application
├── index.php
└── lib
├── ZabbixApiAbstract.class.php
└── ZabbixApi.class.php
├── AbstractZabbixApi.php
└── ZabbixApi.php
```

### Composer
Expand All @@ -66,15 +68,15 @@ All [tagged](https://github.com/domibarton/PhpZabbixApi/tags) versions can be in


```
composer require 'confirm-it-solutions/php-zabbix-api:2.2.2'
composer require 'confirm-it-solutions/php-zabbix-api:2.4.2'
composer require 'confirm-it-solutions/php-zabbix-api:^2.2'
composer require 'confirm-it-solutions/php-zabbix-api:^2.4'
```

If you're looking for more "bleeding-edge" versions (e.g. for testing), then you could also use [branches](https://github.com/confirm-it-solutions/PhpZabbixApi/branches):

```
composer require 'confirm-it-solutions/php-zabbix-api:2.2.*@dev'
composer require 'confirm-it-solutions/php-zabbix-api:2.4.*@dev'
composer require 'confirm-it-solutions/php-zabbix-api:2.2@dev'
composer require 'confirm-it-solutions/php-zabbix-api:2.4@dev'
```

## Using the thing
Expand All @@ -101,34 +103,32 @@ dcheck.isWritable dcheckIsWritable()
By default there are only 2 classes defined:

```
ZabbixApiAbstract
AbstractZabbixApi
└── ZabbixApi
```

If you want to customize or extend the library, you might want to do that in the `ZabbixApi` class.
Out of the box, `ZabbixApi` is an empty class inherited from `ZabbixApiAbstract`.
Out of the box, `ZabbixApi` is an empty class inherited from `AbstractZabbixApi`.

By customizing only `ZabbixApi`, you're able to update `ZabbixApiAbstract` (the build) at any time, without merging your customizations manually.
By customizing only `ZabbixApi`, you're able to update `AbstractZabbixApi` (the build) at any time, without merging your customizations manually.

### Basic usage

To use the PhpZabbixApi you just have to load `ZabbixApi.class.php`, create a new `ZabbixApi` instance, and you're ready to go:
To use the PhpZabbixApi you just have to load `ZabbixApi.php`, create a new `ZabbixApi` instance, and you're ready to go:

```php
<?php
// load ZabbixApi
require_once 'lib/ZabbixApi.class.php';
require_once __DIR__.'/vendor/autoload.php';
use ZabbixApi\ZabbixApi;
use ZabbixApi\Exception;

try
{
try {
// connect to Zabbix API
$api = new ZabbixApi('http://zabbix.confirm.ch/api_jsonrpc.php', 'zabbix_user', 'zabbix_password');

/* ... do your stuff here ... */
}
catch(Exception $e)
{
} catch (Exception $e) {
// Exception in ZabbixApi catched
echo $e->getMessage();
}
Expand All @@ -153,8 +153,9 @@ Here's a simple request to fetch all defined graphs via [graph.get API method](h
$graphs = $api->graphGet();

// print all graph IDs
foreach($graphs as $graph)
foreach ($graphs as $graph) {
echo $graph->graphid."\n";
}
```

### Request with parameters
Expand All @@ -170,8 +171,9 @@ Here's an example to fetch all CPU graphs via [graph.get API method](https://www
));

// print graph ID with graph name
foreach($cpuGraphs as $graph)
foreach ($cpuGraphs as $graph) {
printf("id:%d name:%s\n", $graph->graphid, $graph->name);
}
```

### Define default parameters
Expand All @@ -191,8 +193,9 @@ You can do that by defining the parameters in an array via `setDefaultParams()`:
));

// print graph ID with graph name
foreach($cpuGraphs as $graph)
foreach ($cpuGraphs as $graph) {
printf("id:%d name:%s\n", $graph->graphid, $graph->name);
}
```

### Get associative / un-indexed array
Expand All @@ -208,8 +211,9 @@ Here's an example to fetch all graphs in an associative array, with the graph's
$graphs = $api->graphGet(array(), 'name');

// print graph ID with graph name
if(array_key_exists('CPU Load Zabbix Server', $graphs))
if (array_key_exists('CPU Load Zabbix Server', $graphs)) {
echo 'CPU Load graph exists';
else
} else {
echo 'Could not find CPU Load graph';
}
```
Loading