聚合清单数据 - Amazon Systems Manager
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

聚合清单数据

在为 Amazon Systems Manager Inventory 配置托管式节点后,您可以查看清单数据的聚合计数。例如,假设您配置了数十或数百个托管式节点来收集 AWS:Application 清单类型。通过使用此部分中的信息,您即可查看配置为收集此数据的节点数的准确计数。

您还可以通过针对某数据类型进行聚合以查看特定清单详细信息。例如,AWS:InstanceInformation 清单类型收集 Platform 数据类型的操作系统平台信息。通过聚合 Platform 数据类型的数据,您可以快速查看运行 Windows、Linux 以及 macOS 的节点的数量。

本节中的过程介绍了如何使用 Amazon Command Line Interface (Amazon CLI) 查看清单数据的聚合计数。您还可以在 Amazon Systems Manager 控制台的 Inventory (清单) 页面上预配置聚合计数。这些预配置的控制面板称为 Inventory Insights,而且它们提供清单配置问题的一键修正。

请注意有关清单数据的聚合计数的以下重要详细信息:

  • 如果您终止配置为收集清单数据的托管式节点,Systems Manager 会将清单数据保留 30 天,然后将其删除。对于正在运行的节点,系统将删除存在超过 30 天的清单数据。如果您需要将清单数据存储 30 天以上,可以使用 Amazon Config 来记录历史记录,或者定期查询数据并将其上传到 Amazon Simple Storage Service (Amazon S3) 存储桶。

  • 如果先前已将某个节点配置为报告某一特定清单数据类型(例如 AWS:Network),后来您将该配置更改为停止收集该类型,聚合计数仍会显示 AWS:Network 数据,直到该节点已被终止并已经过 30 天为止。

有关如何快速配置并收集某一特定 Amazon Web Services 账户 中所有节点(以及未来可能在该账户中创建的任何节点)中的清单数据的信息,请参阅 使用控制台配置收集

聚合清单数据以查看收集特定类型数据的节点的计数

您可以使用 Amazon Systems Manager GetInventory API 操作,查看收集一个或多个清单类型和数据类型的节点的聚合计数。例如,AWS:InstanceInformation 清单类型使您能够通过结合使用 GetInventory API 操作和 AWS:InstanceInformation.PlatformType 数据类型,来查看操作系统的聚合。以下是示例 Amazon CLI 命令和输出。

aws ssm get-inventory --aggregators "Expression=AWS:InstanceInformation.PlatformType"

系统将返回类似于以下内容的信息。

{
   "Entities":[
      {
         "Data":{
            "AWS:InstanceInformation":{
               "Content":[
                  {
                     "Count":"7",
                     "PlatformType":"windows"
                  },
                  {
                     "Count":"5",
                     "PlatformType":"linux"
                  }
               ]
            }
         }
      }
   ]
}
开始使用

确定要查看其计数的清单类型和数据类型。您可以通过在 Amazon CLI 中运行以下命令查看支持聚合的清单类型和数据类型的列表。

aws ssm get-inventory-schema --aggregator

该命令返回支持聚合的清单类型和数据类型的 JSON 列表。TypeName 字段显示支持的清单类型。此处,Name (名称) 字段显示每个数据类型。例如,在以下列表中,AWS:Application 清单类型包括 NameVersion 的数据类型。

{
    "Schemas": [
        {
            "TypeName": "AWS:Application",
            "Version": "1.1",
            "DisplayName": "Application",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "Name"
                },
                {
                    "DataType": "STRING",
                    "Name": "Version"
                }
            ]
        },
        {
            "TypeName": "AWS:InstanceInformation",
            "Version": "1.0",
            "DisplayName": "Platform",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "PlatformName"
                },
                {
                    "DataType": "STRING",
                    "Name": "PlatformType"
                },
                {
                    "DataType": "STRING",
                    "Name": "PlatformVersion"
                }
            ]
        },
        {
            "TypeName": "AWS:ResourceGroup",
            "Version": "1.0",
            "DisplayName": "ResourceGroup",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "Name"
                }
            ]
        },
        {
            "TypeName": "AWS:Service",
            "Version": "1.0",
            "DisplayName": "Service",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "Name"
                },
                {
                    "DataType": "STRING",
                    "Name": "DisplayName"
                },
                {
                    "DataType": "STRING",
                    "Name": "ServiceType"
                },
                {
                    "DataType": "STRING",
                    "Name": "Status"
                },
                {
                    "DataType": "STRING",
                    "Name": "StartType"
                }
            ]
        },
        {
            "TypeName": "AWS:WindowsRole",
            "Version": "1.0",
            "DisplayName": "WindowsRole",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "Name"
                },
                {
                    "DataType": "STRING",
                    "Name": "DisplayName"
                },
                {
                    "DataType": "STRING",
                    "Name": "FeatureType"
                },
                {
                    "DataType": "STRING",
                    "Name": "Installed"
                }
            ]
        }
    ]
}

