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() 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 alerts_details(alert): from polylogyx.wrappers.v1.alert_wrappers import alerts_wrapper alerts_data = marshal(alert, alerts_wrapper) if alerts_data['source'] == 'rule': alerts_data['rule'] = { 'name': rules_dao.get_rule_name_by_id(alerts_data['rule_id']), 'id': alerts_data['rule_id'] } host = hosts_dao.getNodeById(alerts_data['node_id']) alerts_data['hostname'] = host.display_name alerts_data['platform'] = host.platform return alerts_data
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 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 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 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 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_host_id_by_node_id(node_id): node = node_dao.getNodeById(node_id) if node: return node.host_identifier