def wipe_database(self): """Completely wipe the database of the server, which includes events, reports, and alerts Arguments --------- None Returns ------- result : requests.Response Response from the server, includes response code, encoding, and text """ endpoint = urllib.parse.urljoin(self.address, "/api/data") return send_request(endpoint, "DELETE", None, self.auth)
def delete_report(self, report_id): """Remove a report from the database by ID Arguments --------- report_id : string ID of the report to remove. This ID is accessible from an MriServerDispatch instance under `report_id` Returns ------- result : requests.Response Response from the server, includes response code, encoding, and text """ endpoint = urllib.parse.urljoin(self.address, "/api/report/" + report_id) return send_request(endpoint, "DELETE", None, self.auth)
def get_reports(self): """Get a list of reports on this server Arguments --------- None Returns ------- reports : dict List of reports, in format {id: title} """ endpoint = urllib.parse.urljoin(self.address, "/api/reports") req = send_request(endpoint, "GET", None, self.auth) reports = {} for r in req.json(): reports[r['id']] = r['title'] return reports
def _send_request(self, suffix, protocol, data): """Send a report via HTTP, but allow for non-responsive or dead servers. Fill in information from the class to reduce the burden on the caller.""" url = requests.compat.urljoin(self.address, suffix) auth = self.auth return send_request(url, protocol, data, auth)