Skip to content

Commit

Permalink
Merge pull request #56 from sethworks/history
Browse files Browse the repository at this point in the history
History
  • Loading branch information
sethvs authored Apr 3, 2024
2 parents d14c0c6 + 10a6525 commit 74501f5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
10 changes: 7 additions & 3 deletions functions/DiskSmartInfo.functions.internal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function inGetDiskSmartInfo
$attribute.Add("Threshold", [byte]$thresholdsData[$a + 1])
$attribute.Add("Value", [byte]$smartData[$a + 3])
$attribute.Add("Worst", [byte]$smartData[$a + 4])
$attribute.Add("Data", $(inGetAttributeData -smartData $smartData -a $a))
$attribute.Add("Data", $(inGetAttributeData -smartAttributes $smartAttributes -smartData $smartData -a $a))

if ((-not $Quiet) -or (((isCritical -AttributeID $attributeID) -and $attribute.Data) -or (isThresholdReached -Attribute $attribute)))
{
Expand All @@ -123,7 +123,8 @@ function inGetDiskSmartInfo
if ($hostHistoricalData)
{
$historicalAttributeData = $historicalAttributes.Where{$_.ID -eq $attributeID}.Data
if ($Config.ShowUnchangedDataHistory -or ($historicalAttributeData -ne $attribute.Data))
if ($Config.ShowUnchangedDataHistory -or
-not (inCompareAttributeData -attributeData $attribute.Data -historicalAttributeData $historicalAttributeData))
{
$attribute.Add("DataHistory", $historicalAttributeData)
}
Expand Down Expand Up @@ -249,6 +250,7 @@ function inOverwriteAttributes
function inGetAttributeData
{
Param(
$smartAttributes,
$smartData,
$a
)
Expand Down Expand Up @@ -372,6 +374,8 @@ function inUpdateHistoricalData

$attributes = @()

$smartAttributes = inOverwriteAttributes -model $model

for ($a = $initialOffset; $a -lt $smartData.Count; $a += $attributeLength)
{
$attribute = [ordered]@{}
Expand All @@ -381,7 +385,7 @@ function inUpdateHistoricalData
if ($attributeID)
{
$attribute.Add("ID", $attributeID)
$attribute.Add("Data", $(inGetAttributeData -smartData $smartData -a $a))
$attribute.Add("Data", $(inGetAttributeData -smartAttributes $smartAttributes -smartData $smartData -a $a))

$attributes += [PSCustomObject]$attribute
}
Expand Down
28 changes: 28 additions & 0 deletions functions/DiskSmartInfo.functions.utility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,31 @@ function inComposeHistoricalDataFileName

return $fullname
}

function inCompareAttributeData
{
Param (
$attributeData,
$historicalAttributeData
)

if ($attributeData.Count -eq $historicalAttributeData.Count)
{
if ($attributeData.Count -eq 1)
{
return $attributeData -eq $historicalAttributeData
}
elseif ($attributeData.Count -gt 1)
{
for ($i = 0; $i -lt $attributeData.Count; $i++)
{
if ($attributeData[$i] -ne $historicalAttributeData[$i])
{
return $false
}
}
return $true
}
}
return $false
}
2 changes: 2 additions & 0 deletions tests/DiskSmartInfo.history.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ Describe "History" {
}

It "Unchanged attribute data" {
$diskSmartInfo[0].SmartData[13].DataHistory | Should -BeNullOrEmpty
$diskSmartInfo[0].SmartData[13].Data | Should -Be @(39,14,47)
$diskSmartInfo[0].SmartData[20].DataHistory | Should -BeNullOrEmpty
$diskSmartInfo[0].SmartData[20].Data | Should -Be 702
}
Expand Down

0 comments on commit 74501f5

Please sign in to comment.