3, Zabbix-api use

Source: Internet
Author: User

Zabbix provides API interfaces and methods that enable you to create hosts, delete hosts, create macros, create templates, and so on, using methods.


Here are some examples to see how to use Zabbix-api

Zabbix Official Document: Https://www.zabbix.com/documentation/2.2/ru/start


To use the API interface of Zabbix, you need to install the Zabbix-api module with PIP. So we need to install PIP first, then install the Zabbix-api module, and install the Setuptools module before installing PIP.


Installing Setuptools

: Https://pypi.python.org/pypi?%3Aaction=search&term=setuptools&submit=search

Installation:

Tar zxf setuptools-19.6.2.tar.gzcd setuptools-19.6.2python setup.py Install


Install PIP

: https://pypi.python.org/pypi/pip/

Installation:

Tar zxf pip-8.1.0.tar.gz cd pip-8.1.0python setup.py install


Installing the ZABBIX-API module

Pip install Zabbix-api[[email protected] pip-8.1.0]# pip Listdeprecation:python 2.6 is no. longer supported by the Python Core team, please upgrade your Python.  A future version of PIP would drop support for Python 2.6iniparse (0.3.1) ordereddict (1.2) pip (8.1.0) pycurl (7.19.0) Pygpgme (0.1) Setuptools (19.6.2) urlgrabber (3.9.1) yum-metadata-parser (1.1.2) ZABBIX-API (0.4) You are using PIP version 8.1.0, ho Wever version 8.1.2 is available. You should consider upgrading via the ' pip install--upgrade pip ' command.


Zabbix-api Use Demo:

Host.exists:

Website Introduction:

Request:

{     "Jsonrpc":  "2.0",     "method":  "Host.exists",      "params": {         "host":  "zabbix  Server ",        " Nodeids ": [              "1"         ]     },     "auth":  "038e1d7b1735c6a5436ee9eae095879e",     "id":  1} 

Response:

{"JSONRPC": "2.0", "result": true, "id": 1}


How to use Zabbix-api to query whether a host exists?

Write a Python script that reads as follows:

Vim host_exists.py

#!/usr/bin/python#coding:utf-8from zabbix_api Import zabbixapiserver = "Http://172.16.206.131/zabbix" username = " Admin "Password =" Zabbix "Zapi = Zabbixapi (Server=server, path=" ", log_level=0) zapi.login (username, password) result = Zapi.host.exists ({"Host": "Zabbix Server"}) print result


Run the script and get the result

[[email protected] scripts]#./host_exists.py True

Indicates that the host exists


Zabbix also provides a number of ways to get information, crossing Internet cafes.





This article is from the "Zengestudy" blog, make sure to keep this source http://zengestudy.blog.51cto.com/1702365/1787080

3, Zabbix-api use

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.