LoginSignup
3
1

More than 5 years have passed since last update.

[JAWS-UG CLI] Amazon EC2 Systems Manager 入門 (3) StateManager

Last updated at Posted at 2017-04-02

この記事について

JAWS-UG CLI専門支部 #81 Amazon EC2 Systems Manager 入門で実施するハンズオン用の手順書です。

前提条件

必要な権限

作業にあたっては、以下の権限を有したIAMユーザもしくはIAMロールを利用してください。

  • EC2 Systems Manager(ssm)のフルコントロール権限
  • EC2のフルコントロール権限
  • CloudFormationの関するフルコントロール権限
  • IAMの関するフルコントロール権限
  • Configの関するフルコントロール権限
  • S3の関するフルコントロール権限
  • SNSの関するフルコントロール権限

0. 準備

0.1. リージョンを指定

ハンズオンでは東京リージョンを利用しますが、必要に応じて他のリージョンに変更してご利用ください。(東京リージョンを他の検証目的で利用している、など)

コマンド
export AWS_DEFAULT_REGION="ap-northeast-1"

0.2. 資格情報を確認

コマンド
aws configure list

インスタンスプロファイルを設定したEC2インスタンスでアクセスキーを設定せずに実行した場合、以下のようになります。

結果
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************QSAA         iam-role
secret_key     ****************c1xY         iam-role
    region                us-west-2              env    AWS_DEFAULT_REGION

0.3. バージョン確認

コマンド
aws --version
結果
(可能な限り最新版を利用しましょう)

0.4. バージョンアップ(必要に応じて)

コマンド
sudo pip install -U awscli

1. 既存のドキュメントの関連付け(インベントリの収集)

ドキュメントをインスタンスに関連付けます。
その際、ドキュメントの実行パラメータや実行周期を指定します。

ここでは、インベントリの収集を実行するドキュメントを関連付けます。

1.1. 既存のドキュメントの関連付け

既存ドキュメントの指定

コマンド
aws ssm list-documents \
    --query "DocumentIdentifiers[?contains(Name,\`Inventory\`)]"
コマンド
DOCUMENT_NAME="AWS-GatherSoftwareInventory"

ドキュメントバージョンの確認

コマンド
aws ssm list-document-versions \
    --name ${DOCUMENT_NAME} 
結果
{
    "DocumentVersions": [
        {
            "IsDefaultVersion": true,
            "Name": "AWS-GatherSoftwareInventory",
            "DocumentVersion": "1",
            "CreatedDate": 1479422093.407
        }
    ]
}

ドキュメントの実行時に指定できるパラメータの確認

コマンド
aws ssm describe-document \
    --name ${DOCUMENT_NAME} \
    --query "Document.Parameters"
結果
[
    {
        "DefaultValue": "Enabled",
        "Type": "String",
        "Name": "applications",
        "Description": "(Optional) Collect data for installed applications."
    },
    {
        "DefaultValue": "Enabled",
        "Type": "String",
        "Name": "awsComponents",
        "Description": "(Optional) Collect data for AWS Components like amazon-ssm-agent."
    },
    {
        "DefaultValue": "Enabled",
        "Type": "String",
        "Name": "networkConfig",
        "Description": "(Optional) Collect data for Network configurations."
    },
    {
        "DefaultValue": "Enabled",
        "Type": "String",
        "Name": "windowsUpdates",
        "Description": "(Optional) Collect data for all Windows Updates."
    },
    {
        "DefaultValue": "Enabled",
        "Type": "String",
        "Name": "customInventory",
        "Description": "(Optional) Collect data for custom inventory."
    }
]

実行するドキュメントの内容を確認

コマンド
aws ssm get-document \
    --name ${DOCUMENT_NAME}
結果
{
    "Content": "{\n    \"schemaVersion\": \"2.0\",\n    \"description\": \"Software Inventory Policy Document.\",\n    \"parameters\": {\n        \"applications\": {\n            \"type\": \"String\",\n            \"default\": \"Enabled\",\n            \"description\": \"(Optional) Collect data for installed applications.\",\n            \"allowedValues\": [\n                \"Enabled\",\n                \"Disabled\"\n            ]\n        },\n        \"awsComponents\": {\n            \"type\": \"String\",\n            \"default\": \"Enabled\",\n            \"description\": \"(Optional) Collect data for AWS Components like amazon-ssm-agent.\",\n            \"allowedValues\": [\n                \"Enabled\",\n                \"Disabled\"\n            ]\n        },\n        \"networkConfig\": {\n            \"type\": \"String\",\n            \"default\": \"Enabled\",\n            \"description\": \"(Optional) Collect data for Network configurations.\",\n            \"allowedValues\": [\n                \"Enabled\",\n                \"Disabled\"\n            ]\n        },\n        \"windowsUpdates\": {\n            \"type\": \"String\",\n            \"default\": \"Enabled\",\n            \"description\": \"(Optional) Collect data for all Windows Updates.\",\n            \"allowedValues\": [\n                \"Enabled\",\n                \"Disabled\"\n            ]\n        },\n        \"customInventory\": {\n            \"type\": \"String\",\n            \"default\": \"Enabled\",\n            \"description\": \"(Optional) Collect data for custom inventory.\",\n            \"allowedValues\": [\n                \"Enabled\",\n                \"Disabled\"\n            ]\n        }\n    },\n    \"mainSteps\": [\n        {\n            \"action\": \"aws:softwareInventory\",\n            \"name\": \"collectSoftwareInventoryItems\",\n            \"inputs\": {\n                \"applications\": \"{{ applications }}\",\n                \"awsComponents\": \"{{ awsComponents }}\",\n                \"networkConfig\": \"{{ networkConfig }}\",\n                \"windowsUpdates\": \"{{ windowsUpdates }}\",\n                \"customInventory\": \"{{ customInventory }}\"\n            }\n        }\n    ]\n}\n",
    "Name": "AWS-GatherSoftwareInventory"
}

ターゲットの指定

ドキュメントを関連付けるインスタンスを指定します。

