コード例 #1
0
def datastream_raw(args):

    path = inspect.getframeinfo(inspect.currentframe()).function
    thread = Analytics().async_send_analytics(path=path, debug=args.debug)

    fetch = DataStreamFetch()
    queryresult = QueryResult("datastream_raw")

    logType = "raw"

    checkFilterArgs(args, queryresult)
    (_, jsonObj) = fetch.fetchLogs(edgerc=args.edgerc,
                                   section=args.section,
                                   streamId=args.streamId,
                                   timeRange=args.timeRange,
                                   logType=logType,
                                   offsetMinutes=args.offset,
                                   debug=args.debug)

    thread.join()
    return handleresponse(args,
                          jsonObj,
                          queryresult,
                          RequireAll=False,
                          HideHeader=True,
                          Debug=args.debug)
コード例 #2
0
def groupcpcodelist(args):

    path = inspect.getframeinfo(inspect.currentframe()).function
    thread = Analytics().async_send_analytics(path=path, debug=args.debug)

    fetch = CPCODEFetch()
    queryresult = QueryResult("groupcpcodelist")

    checkFilterArgs(args, queryresult)

    if args.only_contractIds is not None and len(args.only_contractIds) > 0:
        (_, jsonObj) = fetch.fetchGroupCPCODES(
            edgerc=args.edgerc,
            section=args.section,
            account_key=args.account_key,
            onlycontractIds=args.only_contractIds,
            debug=args.debug,
        )
    else:
        (_, jsonObj) = fetch.fetchGroupCPCODES(edgerc=args.edgerc,
                                               section=args.section,
                                               account_key=args.account_key,
                                               debug=args.debug)

    thread.join()
    return handleresponse(args, jsonObj, queryresult, Debug=args.debug)
コード例 #3
0
def filtertemplate(args):

    path = inspect.getframeinfo(inspect.currentframe()).function
    thread = Analytics().async_send_analytics(path=path)

    return_value = 0

    if args.type is None and args.filterfile is None:
        print("template type is required. here is a list of options",
              file=sys.stderr)
        queryType = QueryResult(args.type)
        obj = queryType.listQueryTypes()

    else:

        queryType = QueryResult(args.type)
        obj = queryType.listQueryTypes()

        if args.type in obj or args.filterfile is not None:

            templateArgs = args.arg_list

            if templateArgs is None:
                templateArgs = []

            if args.args_use_stdin:

                stdinStr = getArgFromSTDIN()
                output = stdinStr.split("\n")
                templateArgs.extend(output)

            if "filterfile" in vars(args) and args.filterfile is not None:
                obj = queryType.loadTemplate(args.get,
                                             templateArgs=templateArgs,
                                             templatefile=args.filterfile)
            else:
                obj = queryType.loadTemplate(args.get,
                                             templateArgs=templateArgs)

        else:
            print("template type: {} not found. ".format(args.type),
                  file=sys.stderr)
            return_value = 1

    print(json.dumps(obj, indent=1))

    thread.join()
    return return_value
コード例 #4
0
def netstorageuser(args):

    path = inspect.getframeinfo(inspect.currentframe()).function
    thread = Analytics().async_send_analytics(path=path, debug=args.debug)

    fetch = NetStorageFetch()
    queryresult = QueryResult("netstorageuser")

    checkFilterArgs(args, queryresult)
    (_, jsonObj) = fetch.fetchNetStorageUsers(edgerc=args.edgerc,
                                              section=args.section,
                                              account_key=args.account_key,
                                              debug=args.debug)

    thread.join()
    return handleresponse(args, jsonObj, queryresult, Debug=args.debug)
コード例 #5
0
def ldslist(args):

    path = inspect.getframeinfo(inspect.currentframe()).function
    thread = Analytics().async_send_analytics(path=path, debug=args.debug)

    fetch = LdsFetch()
    queryresult = QueryResult("ldslist")

    checkFilterArgs(args, queryresult)
    (_, jsonObj) = fetch.fetchCPCodeProducts(edgerc=args.edgerc,
                                             section=args.section,
                                             account_key=args.account_key,
                                             debug=args.debug)

    thread.join()
    return handleresponse(args, jsonObj, queryresult, Debug=args.debug)
