For your specific use-case, we can extend the given CheckCIStatus script to not only check if there are operational virtual servers linked to a given physical server but also return the IP addresses of those operational servers.
To achieve this, let's assume that the relation between a physical server and its virtual servers is adequately represented in the cmdb_rel_ci table, and that the IP address of each server can be found in a field named ip_address in the relevant CI table (cmdb_ci_server, for instance).
Given these conditions, the following updated CheckCIStatus class could serve your purpose:
var CheckCIStatus = Class.create();
CheckCIStatus.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkOperationalStatus: function() {
var physicalServerName = this.getParameter('sysparm_physical_server_name'); // Assuming this is passed from the client script
// Create a glide record to look for virtual servers related to the physical server
var virtualServersGr = new GlideRecord('cmdb_rel_ci');
virtualServersGr.addQuery('parent.name', physicalServerName);
virtualServersGr.query();
var operationalServersData = []; // To hold data of operational servers
while (virtualServersGr.next()) {
// Check if the child item (assumed to be the virtual server) is operational
if (virtualServersGr.child.operational_status == '1') { // Considering '1' as the operational status value
var serverCi = new GlideRecord('cmdb_ci_server'); // Assuming this is the correct table for servers
if (serverCi.get(virtualServersGr.child.sys_id) && serverCi.ip_address) {
operationalServersData.push(serverCi.ip_address.toString()); // Collect IP addresses of operational servers
}
}
}
if (operationalServersData.length > 0) {
// Return the collected IP addresses separated by commas if there are any operational virtual servers
return operationalServersData.join(', ');
} else {
// Return a specific flag or message indicating no operational virtual servers found
return "none";
}
}
});
This script:
- Accepts the name of a physical server.
- Checks for virtual servers related to this physical server.
- Gathers the IP addresses of any operational virtual servers.
- Returns a concatenated string of those IP addresses, or "none" if there are no operational virtual servers.
To utilize this updated script with a message and make further actions based on the result (like showing a popup and clearing a mandatory variable in the user interface), you would create a client-side script that calls this server-side CheckCIStatus script through an AJAX request upon the appropriate trigger (e.g., when a server selection is made).
Given that this explanation focuses on server-side scripting and due to the complexity and variances of client-side implementations (which may involve UI Actions, Client Scripts, or other mechanisms), please ensure you adapt your client-side logic accordingly to parse the returned string of IP addresses and take the required actions, such as displaying messages and modifying form field behaviors.