Commit e77720a6 authored by Sigmund Augdal's avatar Sigmund Augdal

Added subcommand to list triggers by severity

parent 2e22daaf
......@@ -12,6 +12,15 @@ base_dir = os.path.dirname(os.path.realpath(__file__))
auth = None
SEVERITIES = {
"not_classified": 0,
"information": 1,
"warning": 2,
"average": 3,
"high": 4,
"disaster": 5,
}
def get_auth():
try:
......@@ -242,6 +251,18 @@ def find_empty(args):
print(" - {template}".format(template=template['name']))
def get_triggers(args):
rseverities = {v: k for k, v in SEVERITIES.items()}
print("Triggers with severity {severity} or higher:".format(severity=args.severity))
for trigger in invoke('trigger.get', selectHosts=['name'], min_severity=SEVERITIES[args.severity]):
description = trigger['description']
severity = rseverities[int(trigger['priority'])]
for host in trigger['hosts']:
print(" - {severity} {host}: {trigger}".format(host=host['name'], trigger=description, severity=severity))
if len(trigger['hosts']) < 1:
print(" - {severity} NOHOST: {trigger}".format(trigger=description, severity=severity))
def parse_args():
parser = argparse.ArgumentParser('Zabbix cmd line client')
subparsers = parser.add_subparsers(help='Command', dest='command')
......@@ -279,6 +300,9 @@ def parse_args():
find_empty = subparsers.add_parser('find-empty', help="Find empty host groups")
triggers = subparsers.add_parser('get-triggers', help="List triggers")
triggers.add_argument('--severity', choices=SEVERITIES.keys(), help="Minimum severity to include")
return parser.parse_args()
......@@ -304,6 +328,8 @@ def main():
return check_kind(args)
elif args.command == 'find-empty':
return find_empty(args)
elif args.command == 'get-triggers':
return get_triggers(args)
else:
raise NotImplementedError('Unknown command: {command}'.format(command=args.command))
......
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