Skip to content

Commit

Permalink
Merge pull request #249 from TripleSD/dev
Browse files Browse the repository at this point in the history
New version 0.1.10 (build 032)
  • Loading branch information
AntonMZ authored Jun 25, 2020
2 parents 7637e79 + 7bb60f5 commit 3b37e69
Show file tree
Hide file tree
Showing 99 changed files with 20,308 additions and 13,695 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[v.0.1.10 (Build.032)](https://github.com/TripleSD/moring/releases/tag/0.1.10)
- **(New)** - Enabled site's check from moring file.
- **(New)** - Added Backup FTP section.
- **(New)** - Added Backup Yandex Disk section (connectors/tasks/buckets)
- **(New)** - Added alerts on a header.
- **(Fix)** - Bug fixes and other improvements.

[v.0.1.9 (Build.029)](https://github.com/TripleSD/moring/releases/tag/0.1.9)
- **(Upd)** - Refactoring sites repository.
- **(Upd)** - Refactoring old migrations.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<img src="docs/img/moring_readme_2.png" alt="drawing" width="300"/>
</p>

PHP | Laravel 6 | AdminLTE

MoRiNg - opensource система мониторинга. На данный момент реализованы следуюшие функции:
- Мониторинг сайтов
- проверка кода ответа сайта
Expand Down
72 changes: 72 additions & 0 deletions app/Console/Commands/BackupFtpScraper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace App\Console\Commands;

use App\Models\BackupFtpList;
use App\Models\BackupFtpLogs;
use Carbon\Carbon;
use Illuminate\Console\Command;

class BackupFtpScraper extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'scraper:ftp {--interval=}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

public function handle()
{
if ($this->option('interval') === '3') {
$interval = 3;
} elseif ($this->option('interval') === '6') {
$interval = 6;
} elseif ($this->option('interval') === '12') {
$interval = 12;
} elseif ($this->option('interval') === '24') {
$interval = 24;
} elseif ($this->option('interval') === '1') {
$interval = 1;
} else {
$interval = 1;
}

$tasks = BackupFtpList::where('enabled', 1)->where('interval', $interval)->get();

foreach ($tasks as $task) {
BackupFtpList::where('id', $task->id)->update(['updated_at' => Carbon::now()->format('Y-m-d H:i:s')]);

$stream = ftp_connect($task->hostname);
ftp_login($stream, $task->login, $task->password);
ftp_pasv($stream, true);
$files = ftp_mlsd($stream, "/$task->folder");
ftp_close($stream);

$status = 0;
$resolved = 0;

foreach ($files as $file) {
if ($file['name'] === $task->FullFilename) {
$status = 1;
$resolved = 1;
}
}

$arr = [
'task_id' => $task->id,
'status' => $status,
'resolved' => $resolved,
];

BackupFtpLogs::create($arr);
}
}
}
65 changes: 65 additions & 0 deletions app/Console/Commands/BackupYandexConnectorsKeeper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Console\Commands;

use App\Models\BackupYandexConnectors;
use App\Models\BackupYandexConnectorsLogs;
use Illuminate\Console\Command;

class BackupYandexConnectorsKeeper extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'backup:yandex-connectors-keeper';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Updating information about Yandex Disk connectors';

public function handle()
{
$connectors = BackupYandexConnectors::get();

foreach ($connectors as $connector) {
$ch = curl_init('https://cloud-api.yandex.net/v1/disk/');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: OAuth ' . $connector->token]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
$res = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$res = json_decode($res, true);

if ($httpcode === 200) {
BackupYandexConnectors::where('id', $connector->id)->update(
[
'total_space' => $res['total_space'],
'trash_size' => $res['trash_size'],
'used_space' => $res['used_space'],
'http_code' => $httpcode,
'status' => 1,
]
);

BackupYandexConnectorsLogs::create(['connector_id' => $connector->id, 'status' => 1, 'resolved' => 1]);
} else {
BackupYandexConnectors::where('id', $connector->id)->update(
[
'http_code' => $httpcode,
'status' => 0,
]
);

BackupYandexConnectorsLogs::create(['connector_id' => $connector->id, 'status' => 0, 'resolved' => 0]);
}
}
}
}
38 changes: 27 additions & 11 deletions app/Console/Commands/SitesChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Exception;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use Str;

class SitesChecker extends Command
Expand Down Expand Up @@ -58,10 +59,10 @@ public function handle(int $site_id = null, $mode = null)
}

