Use a Python script to call post to monitor server status

Source: Internet
Author: User

The company needs to monitor the status of an app server. Developers require the use of post (JSON format parameters) to view the server return status. To determine if the server is healthy. It is not possible to use Get mode.

I use Python to write a script to monitor. The process is as follows:

Create key:

[email protected] zabbix_agentd.conf.d]# cat httppost.conf

userparameter=http.post,/usr/bin/python/etc/zabbix/scripts/httppost.py

Test key:

[email protected] zabbix_agentd.conf.d]# zabbix_get-s 127.0.0.1-k http.post

200

Script Content

[email protected] scripts]# cat httppost.py

#!/usr/bin/python

Import Requests,json

Url= "Http://app.xxxxx.com/P2MLinkCenter/setting/upgrade"

header={' content-type ': ' Application/json '}

Data=json.dumps ({"Type": "apk", "Versioncode": "1.0.0"})

Req=requests.post (Url=url,data=data,headers=header)

Print Req.status_code


Select a server to create the item:

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/80/1F/wKioL1c5Fs-BdF0BAADCzmdtRpo169.jpg "title=" 1.jpg " alt= "Wkiol1c5fs-bdf0baadczmdtrpo169.jpg"/>

Create graph:

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M02/80/1F/wKioL1c5FuOhZQDOAACI5gMrl7A036.jpg "title=" 2.jpg " alt= "Wkiol1c5fuohzqdoaaci5gmrl7a036.jpg"/>


View Graph:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/80/22/wKiom1c5FlXxFGa3AABH_iltCbE865.png "title=" 3.PNG " alt= "Wkiom1c5flxxfga3aabh_iltcbe865.png"/>

As you can see, the status code returned by the server is 200, indicating OK.


Use a Python script to call post to monitor server status

Related Article

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.