|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace RenokiCo\AwsWebhooks\Concerns; |
| 4 | + |
| 5 | +use Rennokki\LaravelSnsEvents\Concerns\GeneratesSnsMessages; |
| 6 | + |
| 7 | +trait GeneratesSnsWebhookMessages |
| 8 | +{ |
| 9 | + use GeneratesSnsMessages; |
| 10 | + |
| 11 | + /** |
| 12 | + * Get the SES message for mails. |
| 13 | + * |
| 14 | + * @param string $type |
| 15 | + * @return array |
| 16 | + */ |
| 17 | + public function getSesMessage(string $type): array |
| 18 | + { |
| 19 | + return $this->getNotificationPayload([ |
| 20 | + 'eventType' => $type, |
| 21 | + ]); |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * Get an example cloudwatch notification payload. |
| 26 | + * |
| 27 | + * @param string $currentState |
| 28 | + * @param string $previousState |
| 29 | + * @return array |
| 30 | + */ |
| 31 | + public function getCloudwatchMessage(string $currentState = 'ALARM', string $previousState = 'OK'): array |
| 32 | + { |
| 33 | + return $this->getNotificationPayload([ |
| 34 | + 'AlarmName' => 'Some Alarm', |
| 35 | + 'AlarmDescription' => 'This is the alarm description. Pass it some nice info.', |
| 36 | + 'AWSAccountId' => '305476205504', |
| 37 | + 'NewStateValue' => $currentState, |
| 38 | + 'NewStateReason' => 'Threshold Crossed: 1 out of the last 1 datapoints [1.83333333333091 (24/06/20 20:25:00)] was greater than the threshold (1.6) (minimum 1 datapoint for OK -> ALARM transition).', |
| 39 | + 'StateChangeTime' => '2020-06-24T20:27:43.474+0000', |
| 40 | + 'Region' => 'US East (N. Virginia)', |
| 41 | + 'AlarmArn' => 'arn:aws:cloudwatch:us-east-1:305476205504:alarm:Some Alarm', |
| 42 | + 'OldStateValue' => $previousState, |
| 43 | + 'Trigger' => [ |
| 44 | + 'MetricName' => 'CPUUtilization', |
| 45 | + 'Namespace' => 'AWS/RDS', |
| 46 | + 'StatisticType' => 'Statistic', |
| 47 | + 'Statistic' => 'AVERAGE', |
| 48 | + 'Unit' => null, |
| 49 | + 'Dimensions' => [ |
| 50 | + [ |
| 51 | + 'value' => 'some-db-identifier', |
| 52 | + 'name' => 'DBInstanceIdentifier', |
| 53 | + ], |
| 54 | + ], |
| 55 | + 'Period' => 60, |
| 56 | + 'EvaluationPeriods' => 1, |
| 57 | + 'ComparisonOperator' => 'GreaterThanThreshold', |
| 58 | + 'Threshold' => 1.6, |
| 59 | + 'EvaluateLowSampleCountPercentile' => '', |
| 60 | + ], |
| 61 | + ]); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Get an example EC2 notification payload. |
| 66 | + * |
| 67 | + * @return array |
| 68 | + */ |
| 69 | + public function getEc2Message(): array |
| 70 | + { |
| 71 | + return $this->getNotificationPayload([ |
| 72 | + 'version' => 0, |
| 73 | + 'id' => '72d6566c-e6bd-117d-5bbc-2779c679abd5', |
| 74 | + 'detail-type' => 'EC2 Spot Instance Interruption Warning', |
| 75 | + 'source' => 'aws.ec2', |
| 76 | + 'account' => '12345678910', |
| 77 | + 'time' => '2020-03-06T08:25:40Z', |
| 78 | + 'region' => 'eu-west-1', |
| 79 | + 'resources' => [ |
| 80 | + 'arn:aws:ec2:eu-west-1a:instance/i-0cefe48f36d7c281a', |
| 81 | + ], |
| 82 | + 'detail' => [ |
| 83 | + 'instance-id' => 'i-0cefe48f36d7c281a', |
| 84 | + 'instance-action' => 'terminate', |
| 85 | + ], |
| 86 | + ]); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Get an example Gamelift notification payload. |
| 91 | + * |
| 92 | + * @return array |
| 93 | + */ |
| 94 | + public function getGameliftMessage(): array |
| 95 | + { |
| 96 | + return $this->getNotificationPayload([ |
| 97 | + 'version' => 0, |
| 98 | + 'id' => '72d6566c-e6bd-117d-5bbc-2779c679abd5', |
| 99 | + 'detail-type' => 'GameLift Matchmaking Event', |
| 100 | + 'source' => 'aws.gamelift', |
| 101 | + 'account' => '12345678910', |
| 102 | + 'time' => '2020-03-06T08:25:40Z', |
| 103 | + 'region' => 'eu-west-1', |
| 104 | + 'resources' => [ |
| 105 | + 'arn:aws:gamelift:us-west-2:123456789012:matchmakingconfiguration/SampleConfiguration', |
| 106 | + ], |
| 107 | + 'detail' => [ |
| 108 | + 'tickets' => [ |
| 109 | + [ |
| 110 | + 'ticketId' => 'ticket-1', |
| 111 | + 'startTime' => '2017-08-08T21:15:35.676Z', |
| 112 | + 'players' => [ |
| 113 | + ['playerId' => 'player-1'], |
| 114 | + ], |
| 115 | + ], |
| 116 | + ], |
| 117 | + 'estimatedWaitMillis' => 'NOT_AVAILABLE', |
| 118 | + 'type' => 'MatchmakingSearching', |
| 119 | + 'gameSessionInfo' => [ |
| 120 | + 'players' => [ |
| 121 | + ['playerId' => 'player-1'], |
| 122 | + ], |
| 123 | + ], |
| 124 | + ], |
| 125 | + ]); |
| 126 | + } |
| 127 | +} |
0 commit comments