您可以通过创建使用以下语法的命令来聚合任何所列清单类型的数据。

aws ssm get-inventory --aggregators "Expression=InventoryType.DataType"

下面是一些示例。

示例 1

此示例聚合节点使用的 Windows 角色的计数。

aws ssm get-inventory --aggregators "Expression=AWS:WindowsRole.Name"

示例 2

此示例聚合安装在节点上的应用程序的计数。

aws ssm get-inventory --aggregators "Expression=AWS:Application.Name"
组合多个聚合器

您也可以在一个命令中组合多个清单类型和数据类型,以帮助您更好地了解数据。下面是一些示例。

示例 1

此示例聚合节点使用的操作系统类型的计数。它还会返回操作系统的特定名称。

aws ssm get-inventory --aggregators '[{"Expression": "AWS:InstanceInformation.PlatformType", "Aggregators":[{"Expression": "AWS:InstanceInformation.PlatformName"}]}]'

示例 2

此示例聚合在节点上运行的应用程序和每个应用程序的特定版本的计数。

aws ssm get-inventory --aggregators '[{"Expression": "AWS:Application.Name", "Aggregators":[{"Expression": "AWS:Application.Version"}]}]'

如果您愿意,也可以使用 JSON 文件中的一个或多个清单类型和数据类型创建聚合表达式并从 Amazon CLI 调用该文件。该文件中的 JSON 必须使用以下语法。

[ { "Expression": "string", "Aggregators": [ { "Expression": "string" } ] } ]

您必须使用 .json 文件扩展名保存该文件。

以下是使用多个清单类型和数据类型的示例。

[ { "Expression": "AWS:Application.Name", "Aggregators": [ { "Expression": "AWS:Application.Version", "Aggregators": [ { "Expression": "AWS:InstanceInformation.PlatformType" } ] } ] } ]

使用以下命令从 Amazon CLI 调用该文件。

aws ssm get-inventory --aggregators file://file_name.json

此命令会返回如下信息。

{"Entities": 
 [
   {"Data": 
     {"AWS:Application": 
       {"Content": 
         [
           {"Count": "3", 
            "PlatformType": "linux", 
            "Version": "2.6.5", 
            "Name": "audit-libs"}, 
           {"Count": "2", 
            "PlatformType": "windows", 
            "Version": "2.6.5", 
            "Name": "audit-libs"}, 
           {"Count": "4", 
            "PlatformType": "windows", 
            "Version": "6.2.8", 
            "Name": "microsoft office"}, 
           {"Count": "2", 
            "PlatformType": "windows", 
            "Version": "2.6.5", 
            "Name": "chrome"}, 
           {"Count": "1", 
            "PlatformType": "linux", 
            "Version": "2.6.5", 
            "Name": "chrome"}, 
           {"Count": "2", 
            "PlatformType": "linux", 
            "Version": "6.3", 
            "Name": "authconfig"}
         ]
       }
     }, 
    "ResourceType": "ManagedInstance"}
 ]
}

使用组聚合清单数据,以查看已配置为以及未配置为收集某个清单类型的节点

使用 Systems Manager Inventory 中的组,您可以快速查看已配置为和未配置为收集一个或多个清单类型的托管式节点的计数。利用组,可指定一个或多个清单类型和使用 exists 运算符的筛选条件。

例如,假设您已将四个托管式节点配置为收集以下清单类型:

  • 节点 1:AWS:Application

  • 节点 2:AWS:File

  • 节点 3:AWS:ApplicationAWS:File

  • 节点 4:AWS:Network

您可以从 Amazon CLI 运行以下命令,以查看已配置为收集 AWS:ApplicationAWS:File inventory 类型的节点的数量。该响应还返回未配置为收集这两个清单类型的节点数的计数。

aws ssm get-inventory --aggregators 'Groups=[{Name=ApplicationAndFile,Filters=[{Key=TypeName,Values=[AWS:Application],Type=Exists},{Key=TypeName,Values=[AWS:File],Type=Exists}]}]'