(ターゲットの指定にはタグを利用することも可能です。

コマンド
TARGETS_FILE_NAME="targets_for_state_manager.json"
コマンド
cat << EOF > ${TARGETS_FILE_NAME}
[
    {
        "Key": "instanceids",
        "Values": ["${INSTANCE_ID}"]
    }
]
EOF

cat ${TARGETS_FILE_NAME}
コマンド
jsonlint -q ${TARGETS_FILE_NAME}

ドキュメント実行時パラメータの指定

コマンド
PARAMETER_FILE_NAME="parameter_for_state_manager.json"
コマンド
cat << EOF > ${PARAMETER_FILE_NAME}
{
    "applications": ["Enabled"],
    "awsComponents": ["Enabled"],
    "networkConfig": ["Enabled"],
    "windowsUpdates": ["Enabled"],
    "customInventory": ["Enabled"]
}
EOF

cat ${PARAMETER_FILE_NAME}
コマンド
jsonlint -q ${PARAMETER_FILE_NAME}

スケジュールの指定

30分ごとにコマンドを実行するスケジュールを指定します。

コマンド
SCHEDULE_EXPRESSON="cron(0 */30 * * * ? *)"

結果の出力先を指定

コマンド
OUTPUT_FILE_NAME="output_for_state_manager.json"
コマンド
cat << EOF > ${OUTPUT_FILE_NAME}
{
    "S3Location": {
        "OutputS3Region": "${AWS_DEFAULT_REGION}",
        "OutputS3BucketName": "${BUCKET_NAME}",
        "OutputS3KeyPrefix": ""
    }
}
EOF

cat ${OUTPUT_FILE_NAME}
コマンド
jsonlint -q ${OUTPUT_FILE_NAME}

パラメータの確認

コマンド
cat << ETX

    DOCUMENT_NAME: ${DOCUMENT_NAME}
    TARGETS_FILE_NAME: ${TARGETS_FILE_NAME}
    PARAMETER_FILE_NAME: ${PARAMETER_FILE_NAME}
    SCHEDULE_EXPRESSON: "${SCHEDULE_EXPRESSON}"
    OUTPUT_FILE_NAME: ${OUTPUT_FILE_NAME}

ETX
結果

    DOCUMENT_NAME: AWS-GatherSoftwareInventory
    TARGETS_FILE_NAME: targets_for_state_manager.json
    PARAMETER_FILE_NAME: parameter_for_state_manager.json
    SCHEDULE_EXPRESSON: "cron(0 0/30 * 1/1 * ? *)"
    OUTPUT_FILE_NAME: output_for_state_manager.json

ドキュメントの関連付け

コマンド
aws ssm create-association \
    --name ${DOCUMENT_NAME} \
    --targets file://${TARGETS_FILE_NAME} \
    --schedule-expression "${SCHEDULE_EXPRESSON}" \
    --parameters file://${PARAMETER_FILE_NAME} \
    --output-location file://${OUTPUT_FILE_NAME}
結果
{
    "AssociationDescription": {
        "ScheduleExpression": "cron(0 0/30 * 1/1 * ? *)",
        "OutputLocation": {
            "S3Location": {
                "OutputS3KeyPrefix": "",
                "OutputS3BucketName": "ec2-systems-manager-************",
                "OutputS3Region": "ap-northeast-1"
            }
        },
        "Name": "AWS-GatherSoftwareInventory",
        "Overview": {
            "Status": "Pending",
            "DetailedStatus": "Creating"
        },
        "AssociationId": "********-****-****-****-************",
        "DocumentVersion": "$DEFAULT",
        "LastUpdateAssociationDate": 1490522145.404,
        "Date": 1490522145.404,
        "Targets": [
            {
                "Values": [
                    "i-*****************"
                ],
                "Key": "instanceids"
            }
        ]
    }
}

関連付けを確認

コマンド
aws ssm list-associations
結果
{
    "Associations": [
        {
            "ScheduleExpression": "cron(0 0/30 * 1/1 * ? *)",
            "Name": "AWS-GatherSoftwareInventory",
            "LastExecutionDate": 1490522445.0,
            "Overview": {
                "Status": "Success",
                "AssociationStatusAggregatedCount": {
                    "Success": 1
                }
            },
            "AssociationId": "********-****-****-****-************",
            "Targets": [
                {
                    "Values": [
                        "i-*****************"
                    ],
                    "Key": "instanceids"
                }
            ]
        }
    ]
}

関連付けの詳細を確認

最近実行された関連付けを表示

コマンド
ASSOCIATION_ID=$(aws ssm list-associations \
    --query "sort_by(Associations,&LastExecutionDate)[-1].AssociationId" \
    --output text) \
    && echo ${ASSOCIATION_ID}
結果
********-****-****-****-************
コマンド
aws ssm describe-association \
    --association-id ${ASSOCIATION_ID}
結果
{
    "AssociationDescription": {
        "ScheduleExpression": "cron(0 0/30 * 1/1 * ? *)",
        "OutputLocation": {
            "S3Location": {
                "OutputS3BucketName": "ec2-systems-manager-************",
                "OutputS3Region": "ap-northeast-1"
            }
        },
        "Name": "AWS-GatherSoftwareInventory",
        "LastExecutionDate": 1490522445.0,
        "Overview": {
            "Status": "Success",
            "AssociationStatusAggregatedCount": {
                "Success": 1
            }
        },
        "AssociationId": "********-****-****-****-************",
        "DocumentVersion": "$DEFAULT",
        "LastSuccessfulExecutionDate": 1490522445.0,
        "LastUpdateAssociationDate": 1490522145.404,
        "Date": 1490522145.404,
        "Targets": [
            {
                "Values": [
                    "i-*****************"
                ],
                "Key": "instanceids"
            }
        ]
    }
}

1.2. インベントリの収集結果を確認

インベントリ情報のスキーマを確認

コマンド
aws ssm get-inventory-schema
結果
{
    "Schemas": [
        {
            "TypeName": "AWS:AWSComponent",
            "Version": "1.0",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "Name"
                },
                {
                    "DataType": "STRING",
                    "Name": "ApplicationType"
                },
                {
                    "DataType": "STRING",
                    "Name": "Publisher"
                },
                {
                    "DataType": "STRING",
                    "Name": "Version"
                },
                {
                    "DataType": "STRING",
                    "Name": "InstalledTime"
                },
                {
                    "DataType": "STRING",
                    "Name": "Architecture"
                },
                {
                    "DataType": "STRING",
                    "Name": "URL"
                }
            ]
        },
        {
            "TypeName": "AWS:Application",
            "Version": "1.0",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "Name"
                },
                {
                    "DataType": "STRING",
                    "Name": "ApplicationType"
                },
                {
                    "DataType": "STRING",
                    "Name": "Publisher"
                },
                {
                    "DataType": "STRING",
                    "Name": "Version"
                },
                {
                    "DataType": "STRING",
                    "Name": "InstalledTime"
                },
                {
                    "DataType": "STRING",
                    "Name": "Architecture"
                },
                {
                    "DataType": "STRING",
                    "Name": "URL"
                }
            ]
        },
        {
            "TypeName": "AWS:InstanceInformation",
            "Version": "1.0",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "AgentType"
                },
                {
                    "DataType": "STRING",
                    "Name": "AgentVersion"
                },
                {
                    "DataType": "STRING",
                    "Name": "ComputerName"
                },
                {
                    "DataType": "STRING",
                    "Name": "IamRole"
                },
                {
                    "DataType": "STRING",
                    "Name": "InstanceId"
                },
                {
                    "DataType": "STRING",
                    "Name": "IpAddress"
                },
                {
                    "DataType": "STRING",
                    "Name": "PlatformName"
                },
                {
                    "DataType": "STRING",
                    "Name": "PlatformType"
                },
                {
                    "DataType": "STRING",
                    "Name": "PlatformVersion"
                },
                {
                    "DataType": "STRING",
                    "Name": "ResourceType"
                }
            ]
        },
        {
            "TypeName": "AWS:Network",
            "Version": "1.0",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "Name"
                },
                {
                    "DataType": "STRING",
                    "Name": "SubnetMask"
                },
                {
                    "DataType": "STRING",
                    "Name": "Gateway"
                },
                {
                    "DataType": "STRING",
                    "Name": "DHCPServer"
                },
                {
                    "DataType": "STRING",
                    "Name": "DNSServer"
                },
                {
                    "DataType": "STRING",
                    "Name": "MacAddress"
                },
                {
                    "DataType": "STRING",
                    "Name": "IPV4"
                },
                {
                    "DataType": "STRING",
                    "Name": "IPV6"
                }
            ]
        },
        {
            "TypeName": "AWS:PatchCompliance",
            "Version": "1.0",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "Title"
                },
                {
                    "DataType": "STRING",
                    "Name": "KBId"
                },
                {
                    "DataType": "STRING",
                    "Name": "Classification"
                },
                {
                    "DataType": "STRING",
                    "Name": "Severity"
                },
                {
                    "DataType": "STRING",
                    "Name": "State"
                },
                {
                    "DataType": "STRING",
                    "Name": "InstalledTime"
                }
            ]
        },
        {
            "TypeName": "AWS:PatchSummary",
            "Version": "1.0",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "PatchGroup"
                },
                {
                    "DataType": "STRING",
                    "Name": "BaselineId"
                },
                {
                    "DataType": "STRING",
                    "Name": "SnapshotId"
                },
                {
                    "DataType": "STRING",
                    "Name": "OwnerInformation"
                },
                {
                    "DataType": "NUMBER",
                    "Name": "InstalledCount"
                },
                {
                    "DataType": "NUMBER",
                    "Name": "InstalledOtherCount"
                },
                {
                    "DataType": "NUMBER",
                    "Name": "NotApplicableCount"
                },
                {
                    "DataType": "NUMBER",
                    "Name": "MissingCount"
                },
                {
                    "DataType": "NUMBER",
                    "Name": "FailedCount"
                },
                {
                    "DataType": "STRING",
                    "Name": "OperationType"
                },
                {
                    "DataType": "STRING",
                    "Name": "OperationStartTime"
                },
                {
                    "DataType": "STRING",
                    "Name": "OperationEndTime"
                }
            ]
        },
        {
            "TypeName": "AWS:WindowsUpdate",
            "Version": "1.0",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "HotFixId"
                },
                {
                    "DataType": "STRING",
                    "Name": "Description"
                },
                {
                    "DataType": "STRING",
                    "Name": "InstalledTime"
                },
                {
                    "DataType": "STRING",
                    "Name": "InstalledBy"
                }
            ]
        }
    ]
}

