|
| 1 | +import { GraphWidget, IWidget } from "monocdk/aws-cloudwatch"; |
| 2 | +import { |
| 3 | + BaseMonitoringProps, |
| 4 | + CountAxisFromZero, |
| 5 | + DefaultGraphWidgetHeight, |
| 6 | + DefaultSummaryWidgetHeight, |
| 7 | + MetricWithAlarmSupport, |
| 8 | + Monitoring, |
| 9 | + MonitoringScope, |
| 10 | + RateAxisFromZero, |
| 11 | + ThirdWidth, |
| 12 | +} from "../../common"; |
| 13 | +import { |
| 14 | + MonitoringHeaderWidget, |
| 15 | + MonitoringNamingStrategy, |
| 16 | +} from "../../dashboard"; |
| 17 | +import { |
| 18 | + WafV2MetricFactory, |
| 19 | + WafV2MetricFactoryProps, |
| 20 | +} from "./WafV2MetricFactory"; |
| 21 | + |
| 22 | +export interface WafV2MonitoringOptions extends BaseMonitoringProps {} |
| 23 | + |
| 24 | +export interface WafV2MonitoringProps |
| 25 | + extends WafV2MetricFactoryProps, |
| 26 | + WafV2MonitoringOptions {} |
| 27 | + |
| 28 | +/** |
| 29 | + * Monitoring for AWS Web Application Firewall. |
| 30 | + * |
| 31 | + * @see https://docs.aws.amazon.com/waf/latest/developerguide/monitoring-cloudwatch.html |
| 32 | + */ |
| 33 | +export class WafV2Monitoring extends Monitoring { |
| 34 | + protected readonly humanReadableName: string; |
| 35 | + |
| 36 | + protected readonly allowedRequestsMetric: MetricWithAlarmSupport; |
| 37 | + protected readonly blockedRequestsMetric: MetricWithAlarmSupport; |
| 38 | + protected readonly blockedRequestsRateMetric: MetricWithAlarmSupport; |
| 39 | + |
| 40 | + constructor(scope: MonitoringScope, props: WafV2MonitoringProps) { |
| 41 | + super(scope, props); |
| 42 | + |
| 43 | + const namingStrategy = new MonitoringNamingStrategy({ |
| 44 | + ...props, |
| 45 | + namedConstruct: props.acl, |
| 46 | + }); |
| 47 | + this.humanReadableName = namingStrategy.resolveHumanReadableName(); |
| 48 | + |
| 49 | + const metricFactory = new WafV2MetricFactory( |
| 50 | + scope.createMetricFactory(), |
| 51 | + props |
| 52 | + ); |
| 53 | + |
| 54 | + this.allowedRequestsMetric = metricFactory.metricAllowedRequests(); |
| 55 | + this.blockedRequestsMetric = metricFactory.metricBlockedRequests(); |
| 56 | + this.blockedRequestsRateMetric = metricFactory.metricBlockedRequestsRate(); |
| 57 | + } |
| 58 | + |
| 59 | + summaryWidgets(): IWidget[] { |
| 60 | + return [ |
| 61 | + this.createTitleWidget(), |
| 62 | + this.createAllowedRequestsWidget(ThirdWidth, DefaultSummaryWidgetHeight), |
| 63 | + this.createBlockedRequestsWidget(ThirdWidth, DefaultSummaryWidgetHeight), |
| 64 | + this.createBlockedRequestsRateWidget( |
| 65 | + ThirdWidth, |
| 66 | + DefaultSummaryWidgetHeight |
| 67 | + ), |
| 68 | + ]; |
| 69 | + } |
| 70 | + |
| 71 | + widgets(): IWidget[] { |
| 72 | + return [ |
| 73 | + this.createTitleWidget(), |
| 74 | + this.createAllowedRequestsWidget(ThirdWidth, DefaultGraphWidgetHeight), |
| 75 | + this.createBlockedRequestsWidget(ThirdWidth, DefaultSummaryWidgetHeight), |
| 76 | + this.createBlockedRequestsRateWidget( |
| 77 | + ThirdWidth, |
| 78 | + DefaultSummaryWidgetHeight |
| 79 | + ), |
| 80 | + ]; |
| 81 | + } |
| 82 | + |
| 83 | + protected createTitleWidget() { |
| 84 | + return new MonitoringHeaderWidget({ |
| 85 | + family: "Web Application Firewall", |
| 86 | + title: this.humanReadableName, |
| 87 | + }); |
| 88 | + } |
| 89 | + |
| 90 | + protected createAllowedRequestsWidget(width: number, height: number) { |
| 91 | + return new GraphWidget({ |
| 92 | + width, |
| 93 | + height, |
| 94 | + title: "Allowed Requests", |
| 95 | + left: [this.allowedRequestsMetric], |
| 96 | + leftYAxis: CountAxisFromZero, |
| 97 | + }); |
| 98 | + } |
| 99 | + |
| 100 | + protected createBlockedRequestsWidget(width: number, height: number) { |
| 101 | + return new GraphWidget({ |
| 102 | + width, |
| 103 | + height, |
| 104 | + title: "Blocked Requests", |
| 105 | + left: [this.blockedRequestsMetric], |
| 106 | + leftYAxis: CountAxisFromZero, |
| 107 | + }); |
| 108 | + } |
| 109 | + |
| 110 | + protected createBlockedRequestsRateWidget(width: number, height: number) { |
| 111 | + return new GraphWidget({ |
| 112 | + width, |
| 113 | + height, |
| 114 | + title: "Blocked Requests (rate)", |
| 115 | + left: [this.blockedRequestsRateMetric], |
| 116 | + leftYAxis: RateAxisFromZero, |
| 117 | + }); |
| 118 | + } |
| 119 | +} |
0 commit comments