Seek a python script through zabbix api to list hosts?
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Seek a python script through zabbix api to list hosts?
hello everyone!I have met a question.I want to edit a script through zabbix api to list all the host?
Seek a python script through zabbix api to list host?
Last edited by 624867243@qq.com; 02-26-2016 at 09:06 PM.
hello everyone!I have met a question.I want to edit a script through zabbix api to list all the host?
Seek a python script through zabbix api to list host?
...and...
Quote:
Originally Posted by 624867243@qq.com
no one know that?
Yes, I'm sure someone knows...there are many people who write python scripts. We will be happy to help you with a script or error(s), so post what you've written/tried/done on your own, and we can help. But we will NOT write things for you. Read the "Question Guidelines" link in my posting signature.
Yes, I'm sure someone knows...there are many people who write python scripts. We will be happy to help you with a script or error(s), so post what you've written/tried/done on your own, and we can help. But we will NOT write things for you. Read the "Question Guidelines" link in my posting signature.
thank you for your remind,I have solved it .
Code:
#coding:utf-8
import json
import urllib2
url = "http://zabbix.knight.ren/api_jsonrpc.php"
header = {"Content-Type": "application/json"}
# request json
data = json.dumps(
{
"jsonrpc":"2.0",
"method":"host.get",
"params":{
"output":["hostid","name"],
"filter":{"host":""}
},
"auth":"8c67fd696eb3a6a877569b9bc34d6c22",
"id":1,
})
# create request object
request = urllib2.Request(url,data)
for key in header:
request.add_header(key,header[key])
# get host list
try:
result = urllib2.urlopen(request)
except URLError as e:
if hasattr(e, 'reason'):
print 'We failed to reach a server.'
print 'Reason: ', e.reason
elif hasattr(e, 'code'):
print 'The server could not fulfill the request.'
print 'Error code: ', e.code
else:
response = json.loads(result.read())
result.close()
print "Number Of Hosts: ", len(response['result'])
for host in response['result']:
print "Host ID:",host['hostid'],"Host Name:",host['name']
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.