Page 1 of 1 1
Topic Options
#178470 - 2007-07-26 05:58 PM Uptime Calculator (New code)
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Found a different way to calculate uptime.
keep in mind that for this to work you HAVE to have SNMP and WMI SNMP installled on your system in Windows Components, they are NOT installed by default.

Anyway since it's late and i'm tired I probably calculated it wrong somewhere, if someone likes to test it and help me out here with the calculation I'd be very much obliged.

 Code:
$strComputer = "."
$objLocator = CreateObject("WbemScripting.SWbemLocator")
$objWMIService = $objLocator.ConnectServer($strComputer, "root/snmp/localhost")
$objNamedValueSet = CreateObject("WbemScripting.SWbemNamedValueSet")
$colItems = $objWMIService.Instancesof("SNMP_RFC1213_MIB_system",,$objNamedValueSet)
For each $objItem in $colItems
  $x = CDBL($objItem.sysUpTime)
  $mili = $x mod 1000
  $sec = ($x / 1000) mod 60
  $min = ($x / 60000) mod 60
  $hour = ($x / 360000) mod 24
  "sysUpTime: " + CStr($Hour) + ":" + CStr($min) + ":" + CStr($sec) ?
  ?
Next

Top
#178497 - 2007-07-27 01:53 AM Re: Uptime Calculator (New code) [Re: Arend_]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
for some sad reason, this udf doesn't show up in the udf mirror...
but anyhow, it's wmi and doesn't require any special pieces:
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Board=7&Number=84092&
_________________________
!

download KiXnet

Top
#178501 - 2007-07-27 02:13 AM Re: Uptime Calculator (New code) [Re: Lonkero]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
And there's this UDF , which has no dependencies other than WMI, and does not have the issues with timezones.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#178506 - 2007-07-27 08:51 AM Re: Uptime Calculator (New code) [Re: Glenn Barnas]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Hence why the topic said "New code".
Glenn: I've no idea why you would mention issue's with timezones ?

Anyway, this UDF is designed to show uptime in a simple way.

Top
#178528 - 2007-07-27 09:59 PM Re: Uptime Calculator (New code) [Re: Arend_]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Since your code retrieves the uptime value directly and simply translates to "human readable" form, it is not subject to timezone offsets. Lonk's code reads the remote boot time, then subtracts that from the LOCAL current time to calculate the uptime. If the two computers are in different time zones, the result would be inaccurate. My UDF gets both boot and current time from the remote computer. This way, both values are relative to each other, and the calculation is correct. With Lonk's UDF, if I reboot a computer on the west coast (I'm on the east coast) and immediatly run the uptime udf, it reports 4 hours and some minutes, due to the 4 hour difference between time zones.

I like your concept, but the reliance on SNMP is an issue for me in my environment. I haven't found a way to obtain a direct uptime value from remote computers without calculations or third party tools (which basically do the same calculations). WMI reports boot time on all platforms that support WMI, but I havent found that it reports uptime on the same platforms.

Bottom line - there's no issue with your UDF other than the need for SNMP.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#178533 - 2007-07-28 11:32 AM Re: Uptime Calculator (New code) [Re: Glenn Barnas]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Ah ok, I understand.
I find it very unhandy too that SNMP isn't installed by default. It should be because all other devices/OS's do have it installed by default. Our network's RIS images are configured to install it during installation though. Although I haven't found a way to easily install/depoy it for current installations....yet.

Top
#178534 - 2007-07-28 12:34 PM Re: Uptime Calculator (New code) [Re: Arend_]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
 Quote:

....
Although I haven't found a way to easily install/depoy it for current installations....yet.


Advanced Scripting » Automated install of SNMP
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#178539 - 2007-07-29 04:09 PM Re: Uptime Calculator (New code) [Re: Mart]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Thx mart \:\)
But I'm into a more solid solution for this, will post more info as I progress \:\)

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1527 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.171 seconds in which 0.145 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org