Skip to content

Instantly share code, notes, and snippets.

@isaqueprofeta
Last active April 17, 2020 18:25
Show Gist options
  • Save isaqueprofeta/23a02a05ffec88362c36bda98e369ce7 to your computer and use it in GitHub Desktop.
Save isaqueprofeta/23a02a05ffec88362c36bda98e369ce7 to your computer and use it in GitHub Desktop.
Usando a API do zabbix rapidamente em PHP

Instalar PHP:

sudo apt-get install php7.0 php7.0-cli php7.0-common php7.0-curl

Instalar Composer:

sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
sudo php composer-setup.php
sudo php -r "unlink('composer-setup.php');"

Deixar composer global:

sudo mv composer.phar /usr/local/bin/composer
sudo chmod 755 /usr/local/bin/composer

Criar pasta de projeto e instalar as dependências:

mkdir api_zabbix
cd api_zabbix
composer require ikke/phpzabbix

Criar o script com o conteúdo mínimo:

<?php
  // Carrega bibliotecas
  require __DIR__ . '/vendor/autoload.php';

  // Carrega credenciais
  $url_api = http://servidor.zabbix/api_jsonrpc.php;
  $usuario_api = 'Admin';
  $senha_api = 'zabbix';

  // Cria a conexão com o Guzzle e o PHPZabbix e loga
  $client = new \GuzzleHttp\Client();
  $api = new \phpzabbix\PHPZabbix($client, $url_api);
  $api->login($usuario_api, $senha_api);

  // Daqui para a frente é com você!!!
  $grupos = $api->hostgroup->get();
  print_r($grupos);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment