diff --git a/msp/msp/doctype/it_object/it_object.js b/msp/msp/doctype/it_object/it_object.js index 2d576c8..00431a7 100644 --- a/msp/msp/doctype/it_object/it_object.js +++ b/msp/msp/doctype/it_object/it_object.js @@ -2,7 +2,132 @@ // For license information, please see license.txt frappe.ui.form.on('IT Object', { - refresh: function(frm) { + refresh: function (frm) { + + const loader = ` +
+ + `; + + const container = document.getElementById('oitc-output'); + container.innerHTML = loader; + + frm.call('get_oitc_host_status_data', {}) + .then((response) => { + const container = document.getElementById('oitc-output'); + + if (response.message.status !== 200) { + container.innerHTML = response.message.response || 'An error occurred while fetching OITC data'; + return; + } + + let background = response.message?.statusColors?.upStateColor; + if (response.message?.host?.hostStatus?.currentState?.toUpperCase() === "DOWN") { + background = response.message?.statusColors?.downStateColor; + } else if (response.message?.host?.hostStatus?.currentState?.toUpperCase() === "UNREACHABLE") { + background = response.message?.statusColors?.unreachableStateColor; + } + + container.innerHTML = ` +
+
+

+ ${response.message?.host?.hostStatus?.currentState?.toUpperCase()} +

+
+
+
Current State since
+

+ ${response.message?.host?.hostStatus?.currentStateSince} +

+
+
+
Last check
+

+ ${response.message?.host?.hostStatus?.lastCheck} +

+
+
+
Next check
+

+ ${response.message?.host?.hostStatus?.nextCheck} +

+
+
+
Services
+

+ Total Services: ${response.message?.host?.servicesStatus?.totalServices} +

+
Services Status:
+

+
    +
  • OK: ${response.message?.host?.servicesStatus?.state?.ok}
  • +
  • CRITICAL: ${response.message?.host?.servicesStatus?.state?.critical}
  • +
  • WARNING: ${response.message?.host?.servicesStatus?.state?.warning}
  • +
  • UNKNOWN: ${response.message?.host?.servicesStatus?.state?.unknown}
  • +
+

+
+
+ ` + + let statusData = document.querySelector('.js-oitc-output') + statusData.style.textAlign = 'center'; + statusData.style.color = '#FFF'; + statusData.style.fontWeight = 'Bold'; + statusData.style.background = background; + statusData.style.padding = '1rem'; + }) + if (frm.doc.admin_interface_link) { frm.add_custom_button('Open Admin Interface', () => frm.trigger('open_admin_interface'), 'Actions'); }; @@ -10,10 +135,10 @@ frappe.ui.form.on('IT Object', { frm.add_custom_button('Open Monitoring', () => frm.trigger('open_monitoring'), 'Actions'); }; }, - open_admin_interface: function(frm) { + open_admin_interface: function (frm) { window.open(frm.doc.admin_interface_link, '_blank').focus(); }, - open_monitoring: function(frm) { + open_monitoring: function (frm) { window.open(frm.doc.monitoring_link, '_blank').focus(); },