Ad Widget

Collapse

PhpZabbixApi - PHP library for Zabbix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LeoCombes
    Member
    • Mar 2011
    • 32

    #16
    Works fine!
    Thanks Domi!

    Comment

    • lana_paradinha
      Junior Member
      • Sep 2013
      • 28

      #17
      I am open build.php in my web browser and receive this lines.

      BUILT: abstract class file "build/ZabbixApiAbstract.class.php"
      SKIPPED: concrete class file "build/ZabbixApi.class.php"

      I dont understand.

      // write abstract class
      if(!file_put_contents(PATH_BUILD.'/'.FILENAME_ABSTRACT, $fileContent))
      die();

      echo 'BUILT: abstract class file "'.PATH_BUILD.'/'.FILENAME_ABSTRACT.'"'."\n";

      ...

      and

      if(!file_put_contents(PATH_BUILD.'/'.FILENAME_CONCRETE, $fileContent))
      die();

      echo 'BUILT: conrete class file "'.PATH_BUILD.'/'.FILENAME_CONCRETE.'"'."\n";
      }
      else
      {
      echo 'SKIPPED: concrete class file "'.PATH_BUILD.'/'.FILENAME_CONCRETE.'"'."\n";
      }
      ...


      I build.php dont open?


      i am remove files "ZabbixApiAbstract.class.php" and "ZabbixApi.class.ph" but is recreated.

      Comment

      • rmartineau
        Junior Member
        • Jan 2014
        • 8

        #18
        Hi dbarton,

        great job for this library

        are there a way to create directly one host with two interfaces ??

        with jsonrpc it's seem to be like that :

        "interfaces": [
        {
        "ip": "10.117.38.105",
        "useip": 1,
        "dns": "",
        "main": 1,
        "type": 1,
        "port": "10050"
        },
        {
        "ip": "10.117.38.105",
        "useip": 1,
        "dns": "",
        "main": 1,
        "type": 4,
        "port": "12349"
        }
        ],

        what's the syntax to do that with your library ?

        I use zabbix 2.2

        many Thanks

        rmartineau

        Comment

        • rmartineau
          Junior Member
          • Jan 2014
          • 8

          #19
          Hi

          I found the good syntax for solve my problem.

          PHP Code:
          $host $api->hostCreate(array(
              
          'host' => 'HOSTNAME',
              
          'interfaces' => array(
                  array(
                      
          'type' => 1,
                      
          'main' => 1,
                      
          'useip'=> 1,
                      
          'ip' => '10.0.254.254',
                      
          'dns' => '',
                      
          'port' => 10050,
                  ),
                  array(
                      
          'type' => 2,
                      
          'main' => 1,
                      
          'useip'=> 1,
                      
          'ip' => '10.0.254.254',
                      
          'dns' => '',
                      
          'port' => 161,
                  ),
              ),
              
          'groups' => array(
                  array(
          'groupid' => 6),
              ),
          )); 
          it may help someone

          Comment

          • clahti
            Senior Member
            • Jan 2007
            • 126

            #20
            Problems with PhpZabbixApi (won't load)

            Hello all:

            I am trying to get the PhpZabbixApi going. I have a simple test page:

            Code:
            <?php
            
            // load ZabbixApi
            #require 'ZabbixApiAbstract.class.php';
            require 'ZabbixApi.class.php';
            
            try {
            
                // create new ZabbixApi instance
                $api = new ZabbixApi;
            
                // set API url
                $api->setApiUrl('https://zabbix.shotspotter.com/api_jsonrpc.php');
            
                // try to login into Zabbix API
                $api->userLogin(array('user' => 'zabbixapi', 'password' => 'zabbixapi'));
            
            } catch(Exception $e) {
            
                // Exception in ZabbixApi catched
                echo $e->getMessage();
            
            }
            ?>
            This yields the following warning:

            Code:
            PHP Warning:  fopen(https://myserver.mydomain.com/api_jsonrpc.php): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
             in /usr/share/PhpZabbixApi_Builder/build/ZabbixApiAbstract.class.php on line 234
            Could not connect to "https://myserver.mydomain.com/api_jsonrpc.php"
            This is the cookie cutter example of api connect from the PhpZabbixApi website. Notice I had to comment out the require 'ZabbixApiAbstract.class.php' because that was being declared twice. Is there anyone using this API successfully? It is probably something stupid on my part I have successfully used the Ruby bindings for the API, but now I need to use PHP for this project. Any help would be appreciated, I am running Zabbix version 2.2 on vanilla CentOS linux box. It is also worth mentioning that I am running this via the command line, not in a web browser.

            Comment

            • clahti
              Senior Member
              • Jan 2007
              • 126

              #21
              OMG, never mind people. I am leaving this post to illustrate that you should always check your URL path in code before posting stupid questions. I ommitted the /zabbix portion of the path. My bad, carry on

              Comment

              • pds
                Junior Member
                • Apr 2014
                • 11

                #22
                I'm currently trying to use the framework so i can automate the backing up of the templates. However i wonder how the query type paramater is handled with this framework

                (https://www.zabbix.com/documentation...e/template/get)

                Comment

                • Yello
                  Senior Member
                  • Apr 2011
                  • 309

                  #23
                  Hi,
                  Does this api wrapper work with zabbix 2.2? I've just run the builder and the concrete class got built with no methods.

                  Regards,
                  David

                  Comment

                  • geniuspritam
                    Junior Member
                    • Jun 2018
                    • 1

                    #24


                    @Clahti

                    Hope this helps you:

                    <?php

                    // load ZabbixApi
                    #require 'ZabbixApiAbstract.class.php';
                    require 'ZabbixApi.class.php';

                    try {

                    // create new ZabbixApi instance ** Added 'ZabbixApi\' **
                    $api = new ZabbixApi\ZabbixApi();

                    // set API url
                    $api->setApiUrl('http://myhost.mydomain/api_jsonrpc.php');

                    // try to login into Zabbix API
                    $api->userLogin(array('user' => 'myUserId', 'password' => 'myPassword'));
                    var_dump($api); // if Connected you can see the 'authToken'
                    } catch(Exception $e) {

                    // Exception in ZabbixApi catched
                    echo $e->getMessage();

                    }
                    ?>

                    Comment

                    Working...