アプリケーションの一覧

コマンド
aws ssm list-inventory-entries \
    --instance-id ${INSTANCE_ID} \
    --type-name AWS:Application
結果
{
    "InstanceId": "i-*****************",
    "TypeName": "AWS:Application",
    "Entries": [
        {
            "Publisher": "Amazon Web Services",
            "Version": "2.0.562.0",
            "Architecture": "64-Bit",
            "Name": "Amazon SSM Agent"
        },
        {
            "Publisher": "Amazon Web Services",
            "Version": "2.0.562.0",
            "InstalledTime": "2016-12-14T00:00:00Z",
            "Architecture": "32-Bit",
            "Name": "Amazon SSM Agent"
        },
        {
            "Publisher": "Amazon Web Services",
            "Version": "7.4.3",
            "InstalledTime": "2016-11-11T00:00:00Z",
            "Architecture": "32-Bit",
            "Name": "AWS PV Drivers"
        },
        {
            "Publisher": "Amazon Web Services Developer Relations",
            "Version": "3.9.621.0",
            "InstalledTime": "2016-12-14T00:00:00Z",
            "Architecture": "64-Bit",
            "Name": "AWS Tools for Windows"
        },
        {
            "Publisher": "Amazon Web Services",
            "Version": "1.4.15 ",
            "InstalledTime": "2016-12-14T00:00:00Z",
            "Architecture": "32-Bit",
            "Name": "aws-cfn-bootstrap"
        },
        {
            "Publisher": "Amazon Web Services",
            "Version": "4.1.1396.0",
            "Architecture": "64-Bit",
            "Name": "EC2ConfigService"
        },
        {
            "Publisher": "Amazon Web Services",
            "Version": "4.1.1396.0",
            "Architecture": "64-Bit",
            "Name": "EC2ConfigService"
        },
        {
            "Publisher": "Amazon Web Services",
            "Version": "4.1.1396.0",
            "InstalledTime": "2016-12-14T00:00:00Z",
            "Architecture": "32-Bit",
            "Name": "EC2ConfigService"
        },
        {
            "Publisher": "Microsoft Corporation",
            "Version": "15.0.1376",
            "InstalledTime": "2014-05-20T00:00:00Z",
            "Architecture": "64-Bit",
            "Name": "Update for Japanese Microsoft IME Postal Code Dictionary"
        },
        {
            "Publisher": "Microsoft Corporation",
            "Version": "15.0.1215",
            "InstalledTime": "2014-05-20T00:00:00Z",
            "Architecture": "64-Bit",
            "Name": "Update for Japanese Microsoft IME Standard Dictionary"
        },
        {
            "Publisher": "Microsoft Corporation",
            "Version": "15.0.1215",
            "InstalledTime": "2014-05-20T00:00:00Z",
            "Architecture": "64-Bit",
            "Name": "Update for Japanese Microsoft IME Standard Extended Dictionary"
        }
    ],
    "SchemaVersion": "1.0",
    "CaptureTime": "2017-04-02T13:30:03Z"
}

