예제 #1
0
def get(p):
    # load instance
    task_id = p['nav'][-1]
    p['task'] = es.get(p['host'], 'core_task', 'task', task_id)
    if not p['task']:
        return tools.alert('invalid task id - {}'.format(task_id))

    # instance list
    query = 'task_id:{}'.format(task_id)
    option = 'size=50'
    if es.count(p['host'], 'core_task', 'instance'):
        option += '&sort=created:desc'
    p['history_list'] = es.list(p['host'], 'core_task', 'instance', query,
                                option)

    for history in p['history_list']:
        # statistics
        query = "instance_id:{}".format(history['id'])
        history['total'] = es.count(p['host'], 'core_task', 'log', query)
        if not history['total']: history['total'] = ''

        query = "instance_id:{} AND status:SUCCESS".format(history['id'])
        history['success'] = es.count(p['host'], 'core_task', 'log', query)
        if not history['success']: history['success'] = ''

        query = "instance_id:{} AND status:ERROR".format(history['id'])
        history['error'] = es.count(p['host'], 'core_task', 'log', query)
        if not history['error']: history['error'] = ''

    return render_template("task/status/history.html", p=p)
예제 #2
0
파일: log.py 프로젝트: unkyulee/elastic-cms
def get(p):
    # load instance
    instance_id = p['nav'][-1]
    p['instance'] = es.get(p['host'], 'core_task', 'instance', instance_id)
    if not p['instance']:
        return tools.alert('invalid instance id - {}'.format(instance_id))

    # Search Keyword
    search_keyword = tools.get("search[value]") + "*"

    # Length of the result
    length = tools.get("length")
    if not length: length = 10

    # Offset of the result
    start = tools.get("start")
    if not start: start = 0

    # draw
    draw = tools.get("draw")
    if not draw: draw = 0

    # Apply Search Keyword
    query = "instance_id:{} AND {}".format(instance_id, search_keyword)

    option = 'from={}&size={}&sort=created:desc'.format(start, length)
    # search results
    search_result = es.list(p['host'], 'core_task', 'log', query, option)

    # Get Total number of records
    total = es.count(p['host'], 'core_task', 'log')
    filter_total = es.count(p['host'], 'core_task', 'log', query)

    # Form header
    DataTableJson = {}
    DataTableJson = {
        # draw - this is handshake id which maps the request - response async maps from JS
        "draw":
        int(draw),
        "recordsTotal":
        total,
        "recordsFiltered":
        filter_total,
        "data":
        [[log['action'], log['message'], log['status'], log['created']]
         for log in search_result]
    }

    # Return in JSON format
    return json.dumps(DataTableJson)
예제 #3
0
def get(p):

    # Load Task List
    option = None
    query = 'navigation_id:{}'.format(p['navigation']['id'])
    if es.count(p['host'], 'core_task', 'task'):
        option = 'sort=name:asc'
    p['task_list'] = es.list(p['host'], 'core_task', 'task', query, option)

    # get last instance information
    for task in p['task_list']:
        query = 'task_id:{}'.format(task['id'])
        option = None
        if es.count(p['host'], 'core_task', 'instance'):
            option = 'sort=created:desc'

        ret = es.list(p['host'], 'core_task', 'instance', query, option)
        task['instance'] = {}
        if len(ret):
            task['instance'] = ret[0]

    return render_template("task/task/default.html", p=p)
예제 #4
0
def get(p):
    # load instance
    instance_id = p['nav'][-1]
    p['instance'] = es.get(p['host'], 'core_task', 'instance', instance_id)
    if not p['instance']:
        return tools.alert('invalid instance id - {}'.format(instance_id))

    # load task
    p['task'] = es.get(p['host'], 'core_task', 'task',
                       p['instance']['task_id'])

    # statistics
    query = "instance_id:{}".format(p['instance']['id'])
    p['total'] = es.count(p['host'], 'core_task', 'log', query)

    query = "instance_id:{} AND status:SUCCESS".format(p['instance']['id'])
    p['success'] = es.count(p['host'], 'core_task', 'log', query)

    query = "instance_id:{} AND status:ERROR".format(p['instance']['id'])
    p['error'] = es.count(p['host'], 'core_task', 'log', query)

    return render_template("task/status/default.html", p=p)
예제 #5
0
def get(p):
    # load task
    task_id = p['nav'][-1]
    p['task'] = es.get(p['host'], 'core_task', 'task', task_id)
    if not p['task']:
        return tools.alert('task not found - {}'.format(task_id))

    if request.method == "POST":
        es.update(
            p['host'], 'core_task', 'task', task_id, {
                'navigation_id': p['navigation']['id'],
                'name': tools.get('name'),
                'runat':
                tools.get('runat') if tools.get('runat') else 'anywhere',
                'description': tools.get('description')
            })
        es.flush(p['host'], 'core_task')

        return tools.redirect(request.referrer)

    # load action list
    # when there are no records then the task fails to run
    option = ''
    if es.count(p['host'], 'core_task', 'action'):
        option = 'size=10000&sort=order_key:asc'

    query = 'task_id:{}'.format(p['task']['id'])
    p['action_list'] = es.list(p['host'], 'core_task', 'action', query, option)
    for action in p['action_list']:
        action['module'] = es.get(p['host'], 'core_task', 'module',
                                  action['module_id'])

    # load schedule list
    query = 'task_id:{}'.format(p['task']['id'])
    p['schedule_list'] = es.list(p['host'], 'core_task', 'schedule', query)

    # load task module List
    option = 'size=10000&sort=description:asc'
    p['task_module_list'] = es.list(p['host'], 'core_task', 'module', '*',
                                    option)

    return render_template("task/task/edit.html", p=p)