def distributed(node_id=None, status=None, page=1): tasks = DistributedQueryTask.query if status == 'new': tasks = tasks.filter_by(status=DistributedQueryTask.NEW) elif status == 'pending': tasks = tasks.filter_by(status=DistributedQueryTask.PENDING) elif status == 'complete': tasks = tasks.filter_by(status=DistributedQueryTask.COMPLETE) if node_id: node = Node.query.filter_by(id=node_id).first_or_404() tasks = tasks.filter_by(node_id=node.id) tasks = get_paginate_options( request, DistributedQueryTask, ('id', 'status', 'timestamp'), existing_query=tasks, page=page, default_sort='desc' ) display_msg = 'displaying <b>{start} - {end}</b> of <b>{total}</b> {record_name}' pagination = Pagination(page=page, per_page=tasks.per_page, total=tasks.total, alignment='center', show_single_page=False, display_msg=display_msg, record_name='{0} distributed query tasks'.format(status or '').strip(), bs_version=3) return render_template('distributed.html', queries=tasks.items, status=status, pagination=pagination)
def nodes(page=1, status='active'): if status == 'inactive': nodes = Node.query.filter_by(is_active=False) else: nodes = Node.query.filter_by(is_active=True) nodes = get_paginate_options( request, Node, ('id', 'host_identifier', 'enrolled_on', 'last_checkin'), existing_query=nodes, page=page, ) display_msg = 'displaying <b>{start} - {end}</b> of <b>{total}</b> {record_name} ' display_msg += '<a href="{0}" title="Export node information to csv">'.format( url_for('manage.nodes_csv')) display_msg += '<i class="fa fa-download"></i></a>' pagination = Pagination(page=page, per_page=nodes.per_page, total=nodes.total, alignment='center', show_single_page=False, display_msg=display_msg, record_name='{status} nodes'.format(status=status), bs_version=3) return render_template('nodes.html', nodes=nodes.items, pagination=pagination, status=status)
def nodes(page=1, status='active'): if status == 'inactive': nodes = Node.query.filter_by(is_active=False) else: nodes = Node.query.filter_by(is_active=True) nodes = get_paginate_options( request, Node, ('id', 'host_identifier', 'enrolled_on', 'last_checkin'), existing_query=nodes, page=page, ) display_msg = 'displaying <b>{start} - {end}</b> of <b>{total}</b> {record_name} ' display_msg += '<a href="{0}" title="Export node information to csv">'.format( url_for('manage.nodes_csv') ) display_msg += '<i class="fa fa-download"></i></a>' pagination = Pagination(page=page, per_page=nodes.per_page, total=nodes.total, alignment='center', show_single_page=False, display_msg=display_msg, record_name='{status} nodes'.format(status=status), bs_version=3) return render_template('nodes.html', nodes=nodes.items, pagination=pagination, status=status)
def node_logs(node_id, page=1): node = Node.query.filter(Node.id == node_id).first_or_404() status_logs = StatusLog.query.filter_by(node=node) status_logs = get_paginate_options( request, StatusLog, ('line', 'message', 'severity', 'filename'), existing_query=status_logs, page=page, max_pp=50, default_sort='desc' ) pagination = Pagination(page=page, per_page=status_logs.per_page, total=status_logs.total, alignment='center', show_single_page=False, record_name='status logs', bs_version=3) return render_template('logs.html', node=node, status_logs=status_logs.items, pagination=pagination)
def distributed(node_id=None, status=None, page=1): tasks = DistributedQueryTask.query if status == 'new': tasks = tasks.filter_by(status=DistributedQueryTask.NEW) elif status == 'pending': tasks = tasks.filter_by(status=DistributedQueryTask.PENDING) elif status == 'complete': tasks = tasks.filter_by(status=DistributedQueryTask.COMPLETE) if node_id: node = Node.query.filter_by(id=node_id).first_or_404() tasks = tasks.filter_by(node_id=node.id) tasks = get_paginate_options( request, DistributedQueryTask, ('id', 'status', 'timestamp'), existing_query=tasks, page=page, default_sort='desc' ) display_msg = 'displaying <b>{start} - {end}</b> of <b>{total}</b> {record_name}' pagination = Pagination(page=page, per_page=tasks.per_page, total=tasks.total, alignment='center', show_single_page=False, display_msg=display_msg, record_name='{0} distributed query tasks'.format(status or '').strip(), bs_version=3) return render_template('distributed.html', queries=tasks.items, status=status, pagination=pagination)
def node_logs(node_id, page=1): node = Node.query.filter(Node.id == node_id).first_or_404() status_logs = StatusLog.query.filter_by(node=node) status_logs = get_paginate_options( request, StatusLog, ('line', 'message', 'severity', 'filename'), existing_query=status_logs, page=page, max_pp=50, default_sort='desc' ) pagination = Pagination(page=page, per_page=status_logs.per_page, total=status_logs.total, alignment='center', show_single_page=False, record_name='status logs', bs_version=3) return render_template('logs.html', node=node, status_logs=status_logs.items, pagination=pagination)
def distributed_results(distributed_id, status=None, page=1): query = DistributedQuery.query.filter_by(id=distributed_id).first_or_404() tasks = DistributedQueryTask.query.filter_by(distributed_query_id=query.id) if status == 'new': tasks = tasks.filter_by(status=DistributedQueryTask.NEW) elif status == 'pending': tasks = tasks.filter_by(status=DistributedQueryTask.PENDING) elif status == 'complete': tasks = tasks.filter_by(status=DistributedQueryTask.COMPLETE) elif status == 'failed': tasks = tasks.filter_by(status=DistributedQueryTask.FAILED) tasks = get_paginate_options( request, DistributedQueryTask, ('id', 'status', 'timestamp'), existing_query=tasks, page=page, default_sort='desc' ) display_msg = 'displaying <b>{start} - {end}</b> of <b>{total}</b> {record_name}' pagination = Pagination(page=page, per_page=tasks.per_page, total=tasks.total, alignment='center', show_single_page=False, display_msg=display_msg, record_name='{0} distributed query results'.format(status or '').strip(), bs_version=3) # We could do this in the template, but it's more clear here. columns = [] for task in tasks.items: if len(task.results) > 0 and len(task.results[0].columns) > 0: columns = sorted(task.results[0].columns.keys()) return render_template('distributed_results.html', tasks=tasks.items, columns=columns, query=query, status=status, pagination=pagination, distributed_id=distributed_id)
def distributed_results(distributed_id, status=None, page=1): query = DistributedQuery.query.filter_by(id=distributed_id).first_or_404() tasks = DistributedQueryTask.query.filter_by(distributed_query_id=query.id) if status == 'new': tasks = tasks.filter_by(status=DistributedQueryTask.NEW) elif status == 'pending': tasks = tasks.filter_by(status=DistributedQueryTask.PENDING) elif status == 'complete': tasks = tasks.filter_by(status=DistributedQueryTask.COMPLETE) elif status == 'failed': tasks = tasks.filter_by(status=DistributedQueryTask.FAILED) tasks = get_paginate_options(request, DistributedQueryTask, ('id', 'status', 'timestamp'), existing_query=tasks, page=page, default_sort='desc') display_msg = 'displaying <b>{start} - {end}</b> of <b>{total}</b> {record_name}' pagination = Pagination(page=page, per_page=tasks.per_page, total=tasks.total, alignment='center', show_single_page=False, display_msg=display_msg, record_name='{0} distributed query results'.format( status or '').strip(), bs_version=3) # We could do this in the template, but it's more clear here. columns = [] for task in tasks.items: if len(task.results) > 0 and len(task.results[0].columns) > 0: columns = sorted(task.results[0].columns.keys()) return render_template('distributed_results.html', tasks=tasks.items, columns=columns, query=query, status=status, pagination=pagination, distributed_id=distributed_id)
def nodes(page=1): nodes = get_paginate_options( request, Node, ('id', 'host_identifier', 'enrolled_on', 'last_checkin'), page=page, ) display_msg = 'displaying <b>{start} - {end}</b> of <b>{total}</b> {record_name}' pagination = Pagination(page=page, per_page=nodes.per_page, total=nodes.total, alignment='center', show_single_page=False, display_msg=display_msg, record_name='nodes', bs_version=3) return render_template('nodes.html', nodes=nodes.items, pagination=pagination)