Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update zhostupdater.py || compatible python2 & 3 || added -n argument from PR#18 #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions zghostfinder.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/env python
#
# adapted for pythonV3
# import needed modules.
# pyzabbix is needed, see https://github.com/lukecyca/pyzabbix
#
import argparse
import ConfigParser
try:
from configparser import ConfigParser
except ImportError:
from ConfigParser import SafeConfigParser as ConfigParser
import os
import os.path
import sys
Expand All @@ -16,13 +19,13 @@ def ConfigSectionMap(section):
dict1 = {}
options = Config.options(section)
for option in options:
try:
dict1[option] = Config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
try:
dict1[option] = Config.get(section, option)
if dict1[option] == -1:
print("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1


Expand Down Expand Up @@ -57,7 +60,7 @@ def ConfigSectionMap(section):
args = parser.parse_args()

# load config module
Config = ConfigParser.ConfigParser()
Config = ConfigParser()
Config

# if configuration argument is set, test the config file
Expand Down Expand Up @@ -109,7 +112,7 @@ def ConfigSectionMap(section):
zapi.session.verify = False

# Login to the Zabbix API
zapi.login(username, password)
zapi = ZabbixAPI(url=api, user=username, password=password)

##################################
# Start actual API logic
Expand All @@ -134,12 +137,12 @@ def ConfigSectionMap(section):
else:
if args.numeric:
# print host ids
for host in hosts:
print(format(host["hostid"]))
for host in hosts:
print(format(host["hostid"]))
else:
# print host names
for host in hosts:
print(format(host["host"]))
# print host names
for host in hosts:
print(format(host["host"]))
else:
sys.exit("Error: No hosts in hostgroup \""+ group_name + "\"")
else:
Expand Down
Loading