PHP code example of becker / laravel-zabbix-api

1. Go to this page and download the library: Download becker/laravel-zabbix-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

becker / laravel-zabbix-api example snippets


composer 

//config/app.php

/*
 * Package Service Providers...
 */

Becker\Zabbix\ZabbixServiceProvider::class,

//...

php artisan vendor:publish --tag=zabbix

ZABBIX_HOST=http://your.zabbix.url
ZABBIX_USERNAME=username
ZABBIX_PASSWORD=password

//app/Http/Controllers/TestController.php



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class TestController extends Controller
{
    /**
     * The ZabbixApi instance.
     *
     * @var \Becker\Zabbix\ZabbixApi
     */
    protected $zabbix;
    
    /**
     * Create a new Zabbix API instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->zabbix = app('zabbix');
    }

    /**
     * Get all the Zabbix host groups.
     *
     * @return array
     */
    public function index()
    {
        return $this->zabbix->hostgroupGet([
            'output' => 'extend'
        ]);

        // Or, if you want to use Laravel Collections

        return collect($this->zabbix->hostgroupGet())->map(function ($item) {
            return [
                'name' => strtoupper($item->name)
            ];
        });
    }
}