#!/usr/bin/env python3
#
# Convert an snmpget test specification to command-line options

import pscheduler

from validate import spec_is_valid

spec = pscheduler.json_load(exit_on_error=True)

valid, message = spec_is_valid(spec)

if not valid:
    pscheduler.fail(message)

# concatenate oids
try:
    oid_list = spec['oid']
except KeyError:
    pscheduler.fail("Must query at least one OID.")
oid_str = ""
for item in oid_list:
    oid_str = "%s,%s" % (oid_str, item)
spec['oid'] = oid_str

result = pscheduler.speccli_build_args(spec, 
                                       strings=[
        # Strings
        ( 'host', 'host' ),
        ( 'host-node', 'host-node' ),
        ( 'dest', 'dest' ),
        ('oid', 'oid'),
        ( 'protocol', 'protocol'),
        ('community', 'community'),
        ('version', 'version'),
        ( 'period', 'period' ),
        ( 'polls', 'polls' ),
        ( 'timeout', 'timeout' ),
        ( 'auth-protocol', 'auth-protocol'),
        ( 'security-name', 'security-name'),
        ( 'priv-protocol', 'priv-protocol'),
        ( 'auth-key', 'auth-key'),
        ( 'priv-key', 'priv-key'),
        ( 'security-level', 'security-level'),
        ( 'context', 'context')
        ])


pscheduler.succeed_json(result)
