| Conditions | 6 |
| Paths | 5 |
| Total Lines | 28 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | public function collect(): array |
||
| 23 | { |
||
| 24 | if (!array_key_exists(ApacheServerNameCollector::COLLECTION_IDENTIFIER, $this->inventory) |
||
| 25 | || !is_array($this->inventory[ApacheServerNameCollector::COLLECTION_IDENTIFIER]) |
||
| 26 | ) return []; |
||
| 27 | |||
| 28 | $configs = $this->inventory[ApacheServerNameCollector::COLLECTION_IDENTIFIER]; |
||
| 29 | |||
| 30 | $uptimeStatus = []; |
||
| 31 | |||
| 32 | $client = new Client(); |
||
| 33 | |||
| 34 | foreach ($configs as $config) { |
||
| 35 | $domain = $config[ApacheServerNameCollector::FIELD_SERVER_NAME]; |
||
| 36 | try { |
||
| 37 | $result = $client->get('https://' . $domain); |
||
| 38 | } catch (ServerException $e) { |
||
| 39 | $uptimeStatus[$domain] = $e->getResponse()->getStatusCode(); |
||
| 40 | continue; |
||
| 41 | } catch (\Exception) { |
||
| 42 | $uptimeStatus[$domain] = 599; |
||
| 43 | continue; |
||
| 44 | } |
||
| 45 | |||
| 46 | $uptimeStatus[$domain] = $result->getStatusCode(); |
||
| 47 | } |
||
| 48 | |||
| 49 | return $uptimeStatus; |
||
| 50 | } |
||
| 52 |