From eed95e596fa9dba8d65986fff4f168fc3ecc3a0f Mon Sep 17 00:00:00 2001 From: Dave Date: Wed, 18 Jan 2023 23:10:22 +0100 Subject: [PATCH] urbaxkup wip --- msp/msp/doctype/msp_report/__init__.py | 0 msp/msp/doctype/msp_report/msp_report.js | 8 + msp/msp/doctype/msp_report/msp_report.json | 75 +++++++ msp/msp/doctype/msp_report/msp_report.py | 8 + msp/msp/doctype/msp_report/test_msp_report.py | 8 + msp/msp/doctype/urbackup_client/__init__.py | 0 .../urbackup_client/test_urbackup_client.py | 8 + .../urbackup_client/urbackup_client.js | 8 + .../urbackup_client/urbackup_client.json | 193 ++++++++++++++++++ .../urbackup_client/urbackup_client.py | 8 + msp/msp/doctype/urbackup_instance/__init__.py | 0 .../test_urbackup_instance.py | 8 + .../urbackup_instance/urbackup_instance.js | 8 + .../urbackup_instance/urbackup_instance.json | 61 ++++++ .../urbackup_instance/urbackup_instance.py | 73 +++++++ requirements.txt | 3 +- 16 files changed, 468 insertions(+), 1 deletion(-) create mode 100644 msp/msp/doctype/msp_report/__init__.py create mode 100644 msp/msp/doctype/msp_report/msp_report.js create mode 100644 msp/msp/doctype/msp_report/msp_report.json create mode 100644 msp/msp/doctype/msp_report/msp_report.py create mode 100644 msp/msp/doctype/msp_report/test_msp_report.py create mode 100644 msp/msp/doctype/urbackup_client/__init__.py create mode 100644 msp/msp/doctype/urbackup_client/test_urbackup_client.py create mode 100644 msp/msp/doctype/urbackup_client/urbackup_client.js create mode 100644 msp/msp/doctype/urbackup_client/urbackup_client.json create mode 100644 msp/msp/doctype/urbackup_client/urbackup_client.py create mode 100644 msp/msp/doctype/urbackup_instance/__init__.py create mode 100644 msp/msp/doctype/urbackup_instance/test_urbackup_instance.py create mode 100644 msp/msp/doctype/urbackup_instance/urbackup_instance.js create mode 100644 msp/msp/doctype/urbackup_instance/urbackup_instance.json create mode 100644 msp/msp/doctype/urbackup_instance/urbackup_instance.py diff --git a/msp/msp/doctype/msp_report/__init__.py b/msp/msp/doctype/msp_report/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/msp/msp/doctype/msp_report/msp_report.js b/msp/msp/doctype/msp_report/msp_report.js new file mode 100644 index 0000000..46d4846 --- /dev/null +++ b/msp/msp/doctype/msp_report/msp_report.js @@ -0,0 +1,8 @@ +// Copyright (c) 2022, itsdave GmbH and contributors +// For license information, please see license.txt + +frappe.ui.form.on('MSP Report', { + // refresh: function(frm) { + + // } +}); diff --git a/msp/msp/doctype/msp_report/msp_report.json b/msp/msp/doctype/msp_report/msp_report.json new file mode 100644 index 0000000..aef8bc0 --- /dev/null +++ b/msp/msp/doctype/msp_report/msp_report.json @@ -0,0 +1,75 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "MSPREP-.#####", + "creation": "2022-12-14 20:33:18.124149", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "report_generation", + "period", + "report_content", + "report_module", + "customer", + "landscape" + ], + "fields": [ + { + "fieldname": "report_generation", + "fieldtype": "Datetime", + "label": "Report Generation" + }, + { + "fieldname": "period", + "fieldtype": "Data", + "label": "Period" + }, + { + "fieldname": "report_content", + "fieldtype": "Text Editor", + "label": "Report Content" + }, + { + "fieldname": "report_module", + "fieldtype": "Select", + "label": "Report Module", + "options": "urbackup" + }, + { + "fieldname": "customer", + "fieldtype": "Link", + "label": "Customer", + "options": "Customer" + }, + { + "fieldname": "landscape", + "fieldtype": "Link", + "label": "Landscape", + "options": "IT Landscape" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2022-12-14 20:35:01.430039", + "modified_by": "Administrator", + "module": "MSP", + "name": "MSP Report", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/msp/msp/doctype/msp_report/msp_report.py b/msp/msp/doctype/msp_report/msp_report.py new file mode 100644 index 0000000..c22e0c7 --- /dev/null +++ b/msp/msp/doctype/msp_report/msp_report.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, itsdave GmbH and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class MSPReport(Document): + pass diff --git a/msp/msp/doctype/msp_report/test_msp_report.py b/msp/msp/doctype/msp_report/test_msp_report.py new file mode 100644 index 0000000..8631b4c --- /dev/null +++ b/msp/msp/doctype/msp_report/test_msp_report.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, itsdave GmbH and Contributors +# See license.txt + +# import frappe +import unittest + +class TestMSPReport(unittest.TestCase): + pass diff --git a/msp/msp/doctype/urbackup_client/__init__.py b/msp/msp/doctype/urbackup_client/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/msp/msp/doctype/urbackup_client/test_urbackup_client.py b/msp/msp/doctype/urbackup_client/test_urbackup_client.py new file mode 100644 index 0000000..b3ac75c --- /dev/null +++ b/msp/msp/doctype/urbackup_client/test_urbackup_client.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, itsdave GmbH and Contributors +# See license.txt + +# import frappe +import unittest + +class TestUrBackupClient(unittest.TestCase): + pass diff --git a/msp/msp/doctype/urbackup_client/urbackup_client.js b/msp/msp/doctype/urbackup_client/urbackup_client.js new file mode 100644 index 0000000..3610422 --- /dev/null +++ b/msp/msp/doctype/urbackup_client/urbackup_client.js @@ -0,0 +1,8 @@ +// Copyright (c) 2022, itsdave GmbH and contributors +// For license information, please see license.txt + +frappe.ui.form.on('UrBackup Client', { + // refresh: function(frm) { + + // } +}); diff --git a/msp/msp/doctype/urbackup_client/urbackup_client.json b/msp/msp/doctype/urbackup_client/urbackup_client.json new file mode 100644 index 0000000..ae3eec5 --- /dev/null +++ b/msp/msp/doctype/urbackup_client/urbackup_client.json @@ -0,0 +1,193 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "URBACKCL-.#####", + "creation": "2022-12-14 20:43:01.256112", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "it_object", + "customer", + "landscape", + "urbackup_instance", + "client_name", + "urbackup_client_data_section", + "client_version_string", + "delete_pending", + "file_ok", + "groupname", + "id", + "image_ok", + "ip", + "last_filebackup_issues", + "lastbackup", + "lastbackup_image", + "lastseen", + "online", + "os_simple", + "os_version_string", + "processes", + "client_status", + "image_disabled" + ], + "fields": [ + { + "fieldname": "client_name", + "fieldtype": "Data", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Client Name" + }, + { + "fieldname": "customer", + "fieldtype": "Link", + "label": "Customer", + "options": "Customer" + }, + { + "fieldname": "landscape", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Landscape", + "options": "IT Landscape" + }, + { + "fieldname": "urbackup_instance", + "fieldtype": "Link", + "label": "UrBackup Instance", + "options": "UrBackup Instance" + }, + { + "fieldname": "urbackup_client_data_section", + "fieldtype": "Section Break", + "label": "UrBackup Client Data" + }, + { + "fieldname": "client_version_string", + "fieldtype": "Data", + "label": "Client Version String" + }, + { + "fieldname": "delete_pending", + "fieldtype": "Data", + "label": "Delete Pending" + }, + { + "default": "0", + "fieldname": "file_ok", + "fieldtype": "Check", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "File OK" + }, + { + "fieldname": "groupname", + "fieldtype": "Data", + "label": "Groupname" + }, + { + "fieldname": "id", + "fieldtype": "Int", + "label": "ID" + }, + { + "default": "0", + "fieldname": "image_ok", + "fieldtype": "Check", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Image OK" + }, + { + "fieldname": "ip", + "fieldtype": "Data", + "label": "IP" + }, + { + "fieldname": "last_filebackup_issues", + "fieldtype": "Int", + "label": "Last Filebackup Issues" + }, + { + "fieldname": "lastbackup", + "fieldtype": "Int", + "label": "Lastbackup" + }, + { + "fieldname": "lastbackup_image", + "fieldtype": "Int", + "label": "Lastbackup Image" + }, + { + "fieldname": "lastseen", + "fieldtype": "Data", + "label": "Lastseen" + }, + { + "fieldname": "it_object", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "IT Object", + "options": "IT Object" + }, + { + "default": "0", + "fieldname": "online", + "fieldtype": "Check", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Online" + }, + { + "fieldname": "os_simple", + "fieldtype": "Data", + "label": "OS Simple" + }, + { + "fieldname": "os_version_string", + "fieldtype": "Data", + "label": "OS Version String" + }, + { + "fieldname": "processes", + "fieldtype": "Long Text", + "label": "Processes" + }, + { + "fieldname": "client_status", + "fieldtype": "Int", + "label": "Client Status" + }, + { + "fieldname": "image_disabled", + "fieldtype": "Data", + "label": "Image Disabled" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2022-12-14 22:47:53.540884", + "modified_by": "Administrator", + "module": "MSP", + "name": "UrBackup Client", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/msp/msp/doctype/urbackup_client/urbackup_client.py b/msp/msp/doctype/urbackup_client/urbackup_client.py new file mode 100644 index 0000000..fb62832 --- /dev/null +++ b/msp/msp/doctype/urbackup_client/urbackup_client.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, itsdave GmbH and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class UrBackupClient(Document): + pass diff --git a/msp/msp/doctype/urbackup_instance/__init__.py b/msp/msp/doctype/urbackup_instance/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/msp/msp/doctype/urbackup_instance/test_urbackup_instance.py b/msp/msp/doctype/urbackup_instance/test_urbackup_instance.py new file mode 100644 index 0000000..e442a4c --- /dev/null +++ b/msp/msp/doctype/urbackup_instance/test_urbackup_instance.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, itsdave GmbH and Contributors +# See license.txt + +# import frappe +import unittest + +class TestUrBackupInstance(unittest.TestCase): + pass diff --git a/msp/msp/doctype/urbackup_instance/urbackup_instance.js b/msp/msp/doctype/urbackup_instance/urbackup_instance.js new file mode 100644 index 0000000..b0c6421 --- /dev/null +++ b/msp/msp/doctype/urbackup_instance/urbackup_instance.js @@ -0,0 +1,8 @@ +// Copyright (c) 2022, itsdave GmbH and contributors +// For license information, please see license.txt + +frappe.ui.form.on('UrBackup Instance', { + // refresh: function(frm) { + + // } +}); diff --git a/msp/msp/doctype/urbackup_instance/urbackup_instance.json b/msp/msp/doctype/urbackup_instance/urbackup_instance.json new file mode 100644 index 0000000..5b5103e --- /dev/null +++ b/msp/msp/doctype/urbackup_instance/urbackup_instance.json @@ -0,0 +1,61 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "URBACK-.#####", + "creation": "2022-12-14 20:40:21.525094", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "address", + "user", + "password", + "import_clients" + ], + "fields": [ + { + "fieldname": "address", + "fieldtype": "Data", + "label": "Address" + }, + { + "fieldname": "user", + "fieldtype": "Data", + "label": "User" + }, + { + "fieldname": "password", + "fieldtype": "Password", + "label": "Password" + }, + { + "fieldname": "import_clients", + "fieldtype": "Button", + "label": "Import Clients", + "options": "import_clients" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2022-12-14 21:05:51.257205", + "modified_by": "Administrator", + "module": "MSP", + "name": "UrBackup Instance", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/msp/msp/doctype/urbackup_instance/urbackup_instance.py b/msp/msp/doctype/urbackup_instance/urbackup_instance.py new file mode 100644 index 0000000..f5fe07b --- /dev/null +++ b/msp/msp/doctype/urbackup_instance/urbackup_instance.py @@ -0,0 +1,73 @@ +# Copyright (c) 2022, itsdave GmbH and contributors +# For license information, please see license.txt + +import frappe +import urbackup_api +from frappe.model.document import Document +from pprint import pprint +from json import dumps + +class UrBackupInstance(Document): + @frappe.whitelist() + def import_clients(self): + server = urbackup_api.urbackup_server(self.address, self.user, self.get_password()) + clients = server.get_status() + if not clients: + frappe.throw("No Data Returned. Check credentials and connectivity to address.") + + existing_clients = self._get_existing_clients() + + for client in clients: + client_dict = self._get_client_dict(client) + if str(client["name"]).lower() in existing_clients: + print(str(client["name"]).lower() + " allready exists") + self._check_for_client_update(client_dict) + client_status = server.get_clientbackups(client["id"]) + pprint(client_status) + + continue + + client_doc = frappe.get_doc(client_dict) + client_doc.insert() + + + + def _get_existing_clients(self): + client_list = [] + existing_clients = frappe.get_all("UrBackup Client", filters={"urbackup_instance": self.name}, fields=["client_name"]) + for ec in existing_clients: + client_list.append(str(ec["client_name"]).lower()) + return client_list + + def _get_client_dict(self, client): + client["processes"] = dumps(client["processes"]) + client_dict = { + "doctype": "UrBackup Client", + "client_name": str(client["name"]).lower(), + "urbackup_instance": self.name, + "client_status": client["status"], + **client + } + return client_dict + + def _check_for_client_update(self, client_dict): + clients_for_name = frappe.get_all("UrBackup Client", filters={"client_name": client_dict["client_name"]}) + if len(clients_for_name) != 1: + frappe.throw("Multiple Clients found for Client Name: " + str(client_dict["client_name"])) + name = clients_for_name[0]["name"] + existing_client_doc = frappe.get_doc("UrBackup Client", name) + for k in client_dict.keys(): + if k in ("doctype", "client_name", "urbackup_instance", "name"): + continue + if isinstance(client_dict[k], bool): + client_dict[k] = 1 if client_dict[k] == True else 0 + if k == "status": + k = "client_status" + + old = client_dict[k] + new = getattr(existing_client_doc, k) + + if new != old: + print("change found for " + k + ": old=" + str(old) + " new=" + str(new)) + + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 7b9a31f..87af808 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ frappe ipaddress -passwordgenerator \ No newline at end of file +passwordgenerator +urbackup-server-web-api-wrapper