/** * @throws InvalidConfiguration */ public function runMonitor() { if (empty($this->url)) { throw InvalidConfiguration::noUrlConfigured(); } try { $guzzle = new Guzzle(['timeout' => $this->timeout, 'allow_redirects' => $this->allowRedirects]); $response = $guzzle->get($this->url); $this->responseCode = $response->getStatusCode(); $this->responseContent = (string) $response->getBody(); } catch (ClientException $e) { $response = $e->getResponse(); $this->responseCode = $response->getStatusCode(); } catch (ConnectException $e) { } if ($this->responseCode != '200' || !$this->checkResponseContains($this->responseContent, $this->checkPhrase)) { event(new HttpPingDown($this)); } else { event(new HttpPingUp($this)); } }
/** * @param array $monitorConfiguration * @param array $filter * @return mixed */ public static function createForMonitorConfig(array $monitorConfiguration, array $filter = []) { $monitors = collect($monitorConfiguration); if (count($filter) && !empty($filter[0])) { $monitors = $monitors->only($filter); } $configured_monitors = collect(); $monitors->map(function ($monitorConfigs, $monitorName) { if (file_exists(__DIR__ . '/' . ucfirst($monitorName) . 'Monitor.php')) { $className = '\\EricMakesStuff\\ServerMonitor\\Monitors\\' . ucfirst($monitorName) . 'Monitor'; return collect($monitorConfigs)->map(function ($monitorConfig) use($className) { return app($className, [$monitorConfig]); }); } throw InvalidConfiguration::cannotFindMonitor($monitorName); })->each(function ($monitor_group) use($configured_monitors) { $monitor_group->each(function ($monitor) use($configured_monitors) { $configured_monitors->push($monitor); }); }); return $configured_monitors; }
protected function parseUrl($url) { if (empty($url)) { throw InvalidConfiguration::noUrlConfigured(); } $urlParts = parse_url($url); if (!$urlParts) { throw InvalidConfiguration::urlCouldNotBeParsed(); } if (empty($urlParts['scheme']) || $urlParts['scheme'] != 'https') { throw InvalidConfiguration::urlNotSecure(); } return $urlParts; }