def _get_crash_data(node_id, crash_id): """ Given a node ID and crash ID, pull the crash data and return it """ data = "" try: cdir = settings.NODE_DIR + '/' + str(node_id) with open(cdir + '/' + str(crash_id) + '/crash_description.txt') as f: data = f.read() except Exception, e: utility.msg("Failed to read crash %d data: %s" % (node_id, e), LOG) data = None
def delete_node(node_id): """ Remove a node from the system """ try: node = Node.objects.get(id = node_id) utility.msg("Removing node %s" % node_id, LOG) node.delete() # clear the node crash dir ndir = settings.NODE_DIR + '/%s/' % node_id if os.path.isdir(ndir): rmtree(ndir) except Exception, e: utility.msg("Failed to fetch node %s: %s" % (node_id, e), LOG)
def _validate_node(request): """ Validate an incoming request; returns the node if found, otherwise None """ try: data = json.loads(request.body) node_id = data["node_id"] skey = data["skey"] node = Node.objects.get(id = node_id) if node.ip != request.META.get("REMOTE_ADDR"): utility.msg("Remote address %s does not match node %s IP (%s)" % (request.META.get("REMOTE_ADDR"), node.id, node.ip), LOG) node = None if sha256(settings.SECRET_KEY).hexdigest() != skey: utility.msg("Invalid key found for node %s from ip %s" % (node.id, request.META.get("REMOTE_ADDR")), LOG) node = None except Exception, e: utility.msg("Failed to validate node: %s" % e, LOG) node = None