Ad Widget

Collapse

Multiple API Requests at once

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • unixdude
    Junior Member
    • Jan 2015
    • 2

    #1

    Multiple API Requests at once

    Hi Guys

    I have a bit of a strange problem with the JSON-RPC 2.0 API - I have managed to get single requests working fine but my problem comes when making concurrent requests.

    Below is an example of a multiple request I am trying to make:

    PHP Code:
    [
        {
            
    "jsonrpc""2.0",
            
    "method""item.get",
            
    "params": {
                
    "output""extend",
                
    "hostids""10109",
                
    "search": {
                    
    "key_""proc.num[apache2,www-data]"
                
    }
            },
            
    "id"2,
            
    "auth""xxxxxxxxxxxxxxxxxx"
        
    },
        {
            
    "jsonrpc""2.0",
            
    "method""item.get",
            
    "params": {
                
    "output""extend",
                
    "hostids""10109",
                
    "search": {
                    
    "key_""vfs.fs.size[/,used]"
                
    }
            },
            
    "id"3,
            
    "auth""xxxxxxxxxxxxxxxxx"
        
    }

    However I am getting the error "JSON-rpc version is not specified" as the response.

    Can anyone confirm that they can send multiple requests at once? My zabbix version is 2.4.0.

    Any help much appreciated
  • unixdude
    Junior Member
    • Jan 2015
    • 2

    #2
    Well after reading through the zabbix frontend source code it really doesn't appear that it can handle multiple requests, unless I missed something. Weird as it mentions in the documentation that it can, and also in this PDF from Zabconf2012: http://www.zabbix.com/img/zabconf201...I-2_Final_.pdf (search for batch requests)

    Anyway, I took an alternate approach to this in-case anyone is interested. Instead of sending individual requests I just used 'filter' option in the API call, listing multiple keys. This will return an array of results. Example below:

    PHP Code:
    $req = [
                    
    'jsonrpc' => '2.0',
                    
    'method'  => 'item.get',
                    
    'params'  => [
                        
    'output'  => 'extend',
                        
    'hostids' => 12345,
                        
    'filter'  => [
                            
    'key_' => [
                                
    'vfs.fs.size[/,used]',
                                
    'proc.num[apache2,www-data]',
                                
    'mysql.ping',
                                
    'system.cpu.load[percpu,avg5]',
                                
    'vm.memory.size[available]',
                                
    'net.if.in[eth0]',
                                
    'net.if.out[eth0]'
                            
    ]
                        ]
                    ],
                    
    'id'      => 1
                    
    'auth'    => 'xxxxxxxxxxxxxxxxxxxxx'
                
    ]; 
    Hope this helps someone else with the same problem!

    Comment

    Working...