AWSコンポーネントの一覧

コマンド
aws ssm list-inventory-entries \
    --instance-id ${INSTANCE_ID} \
    --type-name AWS:AWSComponent
結果
{
    "InstanceId": "i-*****************",
    "TypeName": "AWS:AWSComponent",
    "Entries": [
        {
            "Publisher": "Amazon Web Services",
            "Version": "2.0.562.0",
            "Architecture": "64-Bit",
            "Name": "Amazon SSM Agent"
        },
        {
            "Publisher": "Amazon Web Services",
            "Version": "2.0.562.0",
            "InstalledTime": "2016-12-14T00:00:00Z",
            "Architecture": "32-Bit",
            "Name": "Amazon SSM Agent"
        },
        {
            "Publisher": "Amazon Web Services",
            "Version": "7.4.3",
            "InstalledTime": "2016-11-11T00:00:00Z",
            "Architecture": "32-Bit",
            "Name": "AWS PV Drivers"
        },
        {
            "Publisher": "Amazon Web Services Developer Relations",
            "Version": "3.9.621.0",
            "InstalledTime": "2016-12-14T00:00:00Z",
            "Architecture": "64-Bit",
            "Name": "AWS Tools for Windows"
        },
        {
            "Publisher": "Amazon Web Services",
            "Version": "1.4.15 ",
            "InstalledTime": "2016-12-14T00:00:00Z",
            "Architecture": "32-Bit",
            "Name": "aws-cfn-bootstrap"
        },
        {
            "Publisher": "Amazon Web Services",
            "Version": "4.1.1396.0",
            "Architecture": "64-Bit",
            "Name": "EC2ConfigService"
        },
        {
            "Publisher": "Amazon Web Services",
            "Version": "4.1.1396.0",
            "Architecture": "64-Bit",
            "Name": "EC2ConfigService"
        },
        {
            "Publisher": "Amazon Web Services",
            "Version": "4.1.1396.0",
            "InstalledTime": "2016-12-14T00:00:00Z",
            "Architecture": "32-Bit",
            "Name": "EC2ConfigService"
        }
    ],
    "SchemaVersion": "1.0",
    "CaptureTime": "2017-04-02T13:30:03Z"
}

ネットワークリソースの一覧

コマンド
aws ssm list-inventory-entries \
    --instance-id ${INSTANCE_ID} \
    --type-name AWS:Network
結果
{
    "InstanceId": "i-*****************",
    "TypeName": "AWS:Network",
    "Entries": [
        {
            "MacAddress": "06:88:05:3A:F2:DB",
            "DNSServer": "10.0.0.2",
            "IPV4": "10.0.0.243",
            "IPV6": "fe80::1181:157e:a72a:7e7c",
            "SubnetMask": "255.255.255.0",
            "Gateway": "10.0.0.1",
            "DHCPServer": "10.0.0.1",
            "Name": "AWS PV Network Device"
        }
    ],
    "SchemaVersion": "1.0",
    "CaptureTime": "2017-04-02T05:00:03Z"
}

WindowsUpdateの一覧

コマンド
aws ssm list-inventory-entries \
    --instance-id ${INSTANCE_ID} \
    --type-name AWS:WindowsUpdate
