/build/static/layout/Breadcrumb_cap_w.png

View and Report Drive Info and Health (2 methods!)

Endorsed by Nick The Ninja

The problem

The K1000 default view on the drives a machine has, in my opinion, is kinda lacking. You can't see if a machine has a SSD or an HDD, you can't see the health or S.M.A.R.T. information, number of hours, etc.

In this blog, I'm going to show 2 methods of improving this, one is safe, just one PowerShell command line, so you don't even need to change the ExecutionPolicy on the machines. The second one is a bit riskier, as we are going to be depending on third party software.


Method 1

Explanation

This is the safest and easier of the two. You just need to create a Custom Inventory (CI) and paste one line of PowerShell code.

This will give us a really high tolerance pass/fail results for health, the Media type (HDD or SSD), size, etc.

This is the Result we can expect:

CeGL9uNOQcgg5YEI5JHARyPiPPKhnxGBAk+ARFzgq4gySASyJ0AiphZCBAycAInYwCuQsk8EjAYPHqz5dD6xIQJEwCAIUE9sENVEmSQC2gn8H1sgLLqGzTMiAAAAAElFTkSuQmCC

As we can see, we get a human-readable and list formatted CI with drive inventory, this will get all drive info except USB and Virtual drives (you can change that).


The Setup

To do this, go to Inventory > Software > Choose Action > New, give it a name, assign any labels and in the Custom Inventory Rule paste:

ShellCommandTextReturn(powershell.exe -command "Get-PhysicalDisk | 
Where-Object Model -NotLike '*Virtual*' | Where-Object BusType -NotLike 
'*USB*' | Select-Object -Property @{Name='ID'; 
Expression={$_.DeviceId}}, Model, HealthStatus, BusType, MediaType, 
@{Name='Size'; Expression={[math]::round($_.size/1GB, 2)}} | Sort-Object
 -Property ID | Format-List")


And voilà. Now for the interesting part.

You can report on top of these results!


Reporting


<rant> The way KACE SMA handles CI data returns is not optimal, it strips all extra spaces and place <br/> tags all over it, so to use this data on our reports we need to kinda hiper focus on one area at a time, this also rule out returning .json or .xml files to process in PowerBi for example. You may still be able to if you try to substring remove them, but I did not try that. ;~; </rant>


Go to Reporting > Reports > New (SQL), give it a name, description (optional), category (optional) and paste the query below.

This is the SQL query we'll be using, don't forget to change de SOFTWARE_ID to the ID of your CI (you can get it on the URL):

SELECT MACHINE.USER_FULLNAME, 
MACHINE.NAME,
MACHINE.BIOS_SERIAL_NUMBER,
MACHINE.CS_MODEL,
MACHINE_CUSTOM_INVENTORY.STR_FIELD_VALUE,
MACHINE_CUSTOM_INVENTORY.MODIFIED

FROM MACHINE_CUSTOM_INVENTORY

LEFT JOIN MACHINE
ON MACHINE_CUSTOM_INVENTORY.ID = MACHINE.ID

WHERE SOFTWARE_ID = 9266
AND (STR_FIELD_VALUE LIKE "%Warning%"
OR STR_FIELD_VALUE LIKE "%Unhealthy%")
As we can see, it tries to find any "Warning" or "Unhealthy" substrings on the CI string return. This Report will warn you of any disks that need IMMEDIATE attention ("Unhealthy") and disks that are really sounding bells on the S.M.A.R.T. ("Warning").

Note that you can't see disks that are showing more subtle signs of pre failure (see method 2)

With this report you can filter any info on the CI, but only on every disk at once, if you thought of a better way, please leave it in the comments.


Method 2

Explanation

This method is riskier as it involves third-party software, but still, on the grand scheme of thing, is fairly safe.

This method is much more powerful than the last, with it, we can query S.M.A.R.T. data from drives that support it, giving us a much more granular health status. With this we can also create a script to ask the drive to perform a self test, giving us updated information, without the user even noticing it.

This is an example of the result we can expect:

cAAAAASUVORK5CYII=

Unfortunate, k1000 just destroys any inline formatting via spaces (see rant in method 1), so the data is much harder to parse, but given that "RAW_VALUE" is the last in the table we can just read what the line value is in the beginning, and jump right to the end to read the raw value:

Eg. 5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - 0


The Setup

First, we need to get the smartctl.exe tool from smartmontools, you can do so here.


Open the installer, read and accept the EULA

Select Extract Files Only

D9kmJcpeJZ6pAAAAAElFTkSuQmCC

And select a folder for extraction.


Now we need to distribute this file to our endpoins, to do this, on the k1000 go to Inventory > Software > Choose Action > New, give it a name, any labels and add the file /bin/smartctl.exe from the folder you extracted smartmontools.

With that done, we now can create a File Synchronization to distribute the file. For that, go to Distribution > File Synchronizations > Choose Action > New, give it a name and select the software we just created.

In path, give the path that you want the file to be stored, remember to change it in the steps below. I'm using C:/tools/


Now to help KACE get the data (I had problems with some machines refusing to report the string) lest create a .bat that runs the smartctl.exe and redirects it to a text file we can read. To do that, copy and save the code below to a .bat file. Note that I'm only scanning /dev/sda, that means that it gets the info only from the primary disk.

@echo off

C:/tools/smartctl.exe -H -A -l selftest -l error /dev/sda > c:\tools\results.txt

type c:\tools\results.txt
Now, with the file in hand, repeat the steps you did to the smartctl.exe file to this .bat file.


Perfect! Now the only thing that we need to do is to create de CI. Open the software you created to distribute the smartctl.exe and paste the code below, remember to change the directory and .bat file name to the one you are using:

ShellCommandTextReturn(powershell -command "C:/tools/get_results.bat")


And voilà! Now you can easily view advanced disk health directly on the device's inventory page!


Reporting

I have 2 reports running on this data, one scanning for really bad disks, and a second one scanning for disk that failed the self test at some point, but are not reporting as failed in the S.M.A.R.T. health (note the latter have false some false positives due to the need to substring search the results)

First report:

SELECT MACHINE.USER_FULLNAME, 
MACHINE.NAME,
MACHINE.BIOS_SERIAL_NUMBER,
MACHINE.CS_MODEL,
MACHINE_CUSTOM_INVENTORY.STR_FIELD_VALUE,
MACHINE_CUSTOM_INVENTORY.MODIFIED

FROM MACHINE_CUSTOM_INVENTORY

LEFT JOIN MACHINE
ON MACHINE_CUSTOM_INVENTORY.ID = MACHINE.ID

WHERE SOFTWARE_ID = 9623
AND !(STR_FIELD_VALUE LIKE "%result: PASSED%"
OR STR_FIELD_VALUE LIKE "%Status: OK%"
OR STR_FIELD_VALUE LIKE "%A mandatory SMART command failed:%")

Second report:

SELECT MACHINE.USER_FULLNAME AS USUARIO, 
MACHINE.NAME AS HOSTNAME,
MACHINE.BIOS_SERIAL_NUMBER AS SERVICETAG,
MACHINE.CS_MODEL AS MODELO,
MACHINE_CUSTOM_INVENTORY.STR_FIELD_VALUE AS VALOR,
MACHINE_CUSTOM_INVENTORY.MODIFIED AS "MODIFICADO EM"

FROM MACHINE_CUSTOM_INVENTORY

LEFT JOIN MACHINE
ON MACHINE_CUSTOM_INVENTORY.ID = MACHINE.ID

WHERE SOFTWARE_ID = 9623
AND STR_FIELD_VALUE LIKE "%read failure%"


Bonus Script

You can add this script to ask smartctl to run an online short self test on the disk, it will also confirm that the file is there before running, and if not try to download it.

Here is the documentation to smartctl, so you can write your own :)


Conclusion

I hope this help somebody, now inside our company we are treating drive failure proactively instead of reactively and have lots more info about the device.

With method one I made a visualization on Power BI that show HDD/SSD ownership

D7zwb6s3saxVAAAAAElFTkSuQmCC

Be creative with this data, there is a lot of useful info on it.


Comments

This post is locked

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
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