mirror of
https://github.com/itsdave-de/msp.git
synced 2025-05-06 15:35:12 +02:00
Merge pull request #30 from itsdave-de/feature/29-link-back-ip-address-to-object
Improve link between IT Object and IP Address Doctypes
This commit is contained in:
commit
8baacfe1be
@ -10,6 +10,7 @@
|
|||||||
"title",
|
"title",
|
||||||
"ip_address",
|
"ip_address",
|
||||||
"protocol",
|
"protocol",
|
||||||
|
"it_object_name",
|
||||||
"it_object",
|
"it_object",
|
||||||
"ip_network",
|
"ip_network",
|
||||||
"it_landscape"
|
"it_landscape"
|
||||||
@ -37,7 +38,8 @@
|
|||||||
"fieldname": "it_object",
|
"fieldname": "it_object",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "IT Object",
|
"label": "IT Object",
|
||||||
"options": "IT Object"
|
"options": "IT Object",
|
||||||
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "it_landscape",
|
"fieldname": "it_landscape",
|
||||||
@ -52,10 +54,16 @@
|
|||||||
"label": "IP Network",
|
"label": "IP Network",
|
||||||
"options": "IP Network",
|
"options": "IP Network",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "it_object_name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "IT Object Name",
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-06-17 11:21:47.850521",
|
"modified": "2022-09-05 12:03:39.294521",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "MSP",
|
"module": "MSP",
|
||||||
"name": "IP Address",
|
"name": "IP Address",
|
||||||
|
@ -8,6 +8,26 @@ import requests
|
|||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class ITObject(Document):
|
class ITObject(Document):
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
self.set_it_object_data_in_ip_address_doctype()
|
||||||
|
|
||||||
|
def set_it_object_data_in_ip_address_doctype(self):
|
||||||
|
if not self.main_ip:
|
||||||
|
return
|
||||||
|
|
||||||
|
ip_address_name_with_it_object = frappe.db.get_value("IP Address", {'it_object': self.name}, ['name'])
|
||||||
|
if ip_address_name_with_it_object:
|
||||||
|
current_ip_address_with_it_object_doctype = frappe.get_doc("IP Address", ip_address_name_with_it_object)
|
||||||
|
current_ip_address_with_it_object_doctype.it_object = None
|
||||||
|
current_ip_address_with_it_object_doctype.it_object_name = None
|
||||||
|
current_ip_address_with_it_object_doctype.save()
|
||||||
|
|
||||||
|
ip_address_doctype = frappe.get_doc("IP Address", self.main_ip)
|
||||||
|
ip_address_doctype.it_object = self.name
|
||||||
|
ip_address_doctype.it_object_name = self.title
|
||||||
|
ip_address_doctype.save()
|
||||||
|
frappe.db.commit()
|
||||||
|
|
||||||
def get_host_status_from_hosts_data(self, hosts_data, msp_settings_doc):
|
def get_host_status_from_hosts_data(self, hosts_data, msp_settings_doc):
|
||||||
|
|
||||||
@ -75,3 +95,9 @@ class ITObject(Document):
|
|||||||
'status': 500,
|
'status': 500,
|
||||||
'response': f'Data could not be fetched from {msp_settings_doc.oitc_url}. Error -> {str(exception)}'
|
'response': f'Data could not be fetched from {msp_settings_doc.oitc_url}. Error -> {str(exception)}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def set_it_object_data_in_ip_address_doctype_for_existing_it_objects():
|
||||||
|
it_objects = frappe.db.get_all("IT Object", fields=['name'])
|
||||||
|
for it_object in it_objects:
|
||||||
|
it_object_doctype = frappe.get_doc("IT Object", it_object['name'])
|
||||||
|
it_object_doctype.set_it_object_data_in_ip_address_doctype()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user