| | | Forum Guru
       
Group: Forum Members Last Login: 10/2/2009 6:52:27 PM Posts: 72, Visits: 9,166 |
| I am using this script to determine up time on some servers it will tell me 1 - if the server is over the allotted time before a restart and 2 - the amount of time it is up for.
I am using WhatsUp 12.4
Win2K3 with SP2
4GB RAM
MSSQL 2005 on different box also running Win2K3 SP2
The problem I am having it it does not return the correct value for each server (it is returning a value just not the right one.) for the server. I got the script off the forum (here) and had to make a few changes in order to send the correct info via an email. I also found the numUptime to be in seconds not in minutes and adjusted the script accordingly. I use this as an active script (VBScript) and have it trigger an email to deliver the payload of the message (the # of Day's, Hours, and Minutes the server has been up for) to our Ticketing software to generate a Work Order for out tech to restart the Server.
I have included a copy of the script here as well as some the test details of a few servers from WhatsUP and from the uptime.exe program from Microsoft (located here: [url=http://support.microsoft.com/kb/232243][/url])
This Script should return up time excessive - restart required if the up time is over 15 days
SCRIPT
=-=-=-=-=-==-=-=-=-=-==-=-=-=-=-=-=-=--=-=-==-=-=-
' Enable custom error handling
On Error Resume Next
' Declare variables
Dim numUptime, numUptMins, numUptHour, numUptDays
Dim strYear, strMonth, strDay, strDate, strHour, strMins, strTime
Dim strComputer, strMsg
strComputer = Context.GetProperty("Address")
Context.LogMessage "Attempting connection to " & strComputer
Context.LogMessage "Connecting as User: " & Context.GetProperty("CredWindows:DomainAndUserid") & " Password: " & Context.GetProperty("CredWindows assword")
' Connect to the specified computer
Set objLocator = CreateObject( "WbemScripting.SWbemLocator" )
Set objWMIService = objLocator.ConnectServer ( Context.GetProperty("Address"), "root/cimv2", Context.GetProperty("CredWindows:DomainAndUserid") , Context.GetProperty("CredWindows assword") )
'Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
' Get the "real" computer name
Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
strComputer = objItem.Name
Next
'Confirm device identity
Context.LogMessage "Device identifies itself as: " & strComputer
' Get the uptime by querying the boot time and the current time
Set colItems = objWMIService.ExecQuery( "Select * from Win32_OperatingSystem", , 48 )
For Each objItem in colItems
numUptime = DateDiff( "n", _
ParseDat( objItem.LastBootUpTime ), _
ParseDat( objItem.LocalDateTime ) )
numUptMins = numUptime Mod 60
numUptHour = (( numUptime \ 60) \60 ) Mod 24
numUptDays = (( numUptime \ 60) \60 ) \ 24
' Build message to be displayed
' Day(s)
strMsg = vbCrLf & strComputer & " has been up for " & numUptDays & " day"
' Add "s" for multiple days
If numUptDays <> 1 Then strMsg = strMsg & "s"
' Hour(s)
strMsg = strMsg & ", " & numUptHour & " hour"
' Add "s" for multiple hours
If numUptHour <> 1 Then strMsg = strMsg & "s"
' And minute(s)
strMsg = strMsg & " and " & numUptMins & " minute"
' Add "s" for multiple minutes
If numUptMins <> 1 Then strMsg = strMsg & "s"
Next
Context.LogMessage "Uptime returned: " & numUptime & " (Seconds)"
'Context.LogMessage strMsg
' Confirm the results - look for uptime beyond 15 days (numUptime is in Seconds))
If numUptime >1296000 Then
Context.SetResult 1," " & strMsg
Context.SetResult 1," up time excessive - restart required" & strMsg
Else
Context.SetResult 0," down time within tolerance" & strMsg
End If
numUptime = ""
strComputer = ""
strMsg = ""
Set colItems = Nothing
Set objWMIService = Nothing
Function ParseDat( ByVal strDate )
strYear = Left( strDate, 4 )
strMonth = Mid( strDate, 5, 2 )
strDay = Mid( strDate, 7, 2 )
strDat = strDay & "-" & strMonth & "-" & strYear
strHour = Mid( strDate, 9, 2 ) - strTimeShift
strMins = Mid( strDate, 11, 2 )
strTime = strHour & ":" & strMins
ParseDat = strDat & " " & strTime
End Function
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Test from WhatsUP's Test feature in the Active Monitor Library:
Attempting connection to 10.8.0.30
Connecting as User: "domain was here"\"username was here" Password: xxxxxxxxxxxxxxxxxxxxxxxxxxx
Device identifies itself as: "servername was here"
Uptime returned: 232442 (Seconds)
down time within tolerance
CSSVR01 has been up for 2 days, 16 hours and 2 minutes
Here is the test from using Microsoft's Uptime.exe program (which is the correct amount of time the server has been up)
I:\>uptime.exe \\"servername was here"
\\"servername was here" has been up for: 13 day(s), 10 hour(s), 7 minute(s), 39 second(s)
As you can see the values are much different 13 days vs 2 days.
Any Ideas?
Bill
|
| | | | Junior Member
       
Group: Forum Members Last Login: 7/9/2009 11:02:30 AM Posts: 19, Visits: 189 |
| No scripting wiz so can't help fix that but I would recommend using snmp, its so much easier as uptime is innate. Added benefit of adding the snmp service to your servers is that you can use the cpu, disk and memory usage performance monitors too.
|
| | | | Forum Guru
       
Group: Forum Members Last Login: 10/2/2009 6:52:27 PM Posts: 72, Visits: 9,166 |
| | I understand the the reason to use SNMP but this script monitors when it is above a certain range. I can use OID 1.3.6.1.2.1.1.3 to provide me with the data but I have no way to provide a range in WUP to trigger an alert to reboot the machine. |
| | | | Forum Guru
       
Group: Forum Members Last Login: 8/13/2009 10:37:24 AM Posts: 65, Visits: 608 |
| Bill Farinella (6/11/2009) I understand the the reason to use SNMP but this script monitors when it is above a certain range. I can use OID 1.3.6.1.2.1.1.3 to provide me with the data but I have no way to provide a range in WUP to trigger an alert to reboot the machine.
Can't you use that OID in an Active monitor and use the Check type Range of Values? |
| | | | Forum Guru
       
Group: Forum Members Last Login: 10/2/2009 6:52:27 PM Posts: 72, Visits: 9,166 |
| | The range if values will not accept the 0days 00:00:00.0 to 13days 12:05:99.12 range. I did try those settings before posting but was unsuccessful. |
| | | | Forum Guru
       
Group: Forum Members Last Login: 10/2/2009 6:52:27 PM Posts: 72, Visits: 9,166 |
| | does anyone have any ideas that could help? |
| | | | Forum Guru
       
Group: Forum Members Last Login: 10/2/2009 6:52:27 PM Posts: 72, Visits: 9,166 |
| | Is there anyone that can give me a hand with this script? PLEASE? |
| | | | Forum Guru
       
Group: Forum Members Last Login: 8/13/2009 10:37:24 AM Posts: 65, Visits: 608 |
| Bill Farinella (6/12/2009) The range if values will not accept the 0days 00:00:00.0 to 13days 12:05:99.12 range. I did try those settings before posting but was unsuccessful.
Convert the number into range you want. For example, if you are looking to reboot if the uptime was over 15 days, your low value would be 0 and your high value would be 129,600,000. This is the time tick in hundredths of a second (86400 seconds/day * 15 days * 100). I've tested it, and it works. Well, not the reboot part, but the checking for the monitor. |
| | | | Forum Guru
       
Group: Forum Members Last Login: 10/2/2009 6:52:27 PM Posts: 72, Visits: 9,166 |
| | I will give it a try. Thank you for responding and giving me a hand with this. |
| |
|
|