Ad Widget

Collapse

how to add discovery rule with API?

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

    #1

    how to add discovery rule with API?

    Hello!
    I trying with the following code:

    Code:
    ZabbixAPI::query('drule','create',array('name'=>'test', 'iprange'=>'192.168.31.11-254', 'delay'=>7200, 'status'=>0, 'unique_dcheckid'=>0)) 
        or die('error: '.print_r(ZabbixAPI::getLastError(),true));
    ...and not work.
    I forgot some obvious thing?
    Thanks!
  • LeoCombes
    Member
    • Mar 2011
    • 32

    #2
    BUMP!

    anyone can help?

    Comment

    • LeoCombes
      Member
      • Mar 2011
      • 32

      #3
      No luck... I still trying but not work.
      Now try with array of arrays, not work at all:

      Code:
      ZabbixAPI::query('drule', 'create', array('druleids'=>15, array('name'=>'test', 'iprange'=>'192.168.31.11-254', 'delay'=>7200, 'status'=>0, 'unique_dcheckid'=>0))
       	or die('error: '.print_r(ZabbixAPI::getLastError(),true)));
      Code:
      CURL Options: Array
      (
          [19913] => 1
          [13] => 30
          [78] => 5
          [81] => 
          [64] => 
          [52] => 1
          [74] => 1
          [10023] => Array
              (
                  [0] => Content-Type: application/json-rpc
                  [1] => User-Agent: ZabbixAPI v1.0 - http://andrewfarley.com/zabbix_php_api
              )
      
          [10036] => POST
          [10015] => {"auth":null,"method":"user.authenticate","id":1,"params":{"password":"zabbix","user":"admin"},"jsonrpc":"2.0"}
          [10102] => gzip
      )
      Got response from API: ({"jsonrpc":"2.0","result":"c8b5bc95bd08f6244ddd0af9d94b8095","id":1})
      Response decoded: (Array
      (
          [jsonrpc] => 2.0
          [result] => c8b5bc95bd08f6244ddd0af9d94b8095
          [id] => 1
      )
      
      __login() Got response from API: (c8b5bc95bd08f6244ddd0af9d94b8095)
      CURL URL: https://190.185.204.2/zabbix/api_jsonrpc.php
      CURL Options: Array
      (
          [19913] => 1
          [13] => 30
          [78] => 5
          [81] => 
          [64] => 
          [52] => 1
          [74] => 1
          [10023] => Array
              (
                  [0] => Content-Type: application/json-rpc
                  [1] => User-Agent: ZabbixAPI v1.0 - http://andrewfarley.com/zabbix_php_api
              )
      
          [10036] => POST
          [10015] => {"auth":"c8b5bc95bd08f6244ddd0af9d94b8095","method":"drule.create","id":1,"[B]params":[][/B],"jsonrpc":"2.0"}
          [10102] => gzip
      )
      Got response from API: ({"jsonrpc":"2.0","result":{"[B]druleids":[][/B]},"id":1})
      Response decoded: (Array
      (
          [jsonrpc] => 2.0
          [result] => Array
              (
                  [druleids] => Array
                      (
                      )
      
              )
      
          [id] => 1
      )
      In bold highlight the possible error (empty arrays/values), however not find a way to make it work.
      Someone who knows the API can lose 5 minutes to tell me the correct way to do this?

      Thank you in advance!

      PS: I use the PHP API extension of Andrew Farley

      Comment

      • LeoCombes
        Member
        • Mar 2011
        • 32

        #4
        could be that the documentation of the API for discovery is wrong?

        Comment

        • LeoCombes
          Member
          • Mar 2011
          • 32

          #5
          After a little research in 2.0 documentation I found that parameters of check rule goes into an array.
          I test this in PHP:

          Code:
          ZabbixAPI::query('drule', 'create', array('dchecks' => array('0' => array('type' => '9','key_' => 'system.uname', 'ports' => '10050', 'uniq' => '0')), 'proxy_hostid' => '0', 'name' => 'prueba', 'iprange' => '192.168.1.1-254', 'delay' => '7200', 'status' => '1')) or die('error: '.print_r(ZabbixAPI::getLastError(),true));
          ...and this in JSON (copy/paste from 2.0 documentation):

          Code:
          {
          "dchecks": [
              {
                  "type": "9",
                  "key_": "system.uname",
                  "ports": "10050",
                  "uniq": "0"
              }
          ],
          "proxy_hostid": 0,
          "name": "Local network ooo",
          "iprange": "192.168.1.1-255",
          "delay": "3600",
          "status": "1"
          }

          ...and NOT WORKING IN ANY WAY!

          any help is appreciated

          Comment

          • LeoCombes
            Member
            • Mar 2011
            • 32

            #6
            I'm asking wrong? Or no one uses the API to add rules of discovery?
            I do not know what else to try, maybe this bump in the thread help someone else to see it.
            Any help will be appreciated.

            Comment

            • LeoCombes
              Member
              • Mar 2011
              • 32

              #7
              Better late than never.
              Today I tried again, but this time with version 2.0 of Zabbix newly installed and everything works. Obviously in previous versions could not create discovery rules from the API.

              Greetings.

              Comment

              Working...