Module Expr Str Import alias Import alias Import alias Import alias Import alias Import alias ImportFrom alias alias alias ImportFrom alias Assign NameStore Str Assign NameStore Num Assign NameStore Str Assign NameStore Call NameLoad Num ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam defaults body Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Return Str decorator_list FunctionDef arguments args NameParam NameParam defaults body Return NameLoad decorator_list decorator_list FunctionDef arguments args defaults body Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Str keyword BinOpAdd Str NameLoad keyword NameLoad Expr Call AttributeLoad NameLoad attr Str keyword BinOpAdd Str Call NameLoad NameLoad keyword NameLoad Expr Call AttributeLoad NameLoad attr Str keyword Str keyword NameLoad keyword Num Expr Call AttributeLoad NameLoad attr Str keyword Str Return Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Expr Str Assign NameStore ListLoad Assign NameStore Call NameLoad NameLoad Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Num For NameStore Call NameLoad Call NameLoad NameLoad body If CompareEq SubscriptLoad NameLoad Index NameLoad Str body Assign NameStore NameLoad Break If CompareEq NameLoad Num body Expr Call AttributeLoad NameLoad attr Str Return Assign NameStore NameLoad While CompareLt NameLoad NameLoad body TryExcept body Expr Yield NameLoad If CompareEq Call NameLoad NameLoad Num body For NameStore NameLoad body Assign SubscriptStore NameLoad Index NameLoad Call AttributeLoad NameLoad attr AugAssignAdd NameStore NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Expr Yield NameLoad If CompareGt NameLoad NameLoad body Break Expr Call AttributeLoad NameLoad attr orelse If NameLoad body For NameStore Call NameLoad NameLoad body Assign SubscriptStore NameLoad Index NameLoad Call AttributeLoad NameLoad attr AugAssignAdd NameStore NameLoad Expr Yield NameLoad If CompareGt NameLoad NameLoad body Break orelse For NameStore NameLoad body Assign SubscriptStore NameLoad Index NameLoad Call AttributeLoad NameLoad attr AugAssignAdd NameStore NameLoad Expr Yield NameLoad If CompareGt NameLoad NameLoad body Break Assign NameStore UnaryOpNot NameLoad handlers ExceptHandler type NameLoad body Raise NameLoad decorator_list FunctionDef arguments args defaults body Assign NameStore Call NameLoad Assign NameStore Call NameLoad Num Num Num Num Num Num Num Call NameLoad Assign NameStore Call NameLoad keyword Num If CompareLtE AttributeLoad NameLoad attr Num body Assign NameStore Call AttributeLoad NameLoad attr Call NameLoad orelse Assign NameStore Call NameLoad keyword AttributeLoad NameLoad attr Assign NameStore BinOpAdd NameLoad NameLoad Assign NameStore Str Assign NameStore Call NameLoad AttributeLoad NameLoad attr NameLoad AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad If CompareNotEq NameLoad Num body Print TupleLoad NameLoad Call AttributeLoad NameLoad attr NameLoad Return Assign NameStore SubscriptLoad NameLoad Index Str Print BinOpAdd Str NameLoad Assign NameStore Call NameLoad AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Assign NameStore Call AttributeLoad Str attr Call NameLoad NameLoad AugAssignAdd NameStore Str Assign NameStore Num TryExcept body Assign NameStore Num Print Print Str Assign NameStore NameLoad For NameStore NameLoad body Assign NameStore BinOpAdd Call AttributeLoad Str attr NameLoad Str AugAssignAdd NameStore NameLoad AugAssignAdd NameStore Num If CompareEq NameLoad Num body Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad If CompareNotEq NameLoad Num body Print TupleLoad NameLoad Call AttributeLoad NameLoad attr NameLoad Break Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr keyword NameLoad keyword Call NameLoad NameLoad keyword NameLoad If CompareNotEq NameLoad Num body Print TupleLoad NameLoad Call AttributeLoad NameLoad attr NameLoad Break For NameStore NameLoad body Print Call AttributeLoad Str attr SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str If CompareGt Call NameLoad NameLoad Num body Assign NameStore BinOpAdd Call NameLoad SubscriptLoad SubscriptLoad NameLoad Index Num Index Str Num Assign NameStore NameLoad Assign NameStore Num handlers ExceptHandler type NameLoad body Print Str Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad If CompareNotEq NameLoad Num body Print TupleLoad NameLoad Call AttributeLoad NameLoad attr NameLoad decorator_list If CompareEq NameLoad Str body Expr Call NameLoad
N/A N/A 
This script creates a new job and uploads to it APM data records
generated from existing data in a CSV file. New records will created
indefinitely or until the 'duration' argument expires. Each record has
a new timestamp so this script can be used to repeatedly replay the
historical data. After each upload of data the script requests any new
bucket results and prints them.

The script is invoked with 1 positional argument -the CSV file containing
APM to use a the source of the generated data- and optional arguments
to specify the location of the Engine API. Run the script with '--help'
to see the options.

The file used in the online example can be downloaded from
http://s3.amazonaws.com/prelert_demo/network.csv

