Commit 3645323d authored by Sigmund Augdal's avatar Sigmund Augdal

pep8 whitespace fixes and config to accept a bit longer lines

parent 608137ba
[flake8]
max-line-length = 120
......@@ -10,6 +10,7 @@ base_dir = os.path.dirname(os.path.realpath(__file__))
auth = None
def get_auth():
try:
with open(os.path.join(base_dir, '.zabbixauth'), 'r') as fh:
......@@ -17,6 +18,7 @@ def get_auth():
except:
return None
def invoke(method, **kwargs):
message = {
"jsonrpc": "2.0",
......@@ -37,6 +39,7 @@ def invoke(method, **kwargs):
raise Exception('Invalid response from Zabbix: {response}'.format(response=repr(response)))
return response['result']
def login():
username = input('Username: ')
password = getpass.getpass()
......@@ -44,6 +47,7 @@ def login():
with open(os.path.join(base_dir, '.zabbixauth'), 'w') as fh:
fh.write(result + "\n")
def get_items(args):
if not args.include_inherited:
item_filter = {'inherited': False}
......@@ -66,15 +70,17 @@ def get_items(args):
continue
print('https://zabbix.uninett.no/zabbix/items.php?form=update&hostid={hostid}&itemid={itemid} {key}'.format(hostid=item['hostid'], itemid=item['itemid'], key=item['key_']))
def dump_vkilo():
ilo_template = 10874
template = invoke('template.get', templateids=ilo_template)
ilohosts = invoke('host.get', templateids=ilo_template, selectMacros='extend')
for host in ilohosts:
vkilo = [ macro['value'] for macro in host['macros'] if macro['macro'] == '{$VKILO}' ]
vkilo = [macro['value'] for macro in host['macros'] if macro['macro'] == '{$VKILO}']
vkilo = vkilo[0] if vkilo else None
print('https://zabbix.uninett.no/zabbix/hosts.php?form=update&hostid={hostid}'.format(hostid=host['hostid']), host['host'], vkilo)
def get_item(args):
items = invoke('item.get', itemids=args.itemid)
if not items:
......@@ -82,7 +88,8 @@ def get_item(args):
sys.exit(1)
item = items[0]
json.dump(item, sys.stdout, sort_keys=True, indent=4)
print() # Add trailing newline
print() # Add trailing newline
def get_web_tests(args):
if not args.include_inherited:
......@@ -96,18 +103,21 @@ def get_web_tests(args):
print('#{index} {url}'.format(index=index, url=step['url']))
print()
def get_unreachable():
for host in invoke('host.get'):
if int(host['available']) != 2:
continue # Host is up
continue # Host is up
url = 'https://zabbix.uninett.no/zabbix/hosts.php?form=update&hostid={hostid}'.format(hostid=host['hostid'])
print(url, host['name'], host['error'])
def get_hosts():
for host in invoke('host.get'):
url = 'https://zabbix.uninett.no/zabbix/hosts.php?form=update&hostid={hostid}'.format(hostid=host['hostid'])
print(url, host['name'])
def parse_args():
parser = argparse.ArgumentParser('Zabbix cmd line client')
subparsers = parser.add_subparsers(help='Command', dest='command')
......@@ -126,6 +136,7 @@ def parse_args():
parser_get_hosts = subparsers.add_parser('get-hosts', help='Get hosts')
return parser.parse_args()
def main():
args = parse_args()
if args.command == 'login':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment