Cannot see custom systems manager inventory in AWS Console

0

Hi, I created a basic custom inventory for Disk usage by creating a Systems manager association. I am running a powershell script to get the disk information but unable to see the inventory in the console. Script runs fine and was written to the intended location in the target machine however the inventory doesn't show up in the console.

Here's my script.

function Get-EbsVolumes {[CmdletBinding()] $Map = @{"0" = '/dev/sda1'}; for($x = 1; $x -le 26; $x++) {$Map.add($x.ToString(), [String]::Format("xvd{0}",[char](97 + $x)))}; for($x = 78; $x -le 102; $x++) {$Map.add($x.ToString(), [String]::Format("xvdc{0}",[char](19 + $x)))} return Get-WmiObject -Class Win32_DiskDrive | % { $Drive = $; $SN = $Drive.SerialNumber -replace '^(vol)([^ ]+)(?: *.+)?$', '$1-$2'; Get-WmiObject -Class Win32_DiskDriveToDiskPartition | Where-Object {$.Antecedent -eq $Drive.Path.Path} | %{ $D2P = $; $Partition = Get-WmiObject -Class Win32_DiskPartition | Where-Object {$.Path.Path -eq $D2P.Dependent}; $Disk = Get-WmiObject -Class Win32_LogicalDisk`ToPartition | Where-Object {$.Antecedent -in $D2P.Dependent} | %{ $L2P = $; Get-WmiObject -Class Win32_LogicalDisk | Where-Object {$.Path.Path -in $L2P.Dependent} | %{ $L2V = $; Get-WmiObject -Class Win32_Volume | Where-Object {$.SerialNumber -eq ([Convert]::ToInt64($L2V.VolumeSerialNumber, 16))}; } } New-Object PSObject -Property @{ Device = $Map[$Drive.SCSITargetId.ToString()]; Disk = [Int]::Parse($Partition.Name.Split(",")[0].Replace("Disk #","")); Boot = $Partition.BootPartition; Partition = [Int]::Parse($Partition.Name.Split(",")[1].Replace(" Partition #","")); DriveLetter = If($Disk -eq $NULL) {"NA"} else {$Disk.DriveLetter}; VolumeDeviceID = If($Disk -eq $NULL) {"NA"} else {$Disk.DeviceID}; DriveType = If($Disk -eq $NULL) {"NA"} else {$Disk.DriveType}; IsSystemVolume = If($Disk -eq $NULL) {"NA"} else {$Disk.SystemVolume}; IsBootVolume = If($Disk -eq $NULL) {"NA"} else {$Disk.BootVolume.ToString()}; DriveLabel = If($Disk -eq $NULL) {"NA"} else {$Disk.Label}; BlockSize = $Disk.BlockSize; Capacity = ([math]::Round($Disk.Capacity /1GB,0)).ToString(); DiskType = $Partition.Type; FreeSpace = [math]::Round($Disk.FreeSpace /1GB,0); SerialNumber = $SN } } } | Where-Object { $.DriveType -eq 3 -and $_.IsSystemVolume -eq $false} }

$data = Get-EbsVolumes | Select-Object @{n="Device";e={$_.Device}},@{n="Disk";e={$_.Disk.ToString()}},@{n="Boot";e={$_.Boot.ToString()}},@{n="DriveLetter";e={$_.DriveLetter.ToString()}},@{n="VolumeDeviceID";e={$_.VolumeDeviceID}},@{n="Partition";e={$_.Partition}},@{n="DriveType";e={$_.DriveType.ToString()}},@{n="IsSystemVolume";e={$_.IsSystemVolume.ToString()}},@{n="IsBootVolume";e={$_.IsBootVolume.ToString()}},@{n="DriveLabel";e={$_.DriveLabel.ToString()}},@{n="BlockSize";e={$_.BlockSize.ToString()}},@{n="Capacity";e={$_.Capacity.ToString()}},@{n="DiskType";e={$_.DiskType.ToString()}},@{n="FreeSpace";e={$_.FreeSpace.ToString()}},@{n="SerialNumber";e={$_.SerialNumber.ToString()}}  | ConvertTo-Json -Compress

$content = "{"SchemaVersion" : "1.0", "TypeName": "Custom:EbsVolumesInventory", "Content": $data}" $instanceId = Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/instance-id $filepath = "C:\ProgramData\Amazon\SSM\InstanceData" + $instanceId + "\inventory\custom\EbsVolumesInventory.json" if (-NOT (Test-Path $filepath)) { New-Item $filepath -ItemType file} Set-Content -Path $filepath -Value $content

質問済み 2年前515ビュー
1回答
0

Hi,

Thank you for sharing your inquiry with us. It appears you may be expanding upon this SSM Inventory blog post[1] by modifying the script to suit your needs.

From my investigation, it appears that your script should be valid for creating the inventory file according to our guidelines[2]. As you mention that your script has created the EbsVolumesInventory.json custom inventory file properly, please also validate the following:

  1. Confirm that the EbsVolumesInventory.json file is formatted properly by running the contents through a JSON linter.

  2. In the Systems Manager Console, open your inventory association, and check the execution history and resources tabs to validate whether the execution for the instance was successful, or if it failed. In the "resources" tabs, you can gather specific output associated with execution which should provide further direction.

  3. If it failed, please share the error message here for further investigation.

  4. In order to gather more details about the failure message, or to check for agent errors when parsing the JSON document, you can check the SSM agent logs by filtering for the execution ID at the most recent execution time. The relevant log files are located at:

  • %PROGRAMDATA%\Amazon\SSM\Logs\ssm-document-worker.log
  • %PROGRAMDATA%\Amazon\SSM\Logs\amazon-ssm-agent.log
  • %PROGRAMDATA%\Amazon\SSM\Logs\errors.log

Reference:

[1] https://aws.amazon.com/blogs/mt/get-disk-utilization-of-your-fleet-using-ec2-systems-manager-custom-inventory-types/

[2] https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-inventory-custom.html

AWS
サポートエンジニア
Sean_S
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