diff options
author | James Cammarata <jimi@sngx.net> | 2013-08-22 16:03:17 -0500 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2013-08-22 16:03:17 -0500 |
commit | 268f171ee47e3d4d250deb0e8d4e7fa0b2c6342b (patch) | |
tree | e14aaa7df541944401731b519a4596c8c7a56c6e /plugins | |
parent | 7bd8c18fa745b041a22eb2300cad34c70b74d41d (diff) | |
parent | 308026f234a4373f5f046815a92e13e434a047a1 (diff) | |
download | ansible-268f171ee47e3d4d250deb0e8d4e7fa0b2c6342b.tar.gz |
Merge branch 'feature/zabbix-inventory' of https://github.com/resmo/ansible into devel
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/inventory/zabbix.ini | 6 | ||||
-rwxr-xr-x | plugins/inventory/zabbix.py | 34 |
2 files changed, 30 insertions, 10 deletions
diff --git a/plugins/inventory/zabbix.ini b/plugins/inventory/zabbix.ini index 7dd02430f8..618c2b9fe8 100644 --- a/plugins/inventory/zabbix.ini +++ b/plugins/inventory/zabbix.ini @@ -4,8 +4,8 @@ [zabbix] # Server location -server = http://192.168.0.1/zabbix +server = http://zabbix.example.com/zabbix # Login -username = -password = +username = admin +password = zabbix diff --git a/plugins/inventory/zabbix.py b/plugins/inventory/zabbix.py index f3f3652aad..a161c63aea 100755 --- a/plugins/inventory/zabbix.py +++ b/plugins/inventory/zabbix.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # (c) 2013, Greg Buehler # @@ -20,16 +20,26 @@ ###################################################################### """ -Zabbix external inventory script. Returns hosts and hostgroups from Zabbix. +Zabbix Server external inventory script. +======================================== +Returns hosts and hostgroups from Zabbix Server. +Configuration is read from `zabbix.ini`. + +Tested with Zabbix Server 2.0.6. """ import os, sys import json import argparse import ConfigParser -from zabbix_api import ZabbixAPI + +try: + from zabbix_api import ZabbixAPI +except: + print "Error: Zabbix API library must be installed: pip install zabbix-api." + sys.exit(1) try: import json @@ -97,8 +107,12 @@ class ZabbixInventory(object): self.read_cli() if self.zabbix_server and self.zabbix_username: - api = ZabbixAPI(server=self.zabbix_server) - api.login(user=self.zabbix_username, password=self.zabbix_password) + try: + api = ZabbixAPI(server=self.zabbix_server) + api.login(user=self.zabbix_username, password=self.zabbix_password) + except BaseException, e: + print "Error: Could not login to Zabbix server. Check your zabbix.ini." + sys.exit(1) if self.options.host: data = self.get_host(api, self.options.host) @@ -107,7 +121,13 @@ class ZabbixInventory(object): elif self.options.list: data = self.get_list(api) print json.dumps(data, indent=2) + + else: + print "usage: --list ..OR.. --host <hostname>" + sys.exit(1) + else: - print "Configuration of server and credentials is required" + print "Error: Configuration of server and credentials are required. See zabbix.ini." + sys.exit(1) -ZabbixInventory()
\ No newline at end of file +ZabbixInventory() |