diff --git a/README.md b/README.md index 8b794366..9bdbd0ca 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Speedtest Tracker -[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE) +[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE) This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses [Ookla's Speedtest cli](https://www.speedtest.net/apps/cli) to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results. @@ -14,6 +14,7 @@ Disclaimer: You will need to accept Ookla's [EULA](https://www.speedtest.net/abo - Graph of previous speedtests going back x days - Backup/restore data in JSON/CSV format - Slack/Discord/Telegram notifications +- [healthchecks.io](https://healthchecks.io) integration - Organizr integration ## Usage diff --git a/conf/site/README.md b/conf/site/README.md index 41274c45..42a242c3 100644 --- a/conf/site/README.md +++ b/conf/site/README.md @@ -1,6 +1,6 @@ # Speedtest Tracker -[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE) +[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE) This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses the [Ookla's speedtest cli](https://www.speedtest.net/apps/cli) package to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results. @@ -14,6 +14,7 @@ Disclaimer: You will need to accept Ookla's EULA and privacy agreements in order - Graph of previous speedtests going back x days - Backup/restore data in JSON/CSV format - Slack/Discord/Telegram notifications +- [healthchecks.io](https://healthchecks.io) integration - Organizr integration ## Installation & Setup diff --git a/conf/site/app/Helpers/SpeedtestHelper.php b/conf/site/app/Helpers/SpeedtestHelper.php index 4abf88a4..26516fa6 100644 --- a/conf/site/app/Helpers/SpeedtestHelper.php +++ b/conf/site/app/Helpers/SpeedtestHelper.php @@ -5,6 +5,7 @@ namespace App\Helpers; use App\Speedtest; use Carbon\Carbon; use Exception; +use Henrywhitaker3\Healthchecks\Healthchecks; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; @@ -51,7 +52,7 @@ class SpeedtestHelper { $test = false; } - if(!$test) { + if($test == false) { Speedtest::create([ 'ping' => 0, 'upload' => 0, @@ -59,9 +60,7 @@ class SpeedtestHelper { 'failed' => true, 'scheduled' => $scheduled, ]); - } - if($test == false) { return false; } diff --git a/conf/site/app/Jobs/SpeedtestJob.php b/conf/site/app/Jobs/SpeedtestJob.php index 8ed0e1bf..0f718b8d 100644 --- a/conf/site/app/Jobs/SpeedtestJob.php +++ b/conf/site/app/Jobs/SpeedtestJob.php @@ -4,7 +4,10 @@ namespace App\Jobs; use App\Events\SpeedtestCompleteEvent; use App\Events\SpeedtestFailedEvent; +use App\Helpers\SettingsHelper; use App\Helpers\SpeedtestHelper; +use Exception; +use Henrywhitaker3\Healthchecks\Healthchecks; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -35,11 +38,36 @@ class SpeedtestJob implements ShouldQueue */ public function handle() { + $healthchecksEnabled = (bool)SettingsHelper::get('healthchecks_enabled')->value; + $healthchecksUuid = SettingsHelper::get('healthchecks_uuid')->value; + + if($healthchecksEnabled === true) { + try { + $hc = new Healthchecks($healthchecksUuid); + $hc->start(); + } catch(Exception $e) { + Log::error($e->getMessage()); + } + } $output = SpeedtestHelper::output(); $speedtest = SpeedtestHelper::runSpeedtest($output, $this->scheduled); if($speedtest == false) { + if(isset($hc)) { + try { + $hc->fail(); + } catch(Exception $e) { + // + } + } event(new SpeedtestFailedEvent()); } else { + if(isset($hc)) { + try { + $hc->success(); + } catch(Exception $e) { + // + } + } event(new SpeedtestCompleteEvent($speedtest)); } return $speedtest; diff --git a/conf/site/changelog.json b/conf/site/changelog.json index f2a9dc9b..5dead0ac 100644 --- a/conf/site/changelog.json +++ b/conf/site/changelog.json @@ -1,4 +1,10 @@ { + "1.8.0": [ + { + "description": "Added healthchecks.io integration.", + "link": "" + } + ], "1.7.19": [ { "description": "Updated dependencies.", diff --git a/conf/site/composer.json b/conf/site/composer.json index c3720bd3..0a766b06 100644 --- a/conf/site/composer.json +++ b/conf/site/composer.json @@ -14,6 +14,7 @@ "fideloper/proxy": "^4.2", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^7.0", + "henrywhitaker3/healthchecks-io": "^1.0", "laravel-notification-channels/telegram": "^0.4.0", "laravel/framework": "^7.0", "laravel/slack-notification-channel": "^2.0", diff --git a/conf/site/composer.lock b/conf/site/composer.lock index c5f4f5be..11884a6d 100644 --- a/conf/site/composer.lock +++ b/conf/site/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "eee4cd81905b1464677cd0295e867901", + "content-hash": "837c814b9f3c208c35d3e28d611623fa", "packages": [ { "name": "asm89/stack-cors", @@ -102,12 +102,6 @@ "brick", "math" ], - "funding": [ - { - "url": "https://tidelift.com/funding/github/packagist/brick/math", - "type": "tidelift" - } - ], "time": "2020-04-15T15:59:35+00:00" }, { @@ -498,20 +492,6 @@ "uppercase", "words" ], - "funding": [ - { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" - }, - { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finflector", - "type": "tidelift" - } - ], "time": "2020-05-29T15:13:26+00:00" }, { @@ -574,20 +554,6 @@ "parser", "php" ], - "funding": [ - { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" - }, - { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Flexer", - "type": "tidelift" - } - ], "time": "2020-05-25T17:44:05+00:00" }, { @@ -824,12 +790,6 @@ "crossdomain", "laravel" ], - "funding": [ - { - "url": "https://github.com/barryvdh", - "type": "github" - } - ], "time": "2020-05-31T07:30:16+00:00" }, { @@ -1035,6 +995,57 @@ ], "time": "2019-07-01T23:21:34+00:00" }, + { + "name": "henrywhitaker3/healthchecks-io", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/henrywhitaker3/PHP-healthchecks.io.git", + "reference": "c9dc8bed2f537e6043ec84c0e95182c15f5b990b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/henrywhitaker3/PHP-healthchecks.io/zipball/c9dc8bed2f537e6043ec84c0e95182c15f5b990b", + "reference": "c9dc8bed2f537e6043ec84c0e95182c15f5b990b", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "rakit/validation": "^1.3", + "ramsey/uuid": "^4.1" + }, + "require-dev": { + "phpstan/phpstan": "^0.12.37", + "phpunit/phpunit": "^8.5", + "vlucas/phpdotenv": "^5.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Henrywhitaker3\\Healthchecks\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Henry Whitaker", + "email": "henrywhitaker3@outlook.com", + "homepage": "https://github.com/henrywhitaker3" + } + ], + "description": "A simple PHP healthchecks.io wrapper", + "homepage": "https://github.com/henrywhitaker3/PHP-healthchecks.io", + "keywords": [ + "api", + "healthchecks", + "healthchecks.io", + "wrapper" + ], + "time": "2020-08-12T11:56:35+00:00" + }, { "name": "laravel-notification-channels/telegram", "version": "0.4.1", @@ -2548,6 +2559,48 @@ ], "time": "2020-05-03T19:32:03+00:00" }, + { + "name": "rakit/validation", + "version": "v1.3.2", + "source": { + "type": "git", + "url": "https://github.com/rakit/validation.git", + "reference": "126306ccabeadec24b6fa310605c71be67dee188" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rakit/validation/zipball/126306ccabeadec24b6fa310605c71be67dee188", + "reference": "126306ccabeadec24b6fa310605c71be67dee188", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=7.0" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.2", + "phpunit/phpunit": "^6.5", + "squizlabs/php_codesniffer": "^3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Rakit\\Validation\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Muhammad Syifa", + "email": "emsifa@gmail.com" + } + ], + "description": "PHP Laravel like standalone validation library", + "time": "2020-08-09T01:18:04+00:00" + }, { "name": "ralouphie/getallheaders", "version": "3.0.3", @@ -4119,20 +4172,6 @@ "portable", "shim" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-03-09T19:04:49+00:00" }, { @@ -4491,20 +4530,6 @@ "polyfill", "shim" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-03-02T11:55:35+00:00" }, { @@ -5202,12 +5227,6 @@ "jwt", "laravel" ], - "funding": [ - { - "url": "https://www.patreon.com/seantymon", - "type": "patreon" - } - ], "time": "2020-03-04T11:21:28+00:00" }, { @@ -5763,20 +5782,6 @@ "constructor", "instantiate" ], - "funding": [ - { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" - }, - { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", - "type": "tidelift" - } - ], "time": "2020-05-29T17:27:14+00:00" }, { @@ -6367,20 +6372,6 @@ "php", "symfony" ], - "funding": [ - { - "url": "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L", - "type": "custom" - }, - { - "url": "https://github.com/nunomaduro", - "type": "github" - }, - { - "url": "https://www.patreon.com/nunomaduro", - "type": "patreon" - } - ], "time": "2020-04-04T19:56:08+00:00" }, { @@ -7257,12 +7248,6 @@ "highlight.php", "syntax" ], - "funding": [ - { - "url": "https://github.com/allejo", - "type": "github" - } - ], "time": "2020-03-02T05:59:21+00:00" }, { diff --git a/conf/site/config/speedtest.php b/conf/site/config/speedtest.php index 4d105f9c..87e86b62 100644 --- a/conf/site/config/speedtest.php +++ b/conf/site/config/speedtest.php @@ -7,7 +7,7 @@ return [ |-------------------------------------------------------------------------- */ - 'version' => '1.7.19', + 'version' => '1.8.0', /* |-------------------------------------------------------------------------- @@ -15,7 +15,7 @@ return [ |-------------------------------------------------------------------------- */ - 'install' => 'docker', + 'install' => 'manual', /* |-------------------------------------------------------------------------- @@ -23,7 +23,7 @@ return [ |-------------------------------------------------------------------------- */ - 'home' => 'HOME=/config', + 'home' => 'HOME=' . base_path() . DIRECTORY_SEPARATOR, /* |-------------------------------------------------------------------------- diff --git a/conf/site/database/migrations/2020_08_12_123941_add_healthchecks_settings.php b/conf/site/database/migrations/2020_08_12_123941_add_healthchecks_settings.php new file mode 100644 index 00000000..343d08d4 --- /dev/null +++ b/conf/site/database/migrations/2020_08_12_123941_add_healthchecks_settings.php @@ -0,0 +1,47 @@ + 'healthchecks_enabled', + 'value' => false, + 'description' => 'Enable the healthchecks.io integration for speedtests.' + ]); + } + + if(!SettingsHelper::get('healthchecks_uuid')) { + Setting::create([ + 'name' => 'healthchecks_uuid', + 'value' => '', + 'description' => '' + ]); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Setting::whereIn('name', [ + 'healthchecks_enabled', + 'healthchecks_uuid', + ])->delete(); + } +} diff --git a/conf/site/database/speed.db b/conf/site/database/speed.db deleted file mode 100644 index 14f8cce3..00000000 Binary files a/conf/site/database/speed.db and /dev/null differ diff --git a/conf/site/resources/js/components/Graphics/HistoryGraph.js b/conf/site/resources/js/components/Graphics/HistoryGraph.js index da83b0b2..c0f227aa 100644 --- a/conf/site/resources/js/components/Graphics/HistoryGraph.js +++ b/conf/site/resources/js/components/Graphics/HistoryGraph.js @@ -205,7 +205,6 @@ export default class HistoryGraph extends Component { failData.datasets[1].data.push(fail); failData.labels.push(new Date(e.date).toLocaleString([], {year: '2-digit', month:'2-digit', day:'2-digit'})); }) - console.log(failData); this.setState({ failData: failData, diff --git a/conf/site/resources/js/components/Settings/Settings.js b/conf/site/resources/js/components/Settings/Settings.js index afcd5c61..785f780d 100644 --- a/conf/site/resources/js/components/Settings/Settings.js +++ b/conf/site/resources/js/components/Settings/Settings.js @@ -158,6 +158,18 @@ export default class Settings extends Component { } ]} /> +