{
  "typeName" : "AWS::IoT::SecurityProfile",
  "description" : "A security profile defines a set of expected behaviors for devices in your account.",
  "sourceUrl" : "https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-iot.git",
  "definitions" : {
    "Behavior" : {
      "description" : "A security profile behavior.",
      "type" : "object",
      "properties" : {
        "Name" : {
          "description" : "The name for the behavior.",
          "type" : "string",
          "pattern" : "[a-zA-Z0-9:_-]+",
          "minLength" : 1,
          "maxLength" : 128
        },
        "Metric" : {
          "description" : "What is measured by the behavior.",
          "type" : "string",
          "pattern" : "[a-zA-Z0-9:_-]+",
          "minLength" : 1,
          "maxLength" : 128
        },
        "MetricDimension" : {
          "$ref" : "#/definitions/MetricDimension"
        },
        "Criteria" : {
          "$ref" : "#/definitions/BehaviorCriteria"
        },
        "SuppressAlerts" : {
          "description" : "Manage Detect alarm SNS notifications by setting behavior notification to on or suppressed. Detect will continue to performing device behavior evaluations. However, suppressed alarms wouldn't be forwarded for SNS notification.",
          "type" : "boolean"
        },
        "ExportMetric" : {
          "$ref" : "#/definitions/ExportMetric"
        }
      },
      "required" : [ "Name" ],
      "additionalProperties" : false
    },
    "ExportMetric" : {
      "description" : "Flag to enable/disable metrics export for metric to be retained.",
      "type" : "boolean"
    },
    "MetricDimension" : {
      "description" : "The dimension of a metric.",
      "type" : "object",
      "properties" : {
        "DimensionName" : {
          "description" : "A unique identifier for the dimension.",
          "type" : "string",
          "pattern" : "[a-zA-Z0-9:_-]+",
          "minLength" : 1,
          "maxLength" : 128
        },
        "Operator" : {
          "description" : "Defines how the dimensionValues of a dimension are interpreted.",
          "type" : "string",
          "enum" : [ "IN", "NOT_IN" ]
        }
      },
      "required" : [ "DimensionName" ],
      "additionalProperties" : false
    },
    "BehaviorCriteria" : {
      "description" : "The criteria by which the behavior is determined to be normal.",
      "type" : "object",
      "properties" : {
        "ComparisonOperator" : {
          "description" : "The operator that relates the thing measured (metric) to the criteria (containing a value or statisticalThreshold).",
          "type" : "string",
          "enum" : [ "less-than", "less-than-equals", "greater-than", "greater-than-equals", "in-cidr-set", "not-in-cidr-set", "in-port-set", "not-in-port-set", "in-set", "not-in-set" ]
        },
        "Value" : {
          "$ref" : "#/definitions/MetricValue"
        },
        "DurationSeconds" : {
          "type" : "integer",
          "description" : "Use this to specify the time duration over which the behavior is evaluated."
        },
        "ConsecutiveDatapointsToAlarm" : {
          "description" : "If a device is in violation of the behavior for the specified number of consecutive datapoints, an alarm occurs. If not specified, the default is 1.",
          "type" : "integer",
          "minimum" : 1,
          "maximum" : 10
        },
        "ConsecutiveDatapointsToClear" : {
          "description" : "If an alarm has occurred and the offending device is no longer in violation of the behavior for the specified number of consecutive datapoints, the alarm is cleared. If not specified, the default is 1.",
          "type" : "integer",
          "minimum" : 1,
          "maximum" : 10
        },
        "StatisticalThreshold" : {
          "$ref" : "#/definitions/StatisticalThreshold"
        },
        "MlDetectionConfig" : {
          "$ref" : "#/definitions/MachineLearningDetectionConfig"
        }
      },
      "additionalProperties" : false
    },
    "MetricValue" : {
      "description" : "The value to be compared with the metric.",
      "type" : "object",
      "properties" : {
        "Count" : {
          "description" : "If the ComparisonOperator calls for a numeric value, use this to specify that (integer) numeric value to be compared with the metric.",
          "type" : "string",
          "minimum" : 0
        },
        "Cidrs" : {
          "description" : "If the ComparisonOperator calls for a set of CIDRs, use this to specify that set to be compared with the metric.",
          "type" : "array",
          "uniqueItems" : true,
          "insertionOrder" : false,
          "items" : {
            "type" : "string"
          }
        },
        "Ports" : {
          "description" : "If the ComparisonOperator calls for a set of ports, use this to specify that set to be compared with the metric.",
          "type" : "array",
          "uniqueItems" : true,
          "insertionOrder" : false,
          "items" : {
            "type" : "integer",
            "minimum" : 0,
            "maximum" : 65535
          }
        },
        "Number" : {
          "description" : "The numeral value of a metric.",
          "type" : "number"
        },
        "Numbers" : {
          "description" : "The numeral values of a metric.",
          "type" : "array",
          "uniqueItems" : true,
          "insertionOrder" : false,
          "items" : {
            "type" : "number"
          }
        },
        "Strings" : {
          "description" : "The string values of a metric.",
          "type" : "array",
          "uniqueItems" : true,
          "insertionOrder" : false,
          "items" : {
            "type" : "string"
          }
        }
      },
      "additionalProperties" : false
    },
    "StatisticalThreshold" : {
      "description" : "A statistical ranking (percentile) which indicates a threshold value by which a behavior is determined to be in compliance or in violation of the behavior.",
      "type" : "object",
      "properties" : {
        "Statistic" : {
          "description" : "The percentile which resolves to a threshold value by which compliance with a behavior is determined",
          "type" : "string",
          "enum" : [ "Average", "p0", "p0.1", "p0.01", "p1", "p10", "p50", "p90", "p99", "p99.9", "p99.99", "p100" ]
        }
      },
      "additionalProperties" : false
    },
    "MachineLearningDetectionConfig" : {
      "description" : "The configuration of an ML Detect Security Profile.",
      "type" : "object",
      "properties" : {
        "ConfidenceLevel" : {
          "description" : "The sensitivity of anomalous behavior evaluation. Can be Low, Medium, or High.",
          "type" : "string",
          "enum" : [ "LOW", "MEDIUM", "HIGH" ]
        }
      },
      "additionalProperties" : false
    },
    "AlertTarget" : {
      "description" : "A structure containing the alert target ARN and the role ARN.",
      "type" : "object",
      "properties" : {
        "AlertTargetArn" : {
          "description" : "The ARN of the notification target to which alerts are sent.",
          "type" : "string",
          "maxLength" : 2048
        },
        "RoleArn" : {
          "description" : "The ARN of the role that grants permission to send alerts to the notification target.",
          "type" : "string",
          "minLength" : 20,
          "maxLength" : 2048
        }
      },
      "required" : [ "AlertTargetArn", "RoleArn" ],
      "additionalProperties" : false
    },
    "MetricToRetain" : {
      "description" : "The metric you want to retain. Dimensions are optional.",
      "type" : "object",
      "properties" : {
        "Metric" : {
          "description" : "What is measured by the behavior.",
          "type" : "string",
          "pattern" : "[a-zA-Z0-9:_-]+",
          "minLength" : 1,
          "maxLength" : 128
        },
        "MetricDimension" : {
          "$ref" : "#/definitions/MetricDimension"
        },
        "ExportMetric" : {
          "$ref" : "#/definitions/ExportMetric"
        }
      },
      "required" : [ "Metric" ],
      "additionalProperties" : false
    },
    "Tag" : {
      "description" : "A key-value pair to associate with a resource.",
      "type" : "object",
      "properties" : {
        "Key" : {
          "type" : "string",
          "description" : "The tag's key.",
          "minLength" : 1,
          "maxLength" : 128
        },
        "Value" : {
          "type" : "string",
          "description" : "The tag's value.",
          "minLength" : 1,
          "maxLength" : 256
        }
      },
      "required" : [ "Value", "Key" ],
      "additionalProperties" : false
    }
  },
  "properties" : {
    "SecurityProfileName" : {
      "description" : "A unique identifier for the security profile.",
      "type" : "string",
      "pattern" : "[a-zA-Z0-9:_-]+",
      "minLength" : 1,
      "maxLength" : 128
    },
    "SecurityProfileDescription" : {
      "description" : "A description of the security profile.",
      "type" : "string",
      "maxLength" : 1000
    },
    "Behaviors" : {
      "description" : "Specifies the behaviors that, when violated by a device (thing), cause an alert.",
      "type" : "array",
      "maxLength" : 100,
      "uniqueItems" : true,
      "insertionOrder" : false,
      "items" : {
        "$ref" : "#/definitions/Behavior"
      }
    },
    "AlertTargets" : {
      "description" : "Specifies the destinations to which alerts are sent.",
      "type" : "object",
      "patternProperties" : {
        "[a-zA-Z0-9:_-]+" : {
          "$ref" : "#/definitions/AlertTarget"
        }
      },
      "additionalProperties" : false
    },
    "AdditionalMetricsToRetainV2" : {
      "description" : "A list of metrics whose data is retained (stored). By default, data is retained for any metric used in the profile's behaviors, but it is also retained for any metric specified here.",
      "type" : "array",
      "uniqueItems" : true,
      "insertionOrder" : false,
      "items" : {
        "$ref" : "#/definitions/MetricToRetain"
      }
    },
    "MetricsExportConfig" : {
      "description" : "A structure containing the mqtt topic for metrics export.",
      "type" : "object",
      "properties" : {
        "MqttTopic" : {
          "description" : "The topic for metrics export.",
          "type" : "string",
          "minLength" : 1,
          "maxLength" : 512
        },
        "RoleArn" : {
          "description" : "The ARN of the role that grants permission to publish to mqtt topic.",
          "type" : "string",
          "minLength" : 20,
          "maxLength" : 2048
        }
      },
      "required" : [ "MqttTopic", "RoleArn" ],
      "additionalProperties" : false
    },
    "Tags" : {
      "description" : "Metadata that can be used to manage the security profile.",
      "type" : "array",
      "maxItems" : 50,
      "uniqueItems" : true,
      "insertionOrder" : false,
      "items" : {
        "$ref" : "#/definitions/Tag"
      }
    },
    "TargetArns" : {
      "description" : "A set of target ARNs that the security profile is attached to.",
      "type" : "array",
      "uniqueItems" : true,
      "insertionOrder" : false,
      "items" : {
        "description" : "The ARN of the target to which the security profile is attached.",
        "type" : "string",
        "maxLength" : 2048
      }
    },
    "SecurityProfileArn" : {
      "description" : "The ARN (Amazon resource name) of the created security profile.",
      "type" : "string"
    }
  },
  "additionalProperties" : false,
  "primaryIdentifier" : [ "/properties/SecurityProfileName" ],
  "required" : [ ],
  "tagging" : {
    "taggable" : true,
    "tagOnCreate" : true,
    "tagUpdatable" : true,
    "cloudFormationSystemTags" : true,
    "tagProperty" : "/properties/Tags",
    "permissions" : [ "iot:TagResource", "iot:UntagResource", "iot:ListTagsForResource" ]
  },
  "createOnlyProperties" : [ "/properties/SecurityProfileName" ],
  "readOnlyProperties" : [ "/properties/SecurityProfileArn" ],
  "handlers" : {
    "create" : {
      "permissions" : [ "iot:CreateSecurityProfile", "iot:AttachSecurityProfile", "iot:DescribeSecurityProfile", "iot:TagResource", "iam:PassRole" ]
    },
    "read" : {
      "permissions" : [ "iot:DescribeSecurityProfile", "iot:ListTagsForResource", "iot:ListTargetsForSecurityProfile" ]
    },
    "update" : {
      "permissions" : [ "iot:UpdateSecurityProfile", "iot:ListTargetsForSecurityProfile", "iot:AttachSecurityProfile", "iot:DetachSecurityProfile", "iot:ListTagsForResource", "iot:UntagResource", "iot:TagResource", "iam:PassRole" ]
    },
    "delete" : {
      "permissions" : [ "iot:DescribeSecurityProfile", "iot:DeleteSecurityProfile" ]
    },
    "list" : {
      "permissions" : [ "iot:ListSecurityProfiles" ]
    }
  }
}