Ejemplo n.º 1
0
def send_watches(watches, current_watches, es):
    xpack = XPackClient(es)
    updated = []
    for watch, template in watches.items():
        if watch_changed(watch, template, current_watches):
            xpack.watcher.put_watch(watch, template)
            updated.append(watch)
    return updated
Ejemplo n.º 2
0
                 body=event,
                 id=event['id'] if "id" in event else i,
                 params=params)
        i += 1
    es.indices.refresh(index=test["index"])
    #Load Scripts
    if 'scripts' in test:
        for script in test['scripts']:
            with open(script['path'], 'r') as script_file:
                es.index(index="_scripts",
                         doc_type="painless",
                         id=script["name"],
                         body=json.loads(script_file.read()))

    #Load Watch and Execute
    watcher = XPackClient(es).watcher
    with open(test['watch_file'], 'r') as watch_file:
        watch = json.loads(watch_file.read())
        watcher.put_watch(id=test["watch_name"], body=watch)
        response = watcher.execute_watch(test["watch_name"])
        #Confirm Matches
        match = test['match'] if 'match' in test else True
        print("Expected: Watch Condition: %s" % match)
        if not 'condition' in response['watch_record']['result']:
            print("Condition not evaluated due to watch error")
            print("TEST FAIL")
            sys.exit(1)
        met = response['watch_record']['result']['condition']['met']
        print("Received: Watch Condition: %s" % met)
        if match:
            if met and response['watch_record']['result']['condition'][
Ejemplo n.º 3
0
    time_field = test["time_field"] if "time_field" in test else "@timestamp"
    for event in test['events']:
        #All offsets in seconds
        event_time=current_data+datetime.timedelta(seconds=int(event['offset'] if 'offset' in event else 0))
        event[time_field]=event_time.strftime('%Y-%m-%dT%H:%M:%S.%fZ') if not time_field in event else event[time_field]
        es.index(index=test['index'],doc_type=test['type'],body=event,id=event['id'] if "id" in event else i,params=params)
        i+=1
    es.indices.refresh(index=test["index"])
    #Load Scripts
    if 'scripts' in test:
        for script in test['scripts']:
            with open(script['path'], 'r') as script_file:
                es.put_script(id=script["name"],body=json.loads(script_file.read()))

    #Load Watch and Execute
    watcher = XPackClient(es).watcher
    with open(test['watch_file'],'r') as watch_file:
        watch=json.loads(watch_file.read())
        watcher.put_watch(id=test["watch_name"],body=watch)
        response=watcher.execute_watch(test["watch_name"])
        #Confirm Matches
        match = test['match'] if 'match' in test else True
        print("Expected: Watch Condition: %s"%match)
        if not 'condition' in response['watch_record']['result']:
            print("Condition not evaluated due to watch error")
            print("TEST FAIL")
            sys.exit(1)
        met=response['watch_record']['result']['condition']['met']
        print("Received: Watch Condition: %s"%met)
        if match:
            if met and response['watch_record']['result']['condition']['status'] == "success":
Ejemplo n.º 4
0
if __name__ == "__main__":
    """This script set the default roles and users to run the LTR demo"""
    if len(sys.argv) == 2:
        password = getpass.getpass()
    elif len(sys.argv) == 3:
        password = sys.argv[2]
    else:
        print(
            """prepare_xpack.py [elasticsearch.user] [elasticsearch.password]"""
        )
        sys.exit(-1)

    username = sys.argv[1]

    es = Elasticsearch(http_auth=(username, password))
    xpack = XPackClient(es)

    print("Configure ltr_admin role:")
    res = xpack.security.put_role(
        'ltr_admin', {
            "cluster": ["all"],
            "indices": [{
                "names": [".ltrstore*"],
                "privileges": ["all"]
            }]
        })
    print(res)

    print("Configure tmdb role:")
    res = xpack.security.put_role(
        'tmdb', {'indices': [{