/build/static/layout/Breadcrumb_cap_w.png

K1000: How to Use Custom Inventory Fields to check Last reboot and Smart Label to report the machines without reboot over 10 days

I created a vbs that looks like this:

 

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)

    dtmSystemUptimeH = DateDiff("h", dtmLastBootUpTime, Now) dtmSystemUptimeS = DateDiff("s", dtmLastBootUpTime, Now) dtmSystemUptimeM = round(dtmSystemUptimeS/60,0)

    Wscript.Echo dtmSystemUptimeH

 

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

 

Which reports how many hours since the last reboot.  I created a software inventory item called "CI - Last Reboot" and attached the vbs to the inventory.  I then used the File sync under distribution to sync the vbs to all windows pc's to a folder called c:\admin\scripts and added a shell command to the software inventory item that looks like this:

 

ShellCommandtextreturn(cmd.exe /c cscript //nologo "c:\admin\scripts\uptime.vbs")

 

That then populates the Custom inventory field with only a number...  which is in hours format.

 

Once that is in place a smart label can query the number and you can easily say more than x amount of hours ect.  And if you want then can create a "Nag" alert for users that are part of a label that indicates no reboot in x amount of time.   (this all takes 2-3 inventories before the field begins to populate)

 

I also used a similar setup for my tiered patching which goes in place next week if there is any interest in that let me know, I'd be happy to share the scripts and config for it.

 


Comments

  • This seems like a lot of work considering that KACE tracks the last reboot in the inventory already. - chucksteel 11 years ago
    • They do track it but because of the way they report it as a date I was not able to create a SQL query that worked in the Smart label's. I had worked with KACE support and no luck. - rsm11 11 years ago
      • Yes, the smart label wizard doesn't handle dates correctly when it creates the SQL. As flip1001 notes you need to manually modify the code and I'm surprised that support didn't know that. - chucksteel 11 years ago
  • Thanks I'll be trying this out! - petelanglois 11 years ago
  • I created a smart label and modified the sql using the tips from the 'Advanced Reporting' pdf from Kace.

    It will label computers that haven't rebooted or shutdown greater than 7 days.

    select MACHINE.*, C.CLIENT_CONNECTED, UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(LAST_SYNC) as LAST_SYNC_TIME,
    UNIX_TIMESTAMP(LAST_SYNC) as LAST_SYNC_SECONDS
    from ORG1.MACHINE
    LEFT JOIN KBSYS.KUID_ORGANIZATION O ON O.KUID=MACHINE.KUID LEFT JOIN KBSYS.SMMP_CONNECTION C ON C.KUID = MACHINE.KUID AND O.ORGANIZATION_ID = 1
    where (NOT OS_NAME LIKE '%server%') AND (LAST_REBOOT < DATE_SUB(CURDATE(), INTERVAL 7 DAY) OR LAST_SHUTDOWN < DATE_SUB(CURDATE(), INTERVAL 7 DAY)) - flip1001 11 years ago
    • I'm going to test this out. Thanks for the script! - petelanglois 11 years ago
    • Thanks, I'll test it out too. I'm surprised they didn't know also...... it was a frustrating call so I improvised. - rsm11 11 years ago
  • I made some changes because I found some machines don't report last reboot/shutdown properly. Most machines have identical reboot/shutdown, but sometimes they might be different. I also created a query for mysql workbench to find the problematic computers so I can see what is wrong with them.

    New smart label:
    SELECT MACHINE.*, C.CLIENT_CONNECTED, UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(LAST_SYNC) as LAST_SYNC_TIME,
    UNIX_TIMESTAMP(LAST_SYNC) as LAST_SYNC_SECONDS
    FROM ORG1.MACHINE
    LEFT JOIN KBSYS.KUID_ORGANIZATION O ON O.KUID=MACHINE.KUID LEFT JOIN KBSYS.SMMP_CONNECTION C ON C.KUID = MACHINE.KUID AND O.ORGANIZATION_ID = 1
    WHERE (NOT OS_NAME LIKE '%server%') AND (LAST_REBOOT < DATE_SUB(CURDATE(), INTERVAL 7 Day)) AND (LAST_SHUTDOWN < DATE_SUB(CURDATE(), INTERVAL 7 Day)) AND NOT (LAST_REBOOT = 'empty') AND NOT (LAST_REBOOT = '') AND NOT (LAST_SHUTDOWN = 'empty') AND NOT (LAST_SHUTDOWN = '')

    Mysql workbench query to find the problematic machines not reporting last reboot/shutdown properly:
    SELECT MACHINE.*
    FROM ORG1.MACHINE
    WHERE (LAST_REBOOT = 'empty') OR
    (LAST_REBOOT = '') OR
    (LAST_SHUTDOWN = 'empty') OR
    (LAST_SHUTDOWN = '') OR
    (NOT LAST_REBOOT = LAST_SHUTDOWN) - flip1001 11 years ago
This post is locked
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