def post(self, host_identifier=None, node_id=None): """Creates tags of a node by its host_identifier""" args = self.parser.parse_args() status = 'failure' if host_identifier: node = dao.get_node_by_host_identifier(host_identifier) elif node_id: node = dao.getNodeById(node_id) else: node = None if node: tag = args['tag'].strip() if not tag: message = "Tag provided is invalid!" else: tag = tags_dao.create_tag_obj(tag) node.tags.append(tag) node.save() status = "success" message = "Successfully created tags to host" else: message = "Host id or node id passed it not correct" return marshal(respcls(message, status), parentwrapper.common_response_wrapper, skip_none=True)
def delete(self, host_identifier=None, node_id=None): """Remove tags of a node by its host_identifier""" args = self.parser.parse_args() status = 'failure' if host_identifier: node = dao.get_node_by_host_identifier(host_identifier) elif node_id: node = dao.getNodeById(node_id) else: node = None if node: tag = args['tag'].strip() tag = tags_dao.get_tag_by_value(tag) if tag: if dao.is_tag_of_node(node, tag): node.tags.remove(tag) node.save() message = "Successfully removed tags from host" status = "success" else: message = "Tag provided is not in host's tag list, Please check tag once again" else: message = "Tag provided doesnot exists" else: message = "Host id or node id passed it not correct" return marshal(respcls(message, status), parentwrapper.common_response_wrapper, skip_none=True)
def post(self): args = self.parser.parse_args() status = "failure" data = None if args['node_id'] is not None or args['host_identifier'] is not None: if args['host_identifier'] is not None: node = dao.get_node_by_host_identifier(args['host_identifier']) if node: node_id = node.id else: node_id = None else: node_id = args['node_id'] if not node_id: message = "Please pass correct host identifier or node id to get the results" else: data = [{ 'name': query[0], 'count': query[1] } for query in dao.get_result_log_count(node_id)] status = "success" message = "Successfully fetched the count of schedule query results count of host identifier passed" else: message = "Atleast one of host identifier or node id should be given!" return marshal(respcls(message, status, data), parentwrapper.common_response_wrapper, skip_none=True)
def post(self): status = 'failure' args = self.parser.parse_args() host_identifier = args['host_identifier'] query_id = args['query_id'] carve_session = {} node = nodedao.get_node_by_host_identifier(host_identifier) if not node: message = 'Node with this identifier does not exists' else: dqt = db.session.query(DistributedQueryTask).filter( DistributedQueryTask.distributed_query_id == query_id).filter( DistributedQueryTask.node_id==node.id).first() if dqt: carve_session = db.session.query(CarveSession).filter(CarveSession.request_id == dqt.guid).first() if carve_session: carve_session = marshal(carve_session, wrapper.carves_wrapper) status = "success" message = "Successfully fetched the Carve" return marshal(respcls(message, status, carve_session), parentwrapper.common_response_wrapper) else: message = "Carve not started" else: message = "Query id provided is invalid!" return marshal(respcls(message, status, carve_session), parentwrapper.common_response_wrapper, skip_none=True)
def post(self): args = self.parser.parse_args() data = None status = "failure" if args['node_id'] is not None or args['host_identifier'] is not None: if args['host_identifier'] is not None: qs = dao.get_node_by_host_identifier(args['host_identifier']) else: node_id = args['node_id'] qs = dao.getNodeById(node_id) if qs: data = { 'results': marshal( dao.get_status_logs_of_a_node( qs, args['searchterm']).offset( args['start']).limit(args['limit']).all(), wrapper.node_status_log_wrapper), 'count': dao.get_status_logs_of_a_node(qs, args['searchterm']).count(), 'total_count': dao.get_status_logs_total_count(qs) } message = "Successfully fetched the host's status logs" status = "success" else: message = "Host identifier or node id passed is not correct!" else: message = "Please pass one of node id or host identifier!" return marshal(respcls(message, status, data), parentwrapper.common_response_wrapper, skip_none=True)
def post(self): from polylogyx.dao.v1.hosts_dao import getHostNameByNodeId carves = None status = 'success' args = self.parser.parse_args() host_identifier = args['host_identifier'] if host_identifier: node = nodedao.get_node_by_host_identifier(host_identifier) if not node: status = 'failure' message = 'Node with this identifier does not exists' else: carves = marshal(dao.get_carves_by_node_id(node.id, args['searchterm']).offset( args['start']).limit(args['limit']).all(), wrapper.carves_wrapper) count = dao.get_carves_by_node_id(node.id, args['searchterm']).count() total_count = dao.get_carves_total_count(node_id=node.id) for carve in carves: carve['hostname'] = getHostNameByNodeId(carve['node_id']) carves = {'count':count, 'results':carves, 'total_count':total_count} message = 'Successfully fetched the Carves data' else: carves = marshal(dao.get_carves_all(args['searchterm']).offset(args['start']).limit(args['limit']).all(), wrapper.carves_wrapper) count = dao.get_carves_all(args['searchterm']).count() total_count = dao.get_carves_total_count(node_id=None) for carve in carves: carve['hostname'] = getHostNameByNodeId(carve['node_id']) carves = {'count':count, 'results':carves, 'total_count':total_count} message = 'Successfully fetched the Carves data' status = "success" return marshal(respcls(message,status,carves),parentwrapper.common_response_wrapper)
def post(self): status = "failure" config = {} args = self.parser.parse_args() if args['host_identifier']: node = hosts_dao.get_node_by_host_identifier( args['host_identifier']) if node: config = node.get_config() message = "Successfully fetched the config through host identifier passed" else: message = "Host identifier passed is not valid!" else: config = dao.get_config(args['platform'], args['arch']) if config: config = dao.get_config_by_platform(config) status = "success" message = "Config is fetched successfully for the platform given" else: message = "Requested config is not present for the platform, arch, type given!" if config: status = "success" return marshal(respcls(message, status, config), parentwrapper.common_response_wrapper, skip_none=True)
def get_carves_with_host_identifier(self, host_identifier): node = hosts_dao.get_node_by_host_identifier(host_identifier) if node: carves = marshal( carves_dao.get_carves_by_node_id( node.id).offset(0).limit(100).all(), wrapper.carves_wrapper) total_count = carves_dao.get_carves_by_node_id(node.id).count() for carve in carves: carve['hostname'] = getHostNameByNodeId(carve['node_id']) carves = {'count': total_count, 'results': carves} return carves
def get_carve_session_by_query_id(self, query_id, host_identifier): node = hosts_dao.get_node_by_host_identifier(host_identifier) if node: dqt = db.session.query(DistributedQueryTask).filter( DistributedQueryTask.distributed_query_id == query_id).filter( DistributedQueryTask.node_id == node.id).first() if dqt: carve_session = db.session.query(CarveSession).filter( CarveSession.request_id == dqt.guid).first() if carve_session: return marshal(carve_session, wrapper.carves_wrapper) return
def get(self, host_identifier=None, node_id=None): """Lists tags of a node by its host_identifier""" status = 'failure' if host_identifier: node = dao.get_node_by_host_identifier(host_identifier) elif node_id: node = dao.getNodeById(node_id) else: node = None if not node: message = "Host id or node id passed it not correct" data = None else: data = [tag.value for tag in node.tags] status = "success" message = "Successfully fetched the tags of host" return marshal(respcls(message, status, data), parentwrapper.common_response_wrapper, skip_none=True)
def post(self): args = self.parser.parse_args() status = "failure" data = {} if args['node_id'] is not None or args['host_identifier'] is not None: if args['host_identifier'] is not None: node = dao.get_node_by_host_identifier(args['host_identifier']) if node: node_id = node.id else: node_id = None else: node_id = args['node_id'] if not node_id: message = "Please pass correct host identifier or node id to get the results" else: qs = dao.get_result_log_of_a_query(node_id, args['query_name'], args['start'], args['limit'], args['searchterm']) data = { 'count': qs[0], 'total_count': qs[2], 'results': [{ 'timestamp': list_ele[1].strftime('%m/%d/%Y %H/%M/%S'), 'action': list_ele[2], 'columns': list_ele[3] } for list_ele in qs[1]] } status = "success" message = "Successfully fetched the count of schedule query results count of host identifier passed" else: message = "Atleast one of host identifier or node id should be given!" return marshal(respcls(message, status, data), parentwrapper.common_response_wrapper, skip_none=True)
def get(self, host_identifier=None, node_id=None): data = None if node_id: queryset = dao.getNodeById(node_id) elif host_identifier: queryset = dao.get_node_by_host_identifier(host_identifier) else: queryset = None db.session.commit() if not queryset: message = "There is no host exists with this host identifier or node id given!" status = "failure" else: data = marshal(queryset, wrapper.nodewrapper) if not data: data = {} message = "Node details are fetched successfully" status = "success" return marshal(respcls(message, status, data), parentwrapper.common_response_wrapper, skip_none=True)
def put(self, host_identifier=None, node_id=None): node = None message = "Node is not present with this node id or host identifier" status = "failure" if host_identifier: node = dao.get_node_by_host_identifier(host_identifier) if node_id: node = dao.getNodeById(node_id) if node: current_app.logger.info( "Host {} is requested to be disabled for all his activities from agent" .format(node.host_identifier)) dao.soft_remove_host(node) message = "Successfully removed the host" status = "Success" return marshal(respcls(message, status), parentwrapper.common_response_wrapper, skip_none=True) return marshal(respcls(message, status), parentwrapper.common_response_wrapper, skip_none=True)
def delete(self, host_identifier=None, node_id=None): node = None message = "Node is not present with this node id or host identifier" status = "failure" if host_identifier: node = dao.get_node_by_host_identifier(host_identifier) if node_id: node = dao.getNodeById(node_id) if node: current_app.logger.info( "Host {} is requested for permanent deletion".format( node.host_identifier)) dao.delete_host(node) message = "Successfully deleted the host" status = "Success" return marshal(respcls(message, status), parentwrapper.common_response_wrapper, skip_none=True) return marshal(respcls(message, status), parentwrapper.common_response_wrapper, skip_none=True)
def post(self): args = self.parser.parse_args() config = None status = "failure" if args['node_id'] is not None or args['host_identifier'] is not None: if args['host_identifier'] is not None: node = dao.get_node_by_host_identifier(args['host_identifier']) else: node_id = args['node_id'] node = dao.getNodeById(node_id) if node: config = assemble_configuration(node) status = "success" message = "Successfully fetched full config of the node for the host identifier passed" else: message = "Host identifier or node id passed is not correct!" else: message = "Atleast one of host identifier or node id should be given!" return marshal(respcls(message, status, config), parentwrapper.common_response_wrapper, skip_none=True)
def post(self): """ Display Alerts by source table content. """ from polylogyx.dao.v1.hosts_dao import get_node_by_host_identifier from polylogyx.dao.v1.queries_dao import get_query_by_name from polylogyx.dao.v1.rules_dao import get_rule_by_id args = self.parser.parse_args() source = args['source'] start = args['start'] limit = args['limit'] resolved = args['resolved'] event_ids = args['event_ids'] query_name = args['query_name'] rule_id = args['rule_id'] start_date = None end_date = None node_id = None if args['host_identifier']: node = get_node_by_host_identifier(args['host_identifier']) if not node: return marshal(respcls("No Host present for the host identifier given!", "failure"), parentwrapper.common_response_wrapper, skip_none=True) node_id = node.id if query_name and not get_query_by_name(query_name): return marshal(respcls("No Query present for the query name given!", "failure"), parentwrapper.common_response_wrapper, skip_none=True) if rule_id and not get_rule_by_id(rule_id): return marshal(respcls("No Rule present for the rule id given!", "failure"), parentwrapper.common_response_wrapper, skip_none=True) if args['date']: try: start_date, end_date = get_start_dat_end_date(args) except: return abort(400, {'message': 'Date format passed is invalid!'}) results = get_results_by_alert_source(start, limit, source, args['searchterm'], resolved, event_ids, start_date, end_date, node_id, query_name, rule_id, args['events_count']) message = "Data is fetched successfully" status = "success" return marshal(respcls(message, status, results), parentwrapper.common_response_wrapper, skip_none=True)
def get(self, host_identifier=None, node_id=None): if node_id: node = dao.getNodeById(node_id) elif host_identifier: node = dao.get_node_by_host_identifier(host_identifier) else: node = None if not node: data = None message = "There is no host exists with this host identifier or node id given!" status = "failure" else: data = {} data['sources'] = dao.host_alerts_distribution_by_source(node) data['rules'] = [{ "name": rule_count_pair[0], "count": rule_count_pair[1] } for rule_count_pair in dao.host_alerts_distribution_by_rule(node) ] message = "Alerts distribution details are fetched for the host" status = "success" return marshal(respcls(message, status, data), parentwrapper.common_response_wrapper, skip_none=True)
def get_node_id_by_host_id(host_identifier): node = node_dao.get_node_by_host_identifier(host_identifier) if node: return node.id