Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
308026f2
Commit
308026f2
authored
Aug 22, 2013
by
René Moser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved zabbix inventory. added sys.exit(1) where needed, added some exception handling.
parent
500e6fa3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
11 deletions
+30
-11
plugins/inventory/zabbix.ini
+3
-3
plugins/inventory/zabbix.py
+27
-8
No files found.
plugins/inventory/zabbix.ini
View file @
308026f2
...
...
@@ -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
plugins/inventory/zabbix.py
View file @
308026f2
#!/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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment