Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ServiceNow MID Server Log Retrieval

This script is used to grab a agent log file from a specified **MID Server** on demand.

## What Does It Do?

It sends a command through the **ECC Queue** to the MID Server, asking it to locate a file (like `agent0.log.0`) and send its contents back to the ServiceNow instance.

---

## How to Use the Function

The function is named `getMidServerAgentLog`.

| Parameter | What it is | Example Value |
| :--- | :--- | :--- |
| **`midServerName`** | The name of your MID Server. | `"DevMidServer01"` |
| **`logFileName`** | The name of the file you want. | `"agent0.log.0"` |

### Quick Example:

```javascript
// Change "YOUR_MID_SERVER" to the actual name!
var mid = "YOUR_MID_SERVER";
var log = "agent0.log.0";

getMidServerAgentLog(mid, log);
// This creates the request in the ECC Queue.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Script to retrieve a specific log file (e.g., agent0.log.0)
* from a given ServiceNow MID Server.
*
* It creates an ECC Queue output record with the 'grabLog' source
* and 'SystemCommand' topic, which instructs the MID Server to
* return the content of the specified file.
*
* @param {string} midServerName - The name of the target MID Server (e.g., 'My_MID_Server_A').
* @param {string} logFileName - The name of the log file to retrieve (e.g., 'agent0.log.0').
* @returns {GlideRecord | null} The ECC Queue record inserted, or null if insertion failed.
*/
function getMidServerAgentLog(midServerName, logFileName) {
if (!midServerName || !logFileName) {
gs.error("MID Server name and log file name are required.");
return null;
}

var gr = new GlideRecord("ecc_queue");
gr.initialize();
gr.source = "grabLog"; // Specific source for file retrieval
gr.topic = "SystemCommand"; // Required topic for this type of command
gr.name = logFileName; // The name of the file to grab (this becomes the command's parameter)
gr.queue = "output"; // Send from ServiceNow to the MID Server
gr.state = "ready"; // Set to ready to be processed by the MID Server
gr.agent = "mid.server." + midServerName; // Full agent string
// Set a high priority to ensure it's processed quickly (optional, but good practice)
gr.priority = 100;

var sysId = gr.insert();

if (sysId) {
gs.info("Request to retrieve log '" + logFileName + "' on MID Server '" + midServerName + "' successfully placed.");
gs.info("ECC Queue Record: https://" + gs.getProperty("instance_name") + ".service-now.com/ecc_queue.do?sys_id=" + sysId);
return gr; // Returns the initialized GlideRecord object
} else {
gs.error("Failed to insert ECC Queue record.");
return null;
}
}

// --- EXAMPLE USAGE ---

// 1. Define your target MID Server name (the name *only*, not the 'mid.server.' prefix)
var targetMidServer = "MyMidServerName"; // <== **UPDATE THIS** to your actual MID Server name

// 2. Define the log file you want to retrieve
var targetLogFile = "agent0.log.0";

// 3. Call the function
var eccRecord = getMidServerAgentLog(targetMidServer, targetLogFile);

if (eccRecord) {
gs.print("Check the ECC Queue Input for a response with the log content.");
}
Loading