結果
{
    "InstanceId": "i-*****************",
    "TypeName": "AWS:WindowsUpdate",
    "Entries": [
        {
            "HotFixId": "KB3210135",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-12-14T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3205401",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-12-14T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3195387",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-11-22T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3182203",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-10-11T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3179948",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-10-11T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3174644",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-09-14T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3175024",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-09-14T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3177186",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-09-14T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3178539",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-09-14T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3179574",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-09-14T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3185319",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-09-14T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3185911",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-09-14T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3184943",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-09-14T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3184122",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-09-14T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3172614",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-08-13T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3170455",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-08-13T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3169704",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-08-13T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3175443",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-08-13T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3173424",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-08-13T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3172729",
            "InstalledBy": "WIN-TL2CL3K3HFR\\Administrator",
            "InstalledTime": "2016-08-13T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3160005",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-06-15T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3161949",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-06-15T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3156418",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-06-15T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3159398",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-06-15T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3161958",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-06-15T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3164035",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-06-15T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3164294",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-06-15T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3162343",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-06-15T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3162835",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-06-15T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3146751",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3125424",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3103616",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3103709",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3145384",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3134179",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3146604",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3145432",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3153704",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3156016",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3000483",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3156017",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3156059",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3156019",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3155784",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3154070",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-05-12T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3137061",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-04-12T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3135456",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-04-12T00:00:00Z",
            "Description": "Security Update"
        },
        {
            "HotFixId": "KB3138602",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-04-12T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3137725",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-04-12T00:00:00Z",
            "Description": "Update"
        },
        {
            "HotFixId": "KB3137728",
            "InstalledBy": "NT AUTHORITY\\SYSTEM",
            "InstalledTime": "2016-04-12T00:00:00Z",
            "Description": "Update"
        }
    ],
    "SchemaVersion": "1.0",
    "NextToken": "AAEAAXOw2P/vOu4NOWV0y4eJkzk+AZVmdLRdDub/qA2PLt/MYlykTAKKcMK7WeH9aIF+sEVADGJI4oIzFL/TzMu3/o41kEEaZ8A285J9q8YglJRl/xDO0zDOyoMWCgEJM28susCj7Ex9OElyvNoRGhj053J9nWEX5MIcIMwl3pkrNcavZkBBTJd38m1/3VYmQv7L3FIhdNDpz28lr5pHX/W2yAJSAw0N8SszE36nwxz9lOUgcp6BqTSCFp8pdNYSFIQ/PY4G1Q4ZDdNMhYkpXxB2k9Q=",
    "CaptureTime": "2017-04-02T05:00:03Z"
}

パッチベースラインへの準拠状況(?)

コマンド
aws ssm list-inventory-entries \
    --instance-id ${INSTANCE_ID} \
    --type-name AWS:PatchCompliance
結果
{
    "InstanceId": "i-*****************",
    "TypeName": "AWS:PatchCompliance",
    "Entries": []
}

パッチの適用状況(概況)(?)

コマンド
aws ssm list-inventory-entries \
    --instance-id ${INSTANCE_ID} \
    --type-name AWS:PatchSummary
結果
{
    "InstanceId": "i-*****************",
    "TypeName": "AWS:PatchSummary",
    "Entries": []
}

2. カスタムドキュメントの関連付け

新たに作成したドキュメントをインスタンスに関連付けます。

ここでは、イベントログの収集/パフォーマンスカウンタをカスタムメトリックに登録を実行するドキュメントを作成・関連付けます。

※IISのログなど、任意のテキストログを収集することも可能です。

2.1. ドキュメントの作成

ドキュメントは、Developers.IO(クラスメソッド様)より拝借しました。

いつもお世話になっております。

Windows ServerのCloudWatch LogsをSSMで行う

ドキュメントの定義を作成

コマンド
DOCUMENT_FILE_NAME="document_for_state_manager.json"
コマンド
cat << EOF > ${DOCUMENT_FILE_NAME}
{
  "schemaVersion": "1.2",
  "description": "Example CloudWatch Logs tasks",
  "runtimeConfig": {
    "aws:cloudWatch": {
      "settings": {
        "startType": "Enabled"
      },
      "properties": {
        "EngineConfiguration": {
          "PollInterval": "00:00:15",
          "Components": [
            {
              "Id": "CloudWatch",
              "FullName": "AWS.EC2.Windows.CloudWatch.CloudWatch.CloudWatchOutputComponent,AWS.EC2.Windows.CloudWatch",
              "Parameters": {
                "AccessKey": "",
                "SecretKey": "",
                "Region": "ap-northeast-1",
                "NameSpace": "windows-ssm-test"
              }
            },
            {
              "Id": "ApplicationEventLog",
              "FullName": "AWS.EC2.Windows.CloudWatch.EventLog.EventLogInputComponent,AWS.EC2.Windows.CloudWatch",
              "Parameters": {
                "LogName": "Application",
                "Levels": "7"
              }
            },
            {
              "Id": "SystemEventLog",
              "FullName": "AWS.EC2.Windows.CloudWatch.EventLog.EventLogInputComponent,AWS.EC2.Windows.CloudWatch",
              "Parameters": {
                "LogName": "System",
                "Levels": "7"
              }
            },
            {
              "Id": "SecurityEventLog",
              "FullName": "AWS.EC2.Windows.CloudWatch.EventLog.EventLogInputComponent,AWS.EC2.Windows.CloudWatch",
              "Parameters": {
                "LogName": "Security",
                "Levels": "7"
              }
            },
            {
              "Id": "ETW",
              "FullName": "AWS.EC2.Windows.CloudWatch.EventLog.EventLogInputComponent,AWS.EC2.Windows.CloudWatch",
              "Parameters": {
                "LogName": "Microsoft-Windows-WinINet/Analytic",
                "Levels": "7"
              }
            },
            {
              "Id": "PerformanceCounter",
              "FullName": "AWS.EC2.Windows.CloudWatch.PerformanceCounterComponent.PerformanceCounterInputComponent,AWS.EC2.Windows.CloudWatch",
              "Parameters": {
                "CategoryName": "Memory",
                "CounterName": "Available MBytes",
                "InstanceName": "",
                "MetricName": "Memory",
                "Unit": "Megabytes",
                "DimensionName": "System",
                "DimensionValue": "Default"
              }
            },
            {
              "Id": "CloudWatchLogs",
              "FullName": "AWS.EC2.Windows.CloudWatch.CloudWatchLogsOutput,AWS.EC2.Windows.CloudWatch",
              "Parameters": {
                "AccessKey": "",
                "SecretKey": "",
                "Region": "ap-northeast-1",
                "LogGroup": "test/Windows",
                "LogStream": "{instance_id}"
              }
            }
          ],
          "Flows": {
            "Flows": [
              "PerformanceCounter,CloudWatch",
              "(SystemEventLog,SecurityEventLog,ApplicationEventLog,ETW),CloudWatchLogs"
            ]
          }
        }
      }
    }
  }
}
EOF

cat ${DOCUMENT_FILE_NAME}
コマンド
jsonlint -q ${DOCUMENT_FILE_NAME}

