def post(self): args = self.parser.parse_args() # need to exists for input payload validation status = 'failure' host_identifier = args['host_identifier'] add_tags = args['add_tags'].split(',') remove_tags = args['remove_tags'].split(',') node = dao.get_node_by_host_identifier(host_identifier) if not node: message = 'Invalid host identifier. This node does not exist' else: if add_tags: add_tags = create_tags(*add_tags) for add_tag in add_tags: if not add_tag in node.tags: node.tags.append(add_tag) if remove_tags: remove_tags = get_tags(*remove_tags) for remove_tag in remove_tags: if remove_tag in node.tags: node.tags.remove(remove_tag) node.save() status = 'success' message = 'Successfully modified the tag(s)' return marshal(respcls(message,status), 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'] node = nodedao.get_node_by_host_identifier(host_identifier) if not node: message = 'Node with this identifier does not exist' 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() carve_session = marshal(carve_session, wrapper.carves_wrapper) if carve_session: 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), parentwrapper.common_response_wrapper, skip_none=True)
def get(self, host_identifier): status = 'failure' node = dao.get_node_by_host_identifier(host_identifier) if not node: message = 'Invalid host identifier. This node does not exist' data = None else: data = marshal(node.tags,tag_wrapper.tag_name_wrapper) status = 'success' message = 'Successfully fetched the tag(s)' return marshal(respcls(message,status,data), parentwrapper.common_response_wrapper, skip_none=True)
def get(self, host_identifier): '''returns specific node info by filtering the object through the host identifier''' node_qs = dao.get_node_by_host_identifier(host_identifier) if host_identifier: if node_qs: system_data = marshal(dao.getNodeData(node_qs.id), wrapper.system_data_wrapper, envelope='system_data') node = marshal(node_qs, wrapper.nodebyid_wrapper) node['system_data'] = system_data node['tags'] = [tag.to_dict() for tag in node_qs.tags] return marshal(respcls("Successfully fetched the node info", 'success', node),parentwrapper.common_response_wrapper, skip_none=True) else: message="Node with this identifier does not exist" else: message="Missing host identifier" return marshal(respcls(message), parentwrapper.failure_response_parent)
def post(self, host_identifier): args = self.parser.parse_args() # need to exists for input payload validation tags = args['tags'].split(',') node = dao.get_node_by_host_identifier(host_identifier) if not node: message = 'Invalid host identifier. This node does not exist' data = None status = "failure" else: obj_list = get_tags_list_to_add(tags) node.tags.extend(obj_list) node.save() message = 'Successfully created the tag(s) to node' status = 'success' return marshal(respcls(message,status), parentwrapper.common_response_wrapper, skip_none=True)
def post(self): args = self.parser.parse_args() host_identifier = args['host_identifier'] node = dao.get_node_by_host_identifier(host_identifier) status = 'failure' message = 'Data missing' data = None if not node: message = 'Node with this identifier does not exist' else: try: timestamp = request.args.get('timestamp') timestamp = dt.datetime.fromtimestamp(float(timestamp)) except Exception: timestamp = dt.datetime.utcnow() timestamp -= dt.timedelta(days=30) query_name = args['query_name'] start = args['start'] limit = args['limit'] query = dao.getResultLogsByHostId(node, timestamp, query_name) try: if not start: start = 0 if not limit: limit = 0 if int(start) >= 0 and int(limit) > 0: query = dao.getResultLogsOffsetLimit( node, timestamp, 'removed', query_name, start, limit) recent = query.all() status = 'success' message = 'Successfully received node schedule query results' data = marshal(recent, res_wrapper.result_log_wrapper, skip_none=False) except: message = 'Start and limit must be integer' if not data: message = "There are no data to be shown and it is empty" return marshal(respcls(message, status, data), parentwrapper.common_response_wrapper, skip_none=False)
def get(self, host_identifier): node = dao.get_node_by_host_identifier(host_identifier) status = 'failure' data = None if not node: message = 'Node with this identifier does not exist' else: try: timestamp = request.args.get('timestamp') timestamp = dt.datetime.fromtimestamp(float(timestamp)) except Exception: timestamp = dt.datetime.utcnow() timestamp -= dt.timedelta(days=30) recent = dao.getResultLogs(node, timestamp, 'removed') data = [r.to_dict() for r in recent] status = 'success' message = 'Successfully received schedule query results' if not data: message = "There are no data to be shown and it is empty" return marshal(respcls(message, status, data), parentwrapper.common_response_wrapper)
def post(self): args = self.parser.parse_args() host_identifier = args['host_identifier'] rule_id = args['rule_id'] query_name = args['query_name'] data_valid = True if host_identifier: node = node_dao.get_node_by_host_identifier(host_identifier) else: node = None alert_results = dao.get_alerts_for_input(node,rule_id,query_name) data = alert_results[0] message = alert_results[1] if not data: status="failure"; else: data = add_rule_name_to_alerts_response(marshal(data, alert_wrapper.alerts_wrapper, skip_none=True)); message = "Successfully received the alerts"; status = "success"; return marshal(respcls(message,status,data), parentwrapper.common_response_wrapper, skip_none=True)
def post(self): carves = None status = 'success' host_identifier = self.parser.parse_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 exist' else: carves = dao.get_carves_by_node_id(node.id) carves = marshal(carves, wrapper.carves_wrapper) message = 'Successfully fetched the carves' else: carves = dao.get_carves_all() carves = marshal(carves, wrapper.carves_wrapper) message = 'Successfully fetched the carves' if not carves: message = "carves data doesn't exists for the input given" return marshal(respcls(message, status, carves), parentwrapper.common_response_wrapper)
def get_node_id_by_host_id(host_identifier): node = node_dao.get_node_by_host_identifier(host_identifier) if node: return node.id