I am running the following WMI Check
select LastBootUpTime from Win32_OperatingSystem which returns
20080720160058.000000-30
and would like to display the Normal Date/Time instead of the Cdate using the TuneUpReply. What value do I need in the Tune Up Reply to accomplish this?
Thanks
Rodney
Reply Value to change CDate
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
Re: Reply Value to change CDate
I think, you may use "Active Script" test method: http://www.ks-soft.net/hostmon.eng/mfra ... htm#scriptRRing wrote:and would like to display the Normal Date/Time instead of the Cdate using the TuneUpReply. What value do I need in the Tune Up Reply to accomplish this?
You just should slightly modify script below to match "Active Script" requirements:
Code: Select all
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
dtmSystemUptime = DateDiff("n", dtmLastBootUpTime, Now)
Wscript.Echo dtmSystemUptime & " minutes"
Next
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
& " " & Mid (dtmBootup, 9, 2) & ":" & _
Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2))
End Function
Max
VB Script Attempt
Alex,
I tried the script and get the following error?
Error in script:
Error number :1002
Source :Microsoft VBScript compilation error
Description :Syntax error
Text :Function WMIDateStringToDate(dtmBootup)
Line :23
Column :0
I tried the script and get the following error?
Error in script:
Error number :1002
Source :Microsoft VBScript compilation error
Description :Syntax error
Text :Function WMIDateStringToDate(dtmBootup)
Line :23
Column :0
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
Foregoing script was given you just as an example. It is not designed for "Active Script" test method. To make it work with HostMonitor you should modify it to match "Active Script" requirements. Quote from the manual: http://www.ks-soft.net/hostmon.eng/mfra ... htm#script
===========================================
Requirements to the script:
HostMonitor has just a few requirements:
1. script must contain "performtest" function. HM always call function with this name
2. "performtest" function must not have any parameters
3. "performtest" function must return string value. This string contains two parts separated by colon (:). First obligatory part contains test status, it can take following values:
* "Host is alive"
* "No answer"
* "Unknown"
* "Unknown host"
* "Ok"
* "Bad"
* "Bad contents"
Second optional part contains "Reply" value, HostMonitor displays this value in Reply field, writes to log files, uses to displays charts (Log Analyzer), etc.
Several examples:
return "Host is alive:1000 ms" | Jscript; Status: Host is alive; Reply: 1000 ms
return "Unknown host:" | Jscript; Status: Unknown host; Reply: empty
performtest = "Ok:300 Kb" | VBscript; Status: Ok; Reply: 300 Kb
performtest = "Bad:90 %" | VBscript; Status: Bad; Reply: 90 %
===========================================
Ok. Below isthe script, you may use with "Active Script" test method. It just sets the status "Ok" and shows the system uptime in minutes. You may modify it on your own. Examples of the scripts are located in "\Examples\Scripts" subfolder of the HostMonitor folder.
Regards,
Max
===========================================
Requirements to the script:
HostMonitor has just a few requirements:
1. script must contain "performtest" function. HM always call function with this name
2. "performtest" function must not have any parameters
3. "performtest" function must return string value. This string contains two parts separated by colon (:). First obligatory part contains test status, it can take following values:
* "Host is alive"
* "No answer"
* "Unknown"
* "Unknown host"
* "Ok"
* "Bad"
* "Bad contents"
Second optional part contains "Reply" value, HostMonitor displays this value in Reply field, writes to log files, uses to displays charts (Log Analyzer), etc.
Several examples:
return "Host is alive:1000 ms" | Jscript; Status: Host is alive; Reply: 1000 ms
return "Unknown host:" | Jscript; Status: Unknown host; Reply: empty
performtest = "Ok:300 Kb" | VBscript; Status: Ok; Reply: 300 Kb
performtest = "Bad:90 %" | VBscript; Status: Bad; Reply: 90 %
===========================================
Ok. Below isthe script, you may use with "Active Script" test method. It just sets the status "Ok" and shows the system uptime in minutes. You may modify it on your own. Examples of the scripts are located in "\Examples\Scripts" subfolder of the HostMonitor folder.
Code: Select all
Option Explicit
const statusAlive = "Host is alive:"
const statusDead = "No answer:"
const statusUnknown = "Unknown:"
const statusNotResolved = "Unknown host:"
const statusOk = "Ok:"
const statusBad = "Bad:"
const statusBadContents = "Bad contents:"
dim objWMIService, colOperatingSystems, dtmBootup, dtmLastBootupTime, dtmSystemUptime, objOS
const strComputer = "."
FUNCTION performtest()
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
dtmSystemUptime = DateDiff("n", dtmLastBootUpTime, Now)
performtest = statusOk+CStr(dtmSystemUptime)
Next
End Function
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
& " " & Mid (dtmBootup, 9, 2) & ":" & _
Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2))
End Function
Max