コード例 #6
0
def bulksearchtemplate(args):

    path = inspect.getframeinfo(inspect.currentframe()).function
    thread = Analytics().async_send_analytics(path=path, debug=args.debug)

    return_value = 0
    searchType = "bulksearch"
    serverside = True

    if args.get is None and args.searchfile is None:

        print("template name is required. here is a list of options",
              file=sys.stderr)
        queryType = QueryResult(searchType)
        obj = queryType.listQueryTypes(serverside=serverside)

    else:

        queryType = QueryResult(searchType)
        obj = queryType.loadTemplate(args.get, serverside=serverside)

        templateArgs = args.arg_list

        if templateArgs is None:
            templateArgs = []

        if "searchfile" in vars(args) and args.searchfile is not None:
            obj = queryType.loadTemplate(args.get,
                                         templateArgs=templateArgs,
                                         serverside=serverside,
                                         templatefile=args.searchfile)
        else:
            obj = queryType.loadTemplate(args.get,
                                         templateArgs=templateArgs,
                                         serverside=serverside)

    print(json.dumps(obj, indent=1))
    thread.join()
    return return_value
コード例 #7
0
def bulksearch(args):

    path = inspect.getframeinfo(inspect.currentframe()).function
    thread = Analytics().async_send_analytics(path=path, debug=args.debug)

    fetch = PropertyManagerFetch()
    queryresult = QueryResult("bulksearch")
    serverside = True

    if args.use_searchstdin and args.use_filterstdin:
        raise ValueError(
            "Both args.use_searchstdin and args.use_filterstdin maynot be True"
        )

    if args.use_searchstdin or args.searchfile is not None:
        if (args.use_searchstdin):
            inputString = getArgFromSTDIN()
        else:
            inputString = getArgFromFile(args.searchfile)

        postdata = queryresult.loadJson(inputString)

        if not queryresult.isJsonServerSide(postdata):
            postdataStr = json.dumps(postdata)
            print("Search JSON Format Error:\n{}".format(postdataStr),
                  file=sys.stderr)
            raise ValueError("bulksearch JSON is not correct format")

    elif args.searchname is not None:
        postdata = queryresult.loadTemplate(args.searchname,
                                            serverside=serverside)

        if isinstance(postdata, list):
            print("Error: choose from one of these:", file=sys.stderr)
            printJsonStr = json.dumps(postdata, indent=1)
            print(printJsonStr, file=sys.stderr)
            raise ValueError("{} not found".format(args.searchname))

    else:
        postdata = queryresult.loadTemplate("default.json",
                                            serverside=serverside)

    checkFilterArgs(args, queryresult)

    if args.network is not None and (not args.network.startswith("p")
                                     and not args.network.startswith("P")
                                     and not args.network.startswith("s")
                                     and not args.network.startswith("S")):
        args.network = None

    (_, jsonObj) = fetch.bulksearch(edgerc=args.edgerc,
                                    section=args.section,
                                    account_key=args.account_key,
                                    postdata=postdata,
                                    contractId=args.contractId,
                                    network=args.network,
                                    debug=args.debug)

    thread.join()
    RequireAll = not args.use_union_filter
    HideHeader = args.skip_header
    SkipConcat = not args.show_nested_list

    return handleresponse(args,
                          jsonObj,
                          queryresult,
                          RequireAll=RequireAll,
                          HideHeader=HideHeader,
                          concatForJQCSV=SkipConcat,
                          Debug=args.debug)
コード例 #8
0
def checkhostdns(args):
    path = inspect.getframeinfo(inspect.currentframe()).function
    thread = Analytics().async_send_analytics(path=path, debug=args.debug)

    queryresult = QueryResult("doh")

    if args.domain is None or len(args.domain) < 1:
        print("... waiting for domain list or json docs from stdin...",
              file=sys.stderr)
        stdinStr = getArgFromSTDIN()
        print("... got list from user input...", file=sys.stderr)
        stdinStr = str.rstrip(stdinStr)
        lines = stdinStr.split(os.linesep)

    else:
        lines = args.domain

    checkFilterArgs(args, queryresult)

    updatedLines = None
    for dns in lines:
        split = [" ", ","]
        splitCharFound = [e for e in split if e in dns]

        if len(splitCharFound) > 0:

            if updatedLines is None:
                updatedLines = list()

            for split in splitCharFound:

                newDns = str.strip(dns)
                updatedLines.extend(newDns.split(split))
        else:
            if updatedLines is None:
                updatedLines = list()

            updatedLines.append(dns)

    if updatedLines is not None:
        lines = updatedLines

    fetchDNS = Fetch_DNS()

    if args.debug:
        print(" ... debug: domain list: {}".format(lines), file=sys.stderr)

    if len(lines) > 1:
        print(" ... querying {} domains ".format(len(lines)),
              file=sys.stderr,
              end="")
        sys.stderr.flush()

    elif len(lines) == 1:
        print(" ... querying {} domain ".format(len(lines)),
              file=sys.stderr,
              end="")
        sys.stderr.flush()

    def printStatus():
        print(".", end="", file=sys.stderr)
        sys.stderr.flush()

    jsonObj = fetchDNS.loadDNSfromHostList(
        lines,
        recoredType=None,
        progressTickHandler=printStatus,
        skipWildcardDomains=args.skip_wildcards)
    print("", file=sys.stderr)

    if "resolution" in jsonObj:
        jsonObj = jsonObj["resolution"]
        thread.join()
        return handleresponse(args,
                              jsonObj,
                              queryresult,
                              enableSTDIN=False,
                              RequireAll=False,
                              Debug=args.debug)
    else:
        print("... something went wrong with response", file=sys.stderr)
        return 1