if ($site_id === null) {
$sites = Sites::where('enabled', 1)->get();
$sites = Sites::where('enabled', 1)->with('checksList')->get();
$tgMessage = 0;
} else {
$sites[] = Sites::find($site_id);
$sites[] = Sites::where('id', $site_id)->with('checksList')->firstOrFail();
$tgMessage = 1;
}

Expand Down Expand Up @@ -119,19 +120,34 @@ private function ckeckSite($site, $cli = false, $debug = false): void
Sites::where('id', $site->id)->update(['ip_address' => gethostbyname($site->url)]);
try {
if ($site->checksList->use_file === 1) {
$httpClient = new Client();
$url = ($site->https === 1 && $site->checksList->check_https === 1) ? 'https://' . $site->file_url : 'http://' . $site->file_url;
$request = $httpClient->request('GET', $url, ['allow_redirects' => false]);
$response = $request->getBody();
$responseArray = json_decode($response, true);
$phpVersion = $responseArray['php-version'];
$statusCode = $request->getStatusCode();
$webServerType = $responseArray['web-server'];
$phpBranch = $responseArray['php-branch'];
if ($site->file_url === null) {
$phpVersion = 0;
$statusCode = 999;
$webServerType = 0;
$phpBranch = 0;
} else {
$httpClient = new Client();
$url = ($site->https === 1) ? 'https://' . $site->url . '/' . $site->file_url : 'http://' . $site->url . '/' . $site->file_url;
$request = $httpClient->request('GET', $url, ['allow_redirects' => false]);
if ($request->getStatusCode() === 200) {
$response = $request->getBody();
$responseArray = json_decode($response, true);
$phpVersion = $responseArray['php-version'];
$statusCode = $request->getStatusCode();
$webServerType = $responseArray['web-server'];
$phpBranch = $responseArray['php-branch'];
} else {
$phpVersion = 0;
$statusCode = $request->getStatusCode();
$webServerType = 0;
$phpBranch = 0;
}
}
} else {
$url = ($site->https === 1 && $site->checksList->check_https === 1) ? 'https://' . $site->url : 'http://' . $site->url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, Config::get('moring.userAgent'));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Expand Down
11 changes: 11 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ protected function schedule(Schedule $schedule)
$schedule->command('ServersPings')->everyFiveMinutes();
$schedule->command('SnmpDevicesChecker')->everyMinute();
$schedule->command('SystemChecker')->daily();

$schedule->command('scraper:ftp --interval=1')->hourly()->between('01:00', '23:55');
$schedule->command('scraper:ftp --interval=3')->hourlyAt([3, 6, 9, 12, 15, 18, 21]);
$schedule->command('scraper:ftp --interval=3')->dailyAt('23:55');
$schedule->command('scraper:ftp --interval=6')->hourlyAt([6, 12, 18]);
$schedule->command('scraper:ftp --interval=6')->dailyAt('23:55');
$schedule->command('scraper:ftp --interval=12')->hourlyAt(12);
$schedule->command('scraper:ftp --interval=12')->dailyAt('23:55');
$schedule->command('scraper:ftp --interval=24')->dailyAt('23:55');

$schedule->command('backup:yandex-connectors-keeper')->everyMinute();
}

/**
Expand Down
67 changes: 67 additions & 0 deletions app/Helpers/SystemLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace App\Helpers;

use App\Models\SystemLogs;

/**
* Class SystemLog.
*/
class SystemLog
{
/**
* @param $functionName
* @param $request
* @return mixed
*/
public static function createUserEvent($functionName, $request)
{
if (isset(\Auth::user()->id)) {
$userId = \Auth::user()->id;
} else {
$userId = 0;
}

$logArray = [
'service' => \Config::get('moring.service_system'),
'debug_info' => $request->method(),
'status' => $request->server('REDIRECT_STATUS'),
'user_id' => $userId,
'route' => \Route::getCurrentRoute()->getActionName() . PHP_EOL,
'callable_function' => $functionName,
];

return SystemLogs::create($logArray);
}

/**
* @param $functionName
* @param null $service
* @param null $status
* @param null $debugInfo
* @return mixed
*/
public static function createServiceEvent($functionName, $service = null, $status = null, $debugInfo = null)
{
if (isset(\Auth::user()->id)) {
$userId = \Auth::user()->id;
} else {
$userId = 0;
}

if ($service === 'mysql') {
$service = \Config::get('moring.service_mysql');
}

$logArray = [
'service' => $service,
'debug_info' => $debugInfo,
'status' => $status,
'user_id' => $userId,
'route' => \Route::getCurrentRoute()->getActionName() . PHP_EOL,
'callable_function' => $functionName,
];

return SystemLogs::create($logArray);
}
}
Loading

0 comments on commit 3b37e69

Please sign in to comment.