ドキュメント名を指定

コマンド
DOCUMENT_NAME="JAWS_SAMPLE_DOCUMENT"

同名ドキュメントの不存在を確認

コマンド
aws ssm list-documents \
    --document-filter-list key="Name",value=${DOCUMENT_NAME}
結果
{
    "DocumentIdentifiers": []
}

ドキュメントを作成

コマンド
aws ssm create-document \
    --content file://${DOCUMENT_FILE_NAME} \
    --name ${DOCUMENT_NAME} \
    --document-type "Command"
結果
{
    "DocumentDescription": {
        "Status": "Creating",
        "Hash": "****************************************************************",
        "Name": "JAWS_SAMPLE_DOCUMENT",
        "Parameters": [
            {
                "Type": "StringList",
                "Name": "commands",
                "Description": "(Required) Specify a shell script or a command to run."
            }
        ],
        "DocumentType": "Command",
        "PlatformTypes": [
            "Linux"
        ],
        "DocumentVersion": "1",
        "HashType": "Sha256",
        "CreatedDate": 1490356476.255,
        "Owner": "************",
        "SchemaVersion": "2.0",
        "DefaultVersion": "1",
        "LatestVersion": "1",
        "Description": "Run a script"
    }
}

ドキュメントの存在を確認

コマンド
aws ssm list-documents \
    --document-filter-list key="Name",value=${DOCUMENT_NAME}
結果
{
    "DocumentIdentifiers": [
        {
            "Name": "JAWS_SAMPLE_DOCUMENT",
            "PlatformTypes": [
                "Linux"
            ],
            "DocumentVersion": "1",
            "DocumentType": "Command",
            "Owner": "************",
            "SchemaVersion": "2.0"
        }
    ]
}

2.2. 作成したドキュメントの関連付け

ターゲットの指定

ドキュメントを関連付けるインスタンスを指定します。

(ターゲットの指定にはタグを利用することも可能です。)

コマンド
TARGETS_FILE_NAME="targets_for_state_manager.json"
コマンド
cat << EOF > ${TARGETS_FILE_NAME}
[
    {
        "Key": "instanceids",
        "Values": ["${INSTANCE_ID}"]
    }
]
EOF

cat ${TARGETS_FILE_NAME}
コマンド
jsonlint -q ${TARGETS_FILE_NAME}

スケジュールの指定

30分ごとにコマンドを実行するスケジュールを指定します。

※30分ごとに行うのは「設定」であり、ログやメトリックの送信を30分ごとに実行するわけではありません。

コマンド
SCHEDULE_EXPRESSON="cron(0 */30 * * * ? *)"

結果の出力先を指定

コマンド
OUTPUT_FILE_NAME="output_for_state_manager.json"
コマンド
cat << EOF > ${OUTPUT_FILE_NAME}
{
    "S3Location": {
        "OutputS3Region": "${AWS_DEFAULT_REGION}",
        "OutputS3BucketName": "${BUCKET_NAME}",
        "OutputS3KeyPrefix": ""
    }
}
EOF

cat ${OUTPUT_FILE_NAME}
コマンド
jsonlint -q ${OUTPUT_FILE_NAME}

パラメータの確認

コマンド
cat << ETX

    DOCUMENT_NAME: ${DOCUMENT_NAME}
    TARGETS_FILE_NAME: ${TARGETS_FILE_NAME}
    SCHEDULE_EXPRESSON: "${SCHEDULE_EXPRESSON}"
    OUTPUT_FILE_NAME: ${OUTPUT_FILE_NAME}

ETX
結果

    DOCUMENT_NAME: JAWS_SAMPLE_DOCUMENT
    TARGETS_FILE_NAME: targets_for_state_manager.json
    SCHEDULE_EXPRESSON: "cron(0 */30 * * * ? *)"
    OUTPUT_FILE_NAME: output_for_state_manager.json

ドキュメントの関連付け

コマンド
aws ssm create-association \
    --name ${DOCUMENT_NAME} \
    --targets file://${TARGETS_FILE_NAME} \
    --schedule-expression "${SCHEDULE_EXPRESSON}" \
    --output-location file://${OUTPUT_FILE_NAME}
結果
{
    "AssociationDescription": {
        "ScheduleExpression": "cron(0 */30 * * * ? *)",
        "OutputLocation": {
            "S3Location": {
                "OutputS3KeyPrefix": "",
                "OutputS3BucketName": "ec2-systems-manager-************",
                "OutputS3Region": "ap-northeast-1"
            }
        },
        "Name": "JAWS_SAMPLE_DOCUMENT",
        "Overview": {
            "Status": "Pending",
            "DetailedStatus": "Creating"
        },
        "AssociationId": "********-****-****-****-************",
        "DocumentVersion": "$DEFAULT",
        "LastUpdateAssociationDate": 1491115608.6,
        "Date": 1491115608.6,
        "Targets": [
            {
                "Values": [
                    "i-*****************"
                ],
                "Key": "instanceids"
            }
        ]
    }
}

関連付けを確認

コマンド
aws ssm list-associations \
    --query "sort_by(Associations,&LastExecutionDate)[-1]"
結果
{
    "ScheduleExpression": "cron(0 */30 * * * ? *)",
    "Name": "JAWS_SAMPLE_DOCUMENT",
    "LastExecutionDate": 1491115609.0,
    "Overview": {
        "Status": "Success",
        "AssociationStatusAggregatedCount": {
            "Success": 1
        }
    },
    "AssociationId": "********-****-****-****-************",
    "Targets": [
        {
            "Values": [
                "i-*****************"
            ],
            "Key": "instanceids"
        }
    ]
}

関連付けの詳細を確認

最近実行された関連付けを表示

コマンド
ASSOCIATION_ID=$(aws ssm list-associations \
    --query "sort_by(Associations,&LastExecutionDate)[-1].AssociationId" \
    --output text) \
    && echo ${ASSOCIATION_ID}
結果
********-****-****-****-************
コマンド
aws ssm describe-association \
    --association-id ${ASSOCIATION_ID}
