Exemplo n.º 1
0
 /**
  * @param $logGroupName
  * @param string $logStreamNameFilter
  * @return \AwsInspector\Model\Collection
  */
 public function findLogStreams($logGroupName, $logStreamNameFilter = null)
 {
     if (empty($logGroupName)) {
         throw new \InvalidArgumentException('LogGroupName cannot be empty');
     }
     $result = $this->cloudWatchLogsClient->describeLogStreams(['logGroupName' => $logGroupName, 'orderBy' => 'LastEventTime', 'descending' => true]);
     $rows = $result->search('logStreams[]');
     $collection = new \AwsInspector\Model\Collection();
     foreach ($rows as $row) {
         if (!$logStreamNameFilter || Finder::matchWildcard($logStreamNameFilter, $row['logStreamName'])) {
             $collection->attach(new LogStream($row));
         }
     }
     return $collection;
 }
Exemplo n.º 2
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;
 }