コード例 #9
0
def checkjsondns(args):

    configFilters = [
        "configsWithCNAME", "configsFullyCNAMED", "configsWithoutCNAME",
        "configsAllNXDomain", "configsAnyNXDomain"
    ]
    hostFilters = ["hostsNXDOMAIN", "hostsCNAMED", "hostsNotCNAMED"]

    filterbychoices = []
    filterbychoices.extend(configFilters)
    filterbychoices.extend(hostFilters)

    if args.dns_filter not in filterbychoices:
        print("... filterby positional arg must be one of {}...".format(
            filterbychoices),
              file=sys.stderr)
        return 1

    path = inspect.getframeinfo(inspect.currentframe()).function
    thread = Analytics().async_send_analytics(path=path, debug=args.debug)

    print("... waiting for json docs from stdin...", file=sys.stderr)
    stdinStr = getArgFromSTDIN()
    print("... got list from user input...", file=sys.stderr)
    stdinStr = str.rstrip(stdinStr)
    lines = stdinStr.split(os.linesep)

    print("... accepting JSON input and skipping any template output",
          file=sys.stderr)

    try:
        args.dns_index = int(args.dns_index)

    except ValueError:
        print("... domain index must be an int {}".format(args.dns_index),
              file=sys.stderr)
        return 1

    def printStatus():
        print(".", end="", file=sys.stderr)
        sys.stderr.flush()

    fetchDNS = Fetch_DNS()

    if args.dns_filter == "hostsNotCNAMED":
        jsonObj = fetchDNS.filterDNSInput(
            lines,
            fetchDNS.hostsNotCNAMED,
            arrayHostIndex=args.dns_index,
            skipWildcardDomains=args.skip_wildcards,
            progressTickHandler=printStatus)

    elif args.dns_filter == "hostsNXDOMAIN":
        jsonObj = fetchDNS.filterDNSInput(
            lines,
            fetchDNS.hostsNXDOMAIN,
            arrayHostIndex=args.dns_index,
            skipWildcardDomains=args.skip_wildcards,
            progressTickHandler=printStatus)

    elif args.dns_filter == "hostsCNAMED":
        jsonObj = fetchDNS.filterDNSInput(
            lines,
            fetchDNS.hostsCNAMED,
            arrayHostIndex=args.dns_index,
            skipWildcardDomains=args.skip_wildcards,
            progressTickHandler=printStatus)

    elif args.dns_filter == "configsWithCNAME":
        jsonObj = fetchDNS.filterDNSInput(
            lines,
            fetchDNS.configsWithCNAME,
            arrayHostIndex=args.dns_index,
            skipWildcardDomains=args.skip_wildcards,
            progressTickHandler=printStatus)

    elif args.dns_filter == "configsWithoutCNAME":
        jsonObj = fetchDNS.filterDNSInput(
            lines,
            fetchDNS.configsWithoutCNAME,
            arrayHostIndex=args.dns_index,
            skipWildcardDomains=args.skip_wildcards,
            progressTickHandler=printStatus)

    elif args.dns_filter == "configsFullyCNAMED":
        jsonObj = fetchDNS.filterDNSInput(
            lines,
            fetchDNS.configsFullyCNAME,
            arrayHostIndex=args.dns_index,
            skipWildcardDomains=args.skip_wildcards,
            progressTickHandler=printStatus)

    elif args.dns_filter == "configsAllNXDomain":
        jsonObj = fetchDNS.filterDNSInput(
            lines,
            fetchDNS.configsAllNXDomain,
            arrayHostIndex=args.dns_index,
            skipWildcardDomains=args.skip_wildcards,
            progressTickHandler=printStatus)

    elif args.dns_filter == "configsAnyNXDomain":
        jsonObj = fetchDNS.filterDNSInput(
            lines,
            fetchDNS.configsAnyNXDomain,
            arrayHostIndex=args.dns_index,
            skipWildcardDomains=args.skip_wildcards,
            progressTickHandler=printStatus)

    else:
        print("Error filterby mapping not setup. Got: {}".format(
            args.dns_filter),
              file=sys.stderr)
        thread.join()
        return 1

    printResponse(jsonObj, JSONOutput=True)
    thread.join()
    return 0