結果
{
    "AssociationDescription": {
        "ScheduleExpression": "cron(0 */30 * * * ? *)",
        "OutputLocation": {
            "S3Location": {
                "OutputS3BucketName": "ec2-systems-manager-788063364413",
                "OutputS3Region": "ap-northeast-1"
            }
        },
        "Name": "JAWS_SAMPLE_DOCUMENT",
        "LastExecutionDate": 1491115609.0,
        "Overview": {
            "Status": "Success",
            "AssociationStatusAggregatedCount": {
                "Success": 1
            }
        },
        "AssociationId": "6b57174d-7712-4806-bf24-ef261268622a",
        "DocumentVersion": "$DEFAULT",
        "LastSuccessfulExecutionDate": 1491115609.0,
        "LastUpdateAssociationDate": 1491115608.6,
        "Date": 1491115608.6,
        "Targets": [
            {
                "Values": [
                    "i-01489e58efd35ebc6"
                ],
                "Key": "instanceids"
            }
        ]
    }
}

2.3. 動作確認

イベントログが収集されたことおよびカスタムメトリックが登録されていることを確認します。

CloudWatch Logs

コマンド
aws logs get-log-events \
    --log-group-name "test/Windows" \
    --log-stream-name ${INSTANCE_ID}
結果
{
    "nextForwardToken": "f/33253002650127330106238289822711145027749153448791441408",
    "events": [
        {
            "ingestionTime": 1491115612647,
            "timestamp": 1491115609528,
            "message": "[System] [Information] [7036] [Service Control Manager] [WIN-TL2CL3K3HFR] [Application Experience サービスは 実行中 状態に移行しました。]"
        },
        {
            "ingestionTime": 1491115612847,
            "timestamp": 1491115610000,
            "message": "[Application] [Error] [1021] [Microsoft-Windows-Perflib] [WIN-TL2CL3K3HFR] [64 ビットの環境で 32 ビット拡張可能カウンター DLL ASP.NET_2.0.50727 を開くことができません。ファイルの製造元に連絡して 64 ビット バージ ョンを入手してください。または、パフォーマンス モニターの 32 ビット バージョンを使用して 32 ビット拡張可能カウンター DLL を開くこともできます。このツールを使用するには、Windows フォルダーを開き Syswow64 フォルダーを開いてから、Perfmon.exe を起動してください。]"
        },
        {
            "ingestionTime": 1491115612847,
            "timestamp": 1491115610000,
            "message": "[Application] [Error] [1017] [Microsoft-Windows-Perflib] [WIN-TL2CL3K3HFR] [\"ASP.NET_2.0.50727\" サービスのパフォーマンス カウンター ライブラリで 1 つ以上のエラーが発生したため、このサービスのパフォーマンス カウンター データ コレクションが無効になっています。この操作を強制したエラーは、アプリケーションのイベント ログに書き込まれています。このサービスのパフォーマンス カウンターを有効にする前に、エラーを修正してください。]"
        },
        {
            "ingestionTime": 1491115627233,
            "timestamp": 1491115610726,
            "message": "[Security]  [4624] [Microsoft-Windows-Security-Auditing] [WIN-TL2CL3K3HFR] [アカウントが正常にログオンしました。\r\n\r\nサブジェクト:\r\n\tセキュリティ ID:\t\tS-1-5-18\r\n\tアカウント名:\t\tWIN-TL2CL3K3HFR$\r\n\tアカウント ドメイン:\t\tWORKGROUP\r\n\tログオン ID:\t\t0x3E7\r\n\r\nログオン タイプ:\t\t\t5\r\n\r\n偽装レベル:\t\t偽装\r\n\r\n新しいログオン:\r\n\tセキュリティ ID:\t\tS-1-5-18\r\n\tアカウント名:\t\tSYSTEM\r\n\tアカウント ドメイン:\t\tNT AUTHORITY\r\n\tログオン ID:\t\t0x3E7\r\n\tログオン GUID:\t\t{00000000-0000-0000-0000-000000000000}\r\n\r\nプロセス情報:\r\n\tプロセス ID:\t\t0x2a0\r\n\tプロセス名:\t\tC:\\Windows\\System32\\services.exe\r\n\r\nネットワーク情報:\r\n\tワークステーション名:\t\r\n\tソース ネットワーク アドレス:\t-\r\n\tソース ポート:\t\t-\r\n\r\n詳細な認証情報:\r\n\tログオン プロセス:\t\tAdvapi  \r\n\t認証パッケージ:\tNegotiate\r\n\t移行されたサービス:\t-\r\n\tパッケージ名 (NTLM のみ):\t-\r\n\tキーの長さ:\t\t0\r\n\r\nこのイベントは、ログオン セッションの作成時に生成されます。このイベントは、アクセス先のコンピューターで生成されます。\r\n\r\nサブジェクトのフィールドは、ログオンを要求したローカル システム上のアカウントを 示します。これはサーバー サービスなどのサービスまたは Winlogon.exe や Services.exe などのローカル プロセスであることが最も一般的です。\r\n\r\nログオン タイプのフィールドは、発生したログオンの種類を示します。最も一般的なタイプは、2 (対話型) と 3 (ネットワーク) です。\r\n\r\n新しいログオンのフィールドは、新しいログオンを作成するアカウント、つまりログオン先のアカウントを示します。\r\n\r\nネットワークのフィールドは、リモート ログオン要求の送信元を示します。ワークステーシ ョン名は常に表示されるとは限らず、場合によっては空白のままであることがあります。\r\n\r\n偽装レベルのフィールドは、ログオン セッション内のプロセスが偽装できる程度を示します。\r\n\r\n認証情報のフィールドは、この特定のログオン要求に関する 詳細情報を示します。\r\n\t- ログオン GUID は、このイベントを KDC イベントに関連付ける場合に使用できる一意の識別子です。\r\n\t- 移行されたサービスは、このログオン要求に関与した中間サービスを示します。\r\n\t- パッケージ名は、NTLM プロトコルのうち使用されたサブプロトコルを示します。\r\n\t- キーの長さは、生成されたセッション キーの長さを示します。これは、セッション キーが要求されなかった場合は 0 になります。]"
        },
        {
            "ingestionTime": 1491115627233,
            "timestamp": 1491115610726,
            "message": "[Security]  [4672] [Microsoft-Windows-Security-Auditing] [WIN-TL2CL3K3HFR] [新しいログオンに特権が割り当てられました。\r\n\r\nサブジェクト:\r\n\tセキュリティ ID:\t\tS-1-5-18\r\n\tアカウント名:\t\tSYSTEM\r\n\tアカウント ドメイン:\t\tNT AUTHORITY\r\n\tログオン ID:\t\t0x3E7\r\n\r\n特権:\t\tSeAssignPrimaryTokenPrivilege\r\n\t\t\tSeTcbPrivilege\r\n\t\t\tSeSecurityPrivilege\r\n\t\t\tSeTakeOwnershipPrivilege\r\n\t\t\tSeLoadDriverPrivilege\r\n\t\t\tSeBackupPrivilege\r\n\t\t\tSeRestorePrivilege\r\n\t\t\tSeDebugPrivilege\r\n\t\t\tSeAuditPrivilege\r\n\t\t\tSeSystemEnvironmentPrivilege\r\n\t\t\tSeImpersonatePrivilege]"
        },
        {
            "ingestionTime": 1491115627072,
            "timestamp": 1491115610739,
            "message": "[System] [Information] [7036] [Service Control Manager] [WIN-TL2CL3K3HFR] [WMI Performance Adapter サービスは 実行中 状態に移行しました。]"
        },
        {
            "ingestionTime": 1491115627072,
            "timestamp": 1491115610818,
            "message": "[System] [Information] [7036] [Service Control Manager] [WIN-TL2CL3K3HFR] [WMI Performance Adapter サービスは 停止 状態に移行しました。]"
        },
        {
            "ingestionTime": 1491116212133,
            "timestamp": 1491116209530,
            "message": "[System] [Information] [7036] [Service Control Manager] [WIN-TL2CL3K3HFR] [Application Experience サービスは 停止 状態に移行しました。]"
        }
    ],
    "nextBackwardToken": "b/33252989269635609497467342930263047503782260033506508800"
}

