Пример #1
0
def main():
    from splunklib.searchcommands import csv as splunkcsv

    del splunkcsv

    import splunk.Intersplunk

    from r_utils import get_service, read_fieldnames_from_command_input

    try:
        # check execution mode: it could be 'getinfo' to get some information about
        # how to execute the actual command
        (isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)
        if isgetinfo:
            splunk.Intersplunk.outputInfo(
                streaming=False,  # because it only runs on a search head
                generating=False,
                retevs=False,
                reqsop=False,
                preop=None,
                timeorder=True,
                clear_req_fields=False,
                req_fields=None)

        # read command arguments
        # keywords, kvs = splunk.Intersplunk.getKeywordsAndOptions()
        if len(sys.argv) < 2:
            raise Exception("Missing actual R script parameter")
        command_argument = sys.argv[1]

        # read header, fieldnames, and events from input stream
        input_data = StringIO()
        shutil.copyfileobj(sys.stdin, input_data)
        input_data.seek(0)
        fieldnames = read_fieldnames_from_command_input(input_buf=input_data)
        input_data.seek(0)
        settings = {}
        input_events = splunk.Intersplunk.readResults(input_data, settings)

        # connect to splunk using SDK
        service = get_service(settings['infoPath'])

        header, rows = r(service,
                         input_events,
                         command_argument,
                         fieldnames=fieldnames)
        splunk.Intersplunk.outputResults(rows, fields=header)

    except r_errors.Error as e:
        splunk.Intersplunk.outputResults(
            splunk.Intersplunk.generateErrorResults(str(e)))

    except Exception as e:
        splunk.Intersplunk.outputResults(
            splunk.Intersplunk.generateErrorResults(
                str(e) + ": " + traceback.format_exc()))
Пример #2
0
Файл: r.py Проект: Ismael-VC/r
def main():
    from splunklib.searchcommands import csv as splunkcsv

    del splunkcsv

    import splunk.Intersplunk

    from r_utils import get_service, read_fieldnames_from_command_input

    try:
        # check execution mode: it could be 'getinfo' to get some information about
        # how to execute the actual command
        (isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)
        if isgetinfo:
            splunk.Intersplunk.outputInfo(
                streaming=False,  # because it only runs on a search head
                generating=False,
                retevs=False,
                reqsop=False,
                preop=None,
                timeorder=True,
                clear_req_fields=False,
                req_fields=None
            )

        # read command arguments
        # keywords, kvs = splunk.Intersplunk.getKeywordsAndOptions()
        if len(sys.argv) < 2:
            raise Exception("Missing actual R script parameter")
        command_argument = sys.argv[1]

        # read header, fieldnames, and events from input stream
        input_data = StringIO()
        shutil.copyfileobj(sys.stdin, input_data)
        input_data.seek(0)
        fieldnames = read_fieldnames_from_command_input(input_buf=input_data)
        input_data.seek(0)
        settings = {}
        input_events = splunk.Intersplunk.readResults(input_data, settings)

        # connect to splunk using SDK
        service = get_service(settings['infoPath'])

        header, rows = r(service,
                         input_events,
                         command_argument,
                         fieldnames=fieldnames)
        splunk.Intersplunk.outputResults(rows, fields=header)

    except r_errors.Error as e:
        splunk.Intersplunk.outputResults(splunk.Intersplunk.generateErrorResults(str(e)))

    except Exception as e:
        splunk.Intersplunk.outputResults(
            splunk.Intersplunk.generateErrorResults(str(e) + ": " + traceback.format_exc()))
Пример #3
0
def main():
    from splunklib.searchcommands import csv as splunkcsv

    del splunkcsv

    import splunk.Intersplunk

    from r_utils import get_service

    try:
        # check execution mode: it could be 'getinfo' to get some information about
        # how to execute the actual command
        (isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)
        if isgetinfo:
            splunk.Intersplunk.outputInfo(
                streaming=False,  # because it only runs on a search head
                generating=False,
                retevs=False,
                reqsop=False,
                preop=None,
                timeorder=True,
                clear_req_fields=False,
                req_fields=None
            )

        # read command arguments
        # keywords, kvs = splunk.Intersplunk.getKeywordsAndOptions()
        if len(sys.argv) != 1:
            raise Exception("No parameter allowed")

        # read header, fieldnames, and events from input stream
        settings = {}
        splunk.Intersplunk.readResults(sys.stdin, settings)

        # connect to splunk using SDK
        service = get_service(settings['infoPath'])

        r_stats(service)
        splunk.Intersplunk.outputResults([])

    except r_errors.Error as e:
        splunk.Intersplunk.outputResults(splunk.Intersplunk.generateErrorResults(str(e)))

    except Exception as e:
        splunk.Intersplunk.outputResults(
            splunk.Intersplunk.generateErrorResults(str(e) + ": " + traceback.format_exc()))