예제 #1
0
 private function initialize()
 {
     // fetch existing groups
     $existingGroups = $this->client->describeLogGroups(['logGroupNamePrefix' => $this->logGroupName])->get('logGroups');
     // extract existing groups names
     $existingGroupsNames = array_map(function ($group) {
         return $group['logGroupName'];
     }, $existingGroups);
     // create group and set retention policy if not created yet
     if (!in_array($this->logGroupName, $existingGroupsNames, true)) {
         $this->client->createLogGroup(['logGroupName' => $this->logGroupName]);
         $this->client->putRetentionPolicy(['logGroupName' => $this->logGroupName, 'retentionInDays' => $this->retentionDays]);
     }
     // fetch existing streams
     $existingStreams = $this->client->describeLogStreams(['logGroupName' => $this->logGroupName, 'logStreamNamePrefix' => $this->logStreamName])->get('logStreams');
     // extract existing streams names
     $existingStreamsNames = array_map(function ($stream) {
         // set sequence token
         if ($stream['logStreamName'] === $this->logStreamName && isset($stream['uploadSequenceToken'])) {
             $this->uploadSequenceToken = $stream['uploadSequenceToken'];
         }
         return $stream['logStreamName'];
     }, $existingStreams);
     // create stream if not created
     if (!in_array($this->logStreamName, $existingStreamsNames, true)) {
         $this->client->createLogStream(['logGroupName' => $this->logGroupName, 'logStreamName' => $this->logStreamName]);
     }
     $this->initialized = true;
 }
예제 #2
0
 /**
  * @param string $logGroupNameFilter
  * @return \AwsInspector\Model\Collection
  */
 public function findLogGroups($logGroupNameFilter = null)
 {
     $collection = new \AwsInspector\Model\Collection();
     $nextToken = null;
     do {
         $params = ['limit' => 50];
         if ($nextToken) {
             $params['nextToken'] = $nextToken;
         }
         $result = $this->cloudWatchLogsClient->describeLogGroups($params);
         foreach ($result->get('logGroups') as $row) {
             if (!$logGroupNameFilter || Finder::matchWildcard($logGroupNameFilter, $row['logGroupName'])) {
                 $collection->attach(new LogGroup($row));
             }
         }
         $nextToken = $result->get("nextToken");
     } while ($nextToken);
     return $collection;
 }