Commit dde7dd0a authored by Olav Morken's avatar Olav Morken
Browse files

Add get-ssl-tests command

parent dee390c3
......@@ -2,6 +2,7 @@
import argparse
from collections import defaultdict
import datetime
import functools
import getpass
import ipaddress
import json
......@@ -12,6 +13,7 @@ import socket
import statistics
import sys
import time
import typing
auth = None
......@@ -118,6 +120,43 @@ def get_item(args):
print() # Add trailing newline
def get_ssl_tests(args: argparse.Namespace) -> None:
def _get_host_or_template(hostortempalteid: int) -> dict:
for host in invoke('host.get', hostids=str(hostortempalteid), selectMacros='extend', selectParentTemplates='extend'):
return host
for template in invoke('template.get', templateids=str(hostortempalteid), selectMacros='extend', selectParentTemplates='extend'):
return template
raise Exception(f'Could not find host or template with id {hostortempalteid}')
@functools.lru_cache
def _get_macros(hostortempalteid: int) -> typing.Dict[str, str]:
data = _get_host_or_template(hostortempalteid)
ret: typing.Dict[str, str] = {macro['macro']: macro['value'] for macro in data['macros']}
for template in data['parentTemplates']:
ret = {
**_get_macros(template['templateid']),
**ret,
}
return ret
def _check_item(*, item: dict) -> None:
if int(item['type']) != ITEM_TYPE_MAP['external']:
return
key = item['key_']
if not key.startswith('ssl_test_venv.sh['):
return
def _resolve_macro(m: re.Match) -> str:
macro = m.group(1)
macros = _get_macros(int(item['hostid']))
return macros.get(macro, f'UNKNOWN({macro})')
key = re.sub(r'(\{\$\w+\})', _resolve_macro, key)
print('https://zabbix.uninett.no/zabbix/items.php?form=update&hostid={hostid}&itemid={itemid} {key}'.format(hostid=item['hostid'], itemid=item['itemid'], key=key))
for template in invoke('template.get'):
for item in invoke('item.get', templateids=template['templateid']):
_check_item(item=item)
for host in invoke('host.get'):
for item in invoke('item.get', hostids=host['hostid']):
_check_item(item=item)
def get_web_tests(args):
if not args.include_inherited:
web_test_filter = {'inherited': False}
......@@ -427,6 +466,8 @@ def parse_args():
parser_get_item = subparsers.add_parser('get-item', help='Get item by ID')
parser_get_item.add_argument('itemid', type=int, help='Item ID')
parser_get_ssl_tests = subparsers.add_parser('get-ssl-tests', help='Get SSL tests')
parser_get_web_tests = subparsers.add_parser('get-web-tests', help='Get Web tests')
parser_get_web_tests.add_argument('--include-inherited', action='store_true', help='Include inherited items in output')
......@@ -469,6 +510,8 @@ def main():
return login()
elif args.command == 'get-items':
return get_items(args)
elif args.command == 'get-ssl-tests':
return get_ssl_tests(args)
elif args.command == 'dump-vkilo':
return dump_vkilo()
elif args.command == 'get-item':
......
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