该命令响应显示仅一个托管式节点已配置为收集 AWS:ApplicationAWS:File 清单类型。

{
   "Entities":[
      {
         "Data":{
            "ApplicationAndFile":{
               "Content":[
                  {
                     "notMatchingCount":"3"
                  },
                  {
                     "matchingCount":"1"
                  }
               ]
            }
         }
      }
   ]
}
注意

组不会返回数据类型计数。此外,您也无法深入查询结果来查看已配置为或未配置为收集该清单类型的节点的 ID。

如果您愿意,也可以使用 JSON 文件中的一个或多个清单类型创建聚合表达式并从 Amazon CLI 调用该文件。该文件中的 JSON 必须使用以下语法:

{ "Aggregators":[ { "Groups":[ { "Name":"Name", "Filters":[ { "Key":"TypeName", "Values":[ "Inventory_type" ], "Type":"Exists" }, { "Key":"TypeName", "Values":[ "Inventory_type" ], "Type":"Exists" } ] } ] } ] }

您必须使用 .json 文件扩展名保存该文件。

使用以下命令从 Amazon CLI 调用该文件。

aws ssm get-inventory --cli-input-json file://file_name.json
其他示例

以下示例说明了如何聚合清单数据,以查看已配置为和未配置为收集指定清单类型的托管式节点。这些示例使用 Amazon CLI。每个示例包含一个带筛选条件的完整命令,您可以从命令行和示例 input.json 文件运行该命令(如果您更喜欢在文件中输入该信息)。

示例 1

此示例聚合已配置为和未配置为收集 AWS:ApplicationAWS:File 清单类型的节点的计数。

从 Amazon CLI 运行以下命令。

aws ssm get-inventory --aggregators 'Groups=[{Name=ApplicationORFile,Filters=[{Key=TypeName,Values=[AWS:Application, AWS:File],Type=Exists}]}]'

如果您更喜欢使用文件,请将以下示例复制并粘贴到文件中并且将其另存为 input.json。

{ "Aggregators":[ { "Groups":[ { "Name":"ApplicationORFile", "Filters":[ { "Key":"TypeName", "Values":[ "AWS:Application", "AWS:File" ], "Type":"Exists" } ] } ] } ] }

从 Amazon CLI 运行以下命令。

aws ssm get-inventory --cli-input-json file://input.json

此命令会返回如下信息。

{
   "Entities":[
      {
         "Data":{
            "ApplicationORFile":{
               "Content":[
                  {
                     "notMatchingCount":"1"
                  },
                  {
                     "matchingCount":"3"
                  }
               ]
            }
         }
      }
   ]
}

示例 2

此示例聚合已配置为和未配置为收集 AWS:ApplicationAWS:FileAWS:Network 清单类型的节点的计数。

从 Amazon CLI 运行以下命令。

aws ssm get-inventory --aggregators 'Groups=[{Name=Application,Filters=[{Key=TypeName,Values=[AWS:Application],Type=Exists}]}, {Name=File,Filters=[{Key=TypeName,Values=[AWS:File],Type=Exists}]}, {Name=Network,Filters=[{Key=TypeName,Values=[AWS:Network],Type=Exists}]}]'

如果您更喜欢使用文件,请将以下示例复制并粘贴到文件中并且将其另存为 input.json。

{ "Aggregators":[ { "Groups":[ { "Name":"Application", "Filters":[ { "Key":"TypeName", "Values":[ "AWS:Application" ], "Type":"Exists" } ] }, { "Name":"File", "Filters":[ { "Key":"TypeName", "Values":[ "AWS:File" ], "Type":"Exists" } ] }, { "Name":"Network", "Filters":[ { "Key":"TypeName", "Values":[ "AWS:Network" ], "Type":"Exists" } ] } ] } ] }

从 Amazon CLI 运行以下命令。

aws ssm get-inventory --cli-input-json file://input.json

此命令会返回如下信息。

{
   "Entities":[
      {
         "Data":{
            "Application":{
               "Content":[
                  {
                     "notMatchingCount":"2"
                  },
                  {
                     "matchingCount":"2"
                  }
               ]
            },
            "File":{
               "Content":[
                  {
                     "notMatchingCount":"2"
                  },
                  {
                     "matchingCount":"2"
                  }
               ]
            },
            "Network":{
               "Content":[
                  {
                     "notMatchingCount":"3"
                  },
                  {
                     "matchingCount":"1"
                  }
               ]
            }
         }
      }
   ]
}