Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Probe to Determine Server Uptime

rkmullis
Kilo Contributor

Has anyone developed a probe (or the capability) to determine system uptime? I'd like for Discovery to report back system uptime for Windows servers and populate the results in a custom field. Is this doable or far-fetched?

4 REPLIES 4

anders9
ServiceNow Employee
ServiceNow Employee

You can get the last boot timeusing the Powershell command:

(Get-WmiObject -Class Win32_OperatingSystem).ConvertToDateTime($wmi.LastBootUpTime)


Community Alums
Not applicable

Win32_PerfFormattedData_PerfOS_System.SystemUpTime

I wrote a probe grab the uptime and populate a custom field on the server form, but the output from this probe is returned in seconds.


2595263


I had difficulty scripting it so that it converted properly into a GlideDate value (kept incrementing the date by the amount of time between by the time between the scans), so I ended up just converting it to days and hours and leaving it at that.


rkmullis
Kilo Contributor

Appreciate the feedback, which was big help. Here's how I accomplished the task:

Created a custom probe:

Name: Windows - System Uptime
Probe Type: WMI Probe
ECC queue topic: WMIRunner
ECC queue name: WMI: System Uptime

WMI Fields
========
Probe: Windows - System Uptime
WMI path: Win32_PerfFormattedData_PerfOS_System.SystemUpTime

Sensors
======
Name: Windows - System Uptime
Reacts to probe: Windows - System Uptime
Sensor Type: Sensor
Sensor type: Javascript

Sensor Script
=========
new DiscoverySensor({
process: function(result) {
this.parseResult(result);
},

parseResult: function(result) {
current.u_system_uptime = result.Win32_PerfFormattedData_PerfOS_System.SystemUpTime;
},

type: "DiscoverySensor"
});

I then added the custom probe to the Discovery Definition --> CI Classification --> Windows classification ("Triggers Probes"). On the custom field u_system_uptime I set the "Attributes" field on the dictionary to "format=glide_duration" (no quotes) per the wiki (http://wiki.servicenow.com/index.php?title=Modifying_the_Glide_durations_Format). Testing extensively in our dev environment produced the desire results (see attached). However, additional tweaking may be needed in order to report off of the custom field.


Very nice. I can use this for my Patch Management Team.