If no 'duration' is set the script will run indefinitely cse Ctrl-C to
stop the script - the interrupt is caught and the job closed gracefully
 N/A argparse N/A csv N/A json N/A logging N/A sys N/A time datetime datetime timedelta tzinfo prelert.engineApiClient EngineApiClient N/A HOST localhost N/A PORT 8080 N/A BASE_URL engine/v1 N/A ZERO_OFFSET N/A timedelta 0 UtcOffset N/A tzinfo N/A N/A 
    Timezone object at 0 (UTC) offset
     utcoffset N/A N/A self dt N/A N/A N/A ZERO_OFFSET N/A tzname N/A N/A self dt N/A N/A N/A UTC N/A dst N/A N/A self dt N/A N/A N/A ZERO_OFFSET N/A N/A parseArguments N/A N/A N/A N/A N/A parser N/A N/A argparse ArgumentParser N/A N/A N/A parser add_argument --host help N/A The Prelert Engine API host, defaults to  HOST default HOST N/A N/A N/A parser add_argument --port help N/A The Prelert Engine API port, defaults to  N/A str PORT default PORT N/A N/A N/A parser add_argument --duration help The number of hours to generate         data for. If not set script will produce records from the historical         start date until the time now type int default 0 N/A N/A N/A parser add_argument file help Path to APM data N/A N/A N/A parser parse_args N/A generateRecords N/A N/A csv_filename start_date interval end_date N/A N/A N/A 
    Generator function reads csv data file and returns records
    with an updated timestamp on demand.

    Records are read from a file and stored in a local array, once
    all the records have been read the function does not loop
    round to the beginning again instead it flips and outputs
    the records in reverse order and so on.

    The csv file must contain a field with the name 'time'
     N/A csv_data N/A N/A csv_file N/A open csv_filename rb N/A reader N/A N/A csv reader csv_file N/A header N/A N/A reader next N/A time_field_idx -1 N/A i N/A range N/A len header N/A N/A N/A N/A header N/A i time N/A N/A time_field_idx i N/A N/A N/A time_field_idx -1 N/A N/A N/A N/A logging error Cannot find 'time' field in csv header N/A N/A reverse False N/A N/A start_date end_date N/A N/A N/A N/A N/A header N/A N/A N/A len csv_data 0 N/A N/A row reader N/A N/A N/A row N/A time_field_idx N/A N/A start_date isoformat N/A start_date interval N/A N/A N/A csv_data append row N/A N/A row N/A N/A start_date end_date N/A N/A N/A N/A N/A csv_file close N/A N/A reverse N/A N/A row N/A reversed csv_data N/A N/A N/A row N/A time_field_idx N/A N/A start_date isoformat N/A start_date interval N/A N/A row N/A N/A start_date end_date N/A N/A N/A N/A row csv_data N/A N/A N/A row N/A time_field_idx N/A N/A start_date isoformat N/A start_date interval N/A N/A row N/A N/A start_date end_date N/A N/A N/A reverse N/A reverse N/A N/A N/A KeyboardInterrupt N/A N/A StopIteration N/A main N/A N/A N/A N/A N/A args N/A parseArguments N/A start_date N/A datetime 2014 5 18 0 0 0 0 N/A UtcOffset N/A interval N/A timedelta seconds 300 N/A N/A N/A args duration 0 N/A N/A end_date N/A N/A datetime now N/A UtcOffset N/A N/A duration N/A timedelta hours N/A args duration N/A end_date N/A start_date duration N/A job_config {        "analysisConfig" : {            "bucketSpan":3600,            "detectors" :[                {"fieldName":"In Discards","byFieldName":"host"},                {"fieldName":"In Octets","byFieldName":"host"},                {"fieldName":"Out Discards","byFieldName":"host"},                {"fieldName":"Out Octets","byFieldName":"host"}             ]        },        "dataDescription" : {            "fieldDelimiter":",",            "timeField":"time",            "timeFormat":"yyyy-MM-dd'T'HH:mm:ssXXX"        }    } N/A engine_client N/A EngineApiClient N/A args host BASE_URL N/A args port N/A N/A http_status_code response N/A N/A engine_client createJob job_config N/A N/A http_status_code 201 N/A N/A N/A http_status_code N/A N/A json dumps response N/A N/A job_id N/A response N/A id N/A N/A Job created with Id =  job_id N/A record_generator N/A generateRecords N/A args file start_date interval end_date N/A header N/A N/A , join N/A next record_generator N/A header N/A count 0 N/A N/A N/A next_bucket_id 1 N/A N/A Date,Bucket ID,Anomaly Score,Max Normalized Probablility N/A data header N/A record record_generator N/A N/A csv N/A N/A N/A , join record N/A data csv N/A count 1 N/A N/A count 100 N/A N/A N/A http_status_code response N/A N/A engine_client upload job_id data N/A N/A http_status_code 202 N/A N/A N/A http_status_code N/A N/A json dumps response N/A N/A N/A http_status_code response N/A N/A engine_client getBucketsByDate job_id job_id start_date N/A str next_bucket_id end_date None N/A N/A http_status_code 200 N/A N/A N/A http_status_code N/A N/A json dumps response N/A N/A bucket response N/A N/A N/A N/A {0},{1},{2},{3} format N/A bucket N/A timestamp N/A bucket N/A id N/A bucket N/A anomalyScore N/A bucket N/A maxNormalizedProbability N/A N/A N/A len response 0 N/A N/A next_bucket_id N/A N/A int N/A N/A response N/A -1 N/A id 1 N/A data header N/A count 0 N/A N/A N/A KeyboardInterrupt N/A N/A Keyboard interrupt closing job... N/A N/A http_status_code response N/A N/A engine_client close job_id N/A N/A http_status_code 202 N/A N/A N/A http_status_code N/A N/A json dumps response N/A N/A N/A __name__ __main__ N/A N/A N/A main