CloudWatch

コマンド
aws cloudwatch list-metrics \
    --namespace "windows-ssm-test" \
    --metric-name "Memory"
結果
{
    "Metrics": [
        {
            "Namespace": "windows-ssm-test",
            "Dimensions": [
                {
                    "Name": "System",
                    "Value": "Default"
                }
            ],
            "MetricName": "Memory"
        }
    ]
}
コマンド
CWATCH_STAT_PERIOD='300'
TIME_BEFORE_MIN='1440'
コマンド
CWATCH_END_TIME=`date -u '+%FT%TZ'` \
     && echo ${CWATCH_END_TIME}
コマンド
CWATCH_START_TIME=`date -u -d "${TIME_BEFORE_MIN} mins ago" '+%FT%TZ'` \
     && echo ${CWATCH_START_TIME}
コマンド
CWATCH_NAMESPACE='windows-ssm-test'
CWATCH_METRIC_NAME='Memory'
CWATCH_DIMENSIONS='Name=System,Value=Default'
CWATCH_STATISTICS='Sum'
コマンド
aws cloudwatch get-metric-statistics \
     --namespace ${CWATCH_NAMESPACE} \
     --metric-name ${CWATCH_METRIC_NAME} \
     --start-time ${CWATCH_START_TIME} \
     --end-time ${CWATCH_END_TIME} \
     --period ${CWATCH_STAT_PERIOD} \
     --statistics ${CWATCH_STATISTICS} \
     --dimensions ${CWATCH_DIMENSIONS}
結果
{
    "Datapoints": [
        {
            "Timestamp": "2017-04-02T07:13:00Z",
            "Sum": 11184.0,
            "Unit": "Megabytes"
        },
        {
            "Timestamp": "2017-04-02T13:43:00Z",
            "Sum": 8022.0,
            "Unit": "Megabytes"
        },
        {
            "Timestamp": "2017-04-02T07:23:00Z",
            "Sum": 4471.0,
            "Unit": "Megabytes"
        },
        {
            "Timestamp": "2017-04-02T06:48:00Z",
            "Sum": 11141.0,
            "Unit": "Megabytes"
        },
        {
            "Timestamp": "2017-04-02T07:33:00Z",
            "Sum": 5016.0,
            "Unit": "Megabytes"
        },
        {
            "Timestamp": "2017-04-02T06:58:00Z",
            "Sum": 8963.0,
            "Unit": "Megabytes"
        },
        {
            "Timestamp": "2017-04-02T07:08:00Z",
            "Sum": 11230.0,
            "Unit": "Megabytes"
        },
        {
            "Timestamp": "2017-04-02T13:38:00Z",
            "Sum": 9194.0,
            "Unit": "Megabytes"
        },
        {
            "Timestamp": "2017-04-02T07:18:00Z",
            "Sum": 11173.0,
            "Unit": "Megabytes"
        },
        {
            "Timestamp": "2017-04-02T06:43:00Z",
            "Sum": 2789.0,
            "Unit": "Megabytes"
        },
        {
            "Timestamp": "2017-04-02T07:28:00Z",
            "Sum": 7146.0,
            "Unit": "Megabytes"
        },
        {
            "Timestamp": "2017-04-02T06:53:00Z",
            "Sum": 11172.0,
            "Unit": "Megabytes"
        },
        {
            "Timestamp": "2017-04-02T07:03:00Z",
            "Sum": 7849.0,
            "Unit": "Megabytes"
        },
        {
            "Timestamp": "2017-04-02T13:33:00Z",
            "Sum": 455.0,
            "Unit": "Megabytes"
        }
    ],
    "Label": "Memory"
}

3. 関連付けの削除

後日記載

4. ドキュメントの削除

後日記載

以上

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1