Configuration of zabbix api and php in CentOS6.x

Source: Internet
Author: User
Tags blank page

Recently, the hadoop cluster has been upgraded from mrv1 to mrv2, and the monitoring template has also changed .. There are about 200 clusters online. The module is added using the link method, that is, a large number of modules are linked under a template, and then the host is added to this template.

In this case, a machine has about 215 items.

To increase the monitoring of NM, the link method is also used to connect the template. When link is found on the page, a blank page is always returned. In order to get online quickly, we changed the following method and used the host. update api to directly link the host to the NM template. Let's look back at this question: when using the Page link template, it actually calls the zabbix template-related APIs (the template is called specifically. update method) Call the api test directly through the script: Test script:
#!/usr/bin/env python import urllib2 import sys import json def requestJason(url,values): data = json.dumps(values) print data req = urllib2.Request(url, data, { 'Content-Type' : 'application/json-rpc' }) response = urllib2.urlopen(req, data) data_get = response.read() output = json.loads(data_get) print output try : message = output[ 'result' ] except : message = output[ 'error' ][ 'data' ] quit() print json.dumps(message) return output def authenticate(url, username, password): values = { 'jsonrpc' : '2.0' , 'method' : 'user.login' , 'params' : { 'user' : username, 'password' : password }, 'id' : '0' } idvalue = requestJason(url,values) return idvalue[ 'result' ] def getTemplate(hostname,url,auth): values = { 'jsonrpc' : '2.0' , 'method' : 'template.get' , 'params' : { 'output' : "extend" , 'filter' : { 'host' : hostname } }, 'auth' : auth, 'id' : '2' } output = requestJason(url,values) print output[ 'result' ][ 0 ][ 'hostid' ] return output[ 'result' ][ 0 ][ 'hostid' ] def changeTemplate(idx,id_list,url,auth): values = { 'jsonrpc' : '2.0' , 'method' : 'template.update' , 'params' : { "templateid" :idx, "templates" :id_list }, 'auth' : auth, 'id' : '2' } output = requestJason(url,values) print output def main(): id_list = [] hostname = "Vipshop_Template_OS_Linux_Hadoop_Datanode_Pro" url = 'xxxx' username = 'admin' password = 'xxxx' auth = authenticate(url, username, password) idx = getTemplate(hostname,url,auth) temlist = [ 'Vipshop_Template_LB_Tengine_8090' , 'Vipshop_Template_Redis_6379' , 'Vipshop_Template_Redis_6380' , 'Vipshop_Template_Redis_6381' , 'Vipshop_Template_Redis_6382' , 'Vipshop_Template_Redis_6383' ] for tem in temlist: idtemp = getTemplate(tem,url,auth) id_list.append({ "templateid" :idtemp}) print id_list #id_list = [{"templateid":'10843'},{"templateid":"10554"},{"templateid":"10467"},{"templateid":"10560"},{"templateid":"10566"},{"templateid":"10105"}] changeTemplate(idx,id_list,url,auth) if __name__ = = '__main__' : main()Script result: urllib2.HTTPError: HTTP Error 500: Internal Server Error because the api actually sends a post request in jason format, manually use curl for verification:
curl -vvv -i -X POST -H 'Content-Type:application/json' -d '{ "params" : { "templates" : [{ "templateid" : "10117" }, { "templateid" : "10132" }, { "templateid" : "10133" }, { "templateid" : "10134" }, { "templateid" : "10135" }, { "templateid" : "10136" }], "templateid" : "10464" }, "jsonrpc" : "2.0" , "method" : "template.update" , "auth" : "421a04b400e859834357b5681a586a5f" , "id" : "2" }' http: //zabbix .idc.vipshop.com /api_jsonrpc .phpIf the 500 error is returned (that is, the backend php encounters an error during processing), adjust the php configuration and change the log to the debug format:
php-fpm.conf: log_level = debugThe following error is found in the error log:
[04-May-2014 14:04:32.115189] WARNING: pid 6270, fpm_request_check_timed_out(), line 271: [pool www] child 6294, script '/apps/svr/zabbix/wwwroot/api_jsonrpc.php' (request: "POST /api_jsonrpc.php" ) executing too slow (1.269946 sec), logging [04-May-2014 14:04:32.115327] DEBUG: pid 6270, fpm_got_signal(), line 72: received SIGCHLD [04-May-2014 14:04:32.115371] NOTICE: pid 6270, fpm_children_bury(), line 227: child 6294 stopped for tracing [04-May-2014 14:04:32.115385] NOTICE: pid 6270, fpm_php_trace(), line 142: about to trace 6294 [04-May-2014 14:04:32.115835] NOTICE: pid 6270, fpm_php_trace(), line 170: finished trace of 6294 [04-May-2014 14:04:32.115874] DEBUG: pid 6270, fpm_event_loop(), line 409: event module triggered 1 events [04-May-2014 14:04:35.318614] WARNING: pid 6270, fpm_stdio_child_said(), line 166: [pool www] child 6294 said into stderr: "NOTICE: sapi_cgi_log_message(), line 663: PHP message: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 512 bytes) in /apps/svr/zabbix/wwwroot/api/classes/CItem.php on line 1088" [04-May-2014 14:04:35.318665] DEBUG: pid 6270, fpm_event_loop(), line 409: event module triggered 1 eventsThat is to say, when creating a link template, you need to put the relevant data in the php memory, and the default setting is 128 M. If there are many items and hosts, it is easy to exceed this limit. Change
Memory_limit = 1280 M

A 502 Bad Gateway error is returned after a retest, that is, the backend execution times out. Error log:
[04-May-2014 14:50:21.318071] WARNING: pid 4131, fpm_request_check_timed_out(), line 281: [pool www] child 4147, script '/apps/svr/zabbix/wwwroot/api_jsonrpc.php' (request: "POST /api_jsonrpc.php" ) execution timed out (10.030883 sec), terminating
The execution time exceeds the request_terminate_timeout setting. Resulting in 502. Change request_terminate_timeout = 1800 (10 s by default), max_execution_time = 0 (30 s by default), and retest. OK. Conclusion: zabbix is a batch action when calling APIs for updates. zabbix has certain requirements on memory and execution time. Therefore, you need to properly set php parameters, lower the log level during debugging, and enable slow log to locate the problem.

This article from the "Food light blog" blog, please be sure to keep this source http://caiguangguang.blog.51cto.com/1652935/1407422

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.