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
500e6fa3
Commit
500e6fa3
authored
11 years ago
by
Greg Buehler
Committed by
Rene Moser
11 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Zabbix inventory plugin
parent
10a0f03c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
0 deletions
+125
-0
plugins/inventory/zabbix.ini
+11
-0
plugins/inventory/zabbix.py
+114
-0
No files found.
plugins/inventory/zabbix.ini
0 → 100644
View file @
500e6fa3
# Ansible Zabbix external inventory script settings
#
[zabbix]
# Server location
server
=
http://192.168.0.1/zabbix
# Login
username
=
password =
This diff is collapsed.
Click to expand it.
plugins/inventory/zabbix.py
0 → 100755
View file @
500e6fa3
#!/usr/bin/python
# (c) 2013, Greg Buehler
#
# This file is part of Ansible,
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
######################################################################
"""
Zabbix external inventory script. Returns hosts and hostgroups from Zabbix.
"""
import
os
,
sys
import
json
import
argparse
import
ConfigParser
from
zabbix_api
import
ZabbixAPI
try
:
import
json
except
:
import
simplejson
as
json
class
ZabbixInventory
(
object
):
def
read_settings
(
self
):
config
=
ConfigParser
.
SafeConfigParser
()
config
.
read
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
+
'/zabbix.ini'
)
# server
if
config
.
has_option
(
'zabbix'
,
'server'
):
self
.
zabbix_server
=
config
.
get
(
'zabbix'
,
'server'
)
# login
if
config
.
has_option
(
'zabbix'
,
'username'
):
self
.
zabbix_username
=
config
.
get
(
'zabbix'
,
'username'
)
if
config
.
has_option
(
'zabbix'
,
'password'
):
self
.
zabbix_password
=
config
.
get
(
'zabbix'
,
'password'
)
def
read_cli
(
self
):
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--host'
)
parser
.
add_argument
(
'--list'
,
action
=
'store_true'
)
self
.
options
=
parser
.
parse_args
()
def
hoststub
(
self
):
return
{
'hosts'
:
[]
}
def
get_host
(
self
,
api
,
name
):
data
=
{}
return
data
def
get_list
(
self
,
api
):
hostsData
=
api
.
host
.
get
({
'output'
:
'extend'
,
'selectGroups'
:
'extend'
})
data
=
{}
data
[
self
.
defaultgroup
]
=
self
.
hoststub
()
for
host
in
hostsData
:
hostname
=
host
[
'name'
]
data
[
self
.
defaultgroup
][
'hosts'
]
.
append
(
hostname
)
for
group
in
host
[
'groups'
]:
groupname
=
group
[
'name'
]
if
not
groupname
in
data
:
data
[
groupname
]
=
self
.
hoststub
()
data
[
groupname
][
'hosts'
]
.
append
(
hostname
)
return
data
def
__init__
(
self
):
self
.
defaultgroup
=
'group_all'
self
.
zabbix_server
=
None
self
.
zabbix_username
=
None
self
.
zabbix_password
=
None
self
.
read_settings
()
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
)
if
self
.
options
.
host
:
data
=
self
.
get_host
(
api
,
self
.
options
.
host
)
print
json
.
dumps
(
data
,
indent
=
2
)
elif
self
.
options
.
list
:
data
=
self
.
get_list
(
api
)
print
json
.
dumps
(
data
,
indent
=
2
)
else
:
print
"Configuration of server and credentials is required"
ZabbixInventory
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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