Skip to content

Commit 3b37e69

Browse files
authored
Merge pull request #249 from TripleSD/dev
New version 0.1.10 (build 032)
2 parents 7637e79 + 7bb60f5 commit 3b37e69

99 files changed

Lines changed: 20308 additions & 13695 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
[v.0.1.10 (Build.032)](https://github.com/TripleSD/moring/releases/tag/0.1.10)
2+
- **(New)** - Enabled site's check from moring file.
3+
- **(New)** - Added Backup FTP section.
4+
- **(New)** - Added Backup Yandex Disk section (connectors/tasks/buckets)
5+
- **(New)** - Added alerts on a header.
6+
- **(Fix)** - Bug fixes and other improvements.
7+
18
[v.0.1.9 (Build.029)](https://github.com/TripleSD/moring/releases/tag/0.1.9)
29
- **(Upd)** - Refactoring sites repository.
310
- **(Upd)** - Refactoring old migrations.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<img src="docs/img/moring_readme_2.png" alt="drawing" width="300"/>
1818
</p>
1919

20+
PHP | Laravel 6 | AdminLTE
21+
2022
MoRiNg - opensource система мониторинга. На данный момент реализованы следуюшие функции:
2123
- Мониторинг сайтов
2224
- проверка кода ответа сайта
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\BackupFtpList;
6+
use App\Models\BackupFtpLogs;
7+
use Carbon\Carbon;
8+
use Illuminate\Console\Command;
9+
10+
class BackupFtpScraper extends Command
11+
{
12+
/**
13+
* The name and signature of the console command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'scraper:ftp {--interval=}';
18+
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Command description';
25+
26+
public function handle()
27+
{
28+
if ($this->option('interval') === '3') {
29+
$interval = 3;
30+
} elseif ($this->option('interval') === '6') {
31+
$interval = 6;
32+
} elseif ($this->option('interval') === '12') {
33+
$interval = 12;
34+
} elseif ($this->option('interval') === '24') {
35+
$interval = 24;
36+
} elseif ($this->option('interval') === '1') {
37+
$interval = 1;
38+
} else {
39+
$interval = 1;
40+
}
41+
42+
$tasks = BackupFtpList::where('enabled', 1)->where('interval', $interval)->get();
43+
44+
foreach ($tasks as $task) {
45+
BackupFtpList::where('id', $task->id)->update(['updated_at' => Carbon::now()->format('Y-m-d H:i:s')]);
46+
47+
$stream = ftp_connect($task->hostname);
48+
ftp_login($stream, $task->login, $task->password);
49+
ftp_pasv($stream, true);
50+
$files = ftp_mlsd($stream, "/$task->folder");
51+
ftp_close($stream);
52+
53+
$status = 0;
54+
$resolved = 0;
55+
56+
foreach ($files as $file) {
57+
if ($file['name'] === $task->FullFilename) {
58+
$status = 1;
59+
$resolved = 1;
60+
}
61+
}
62+
63+
$arr = [
64+
'task_id' => $task->id,
65+
'status' => $status,
66+
'resolved' => $resolved,
67+
];
68+
69+
BackupFtpLogs::create($arr);
70+
}
71+
}
72+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\BackupYandexConnectors;
6+
use App\Models\BackupYandexConnectorsLogs;
7+
use Illuminate\Console\Command;
8+
9+
class BackupYandexConnectorsKeeper extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'backup:yandex-connectors-keeper';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Updating information about Yandex Disk connectors';
24+
25+
public function handle()
26+
{
27+
$connectors = BackupYandexConnectors::get();
28+
29+
foreach ($connectors as $connector) {
30+
$ch = curl_init('https://cloud-api.yandex.net/v1/disk/');
31+
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: OAuth ' . $connector->token]);
32+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
33+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
34+
curl_setopt($ch, CURLOPT_HEADER, false);
35+
$res = curl_exec($ch);
36+
$httpcode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
37+
curl_close($ch);
38+
39+
$res = json_decode($res, true);
40+
41+
if ($httpcode === 200) {
42+
BackupYandexConnectors::where('id', $connector->id)->update(
43+
[
44+
'total_space' => $res['total_space'],
45+
'trash_size' => $res['trash_size'],
46+
'used_space' => $res['used_space'],
47+
'http_code' => $httpcode,
48+
'status' => 1,
49+
]
50+
);
51+
52+
BackupYandexConnectorsLogs::create(['connector_id' => $connector->id, 'status' => 1, 'resolved' => 1]);
53+
} else {
54+
BackupYandexConnectors::where('id', $connector->id)->update(
55+
[
56+
'http_code' => $httpcode,
57+
'status' => 0,
58+
]
59+
);
60+
61+
BackupYandexConnectorsLogs::create(['connector_id' => $connector->id, 'status' => 0, 'resolved' => 0]);
62+
}
63+
}
64+
}
65+
}

app/Console/Commands/SitesChecker.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Exception;
1313
use GuzzleHttp\Client;
1414
use Illuminate\Console\Command;
15+
use Illuminate\Support\Facades\Config;
1516
use Str;
1617

1718
class SitesChecker extends Command
@@ -58,10 +59,10 @@ public function handle(int $site_id = null, $mode = null)
5859
}
5960

6061
if ($site_id === null) {
61-
$sites = Sites::where('enabled', 1)->get();
62+
$sites = Sites::where('enabled', 1)->with('checksList')->get();
6263
$tgMessage = 0;
6364
} else {
64-
$sites[] = Sites::find($site_id);
65+
$sites[] = Sites::where('id', $site_id)->with('checksList')->firstOrFail();
6566
$tgMessage = 1;
6667
}
6768

@@ -119,19 +120,34 @@ private function ckeckSite($site, $cli = false, $debug = false): void
119120
Sites::where('id', $site->id)->update(['ip_address' => gethostbyname($site->url)]);
120121
try {
121122
if ($site->checksList->use_file === 1) {
122-
$httpClient = new Client();
123-
$url = ($site->https === 1 && $site->checksList->check_https === 1) ? 'https://' . $site->file_url : 'http://' . $site->file_url;
124-
$request = $httpClient->request('GET', $url, ['allow_redirects' => false]);
125-
$response = $request->getBody();
126-
$responseArray = json_decode($response, true);
127-
$phpVersion = $responseArray['php-version'];
128-
$statusCode = $request->getStatusCode();
129-
$webServerType = $responseArray['web-server'];
130-
$phpBranch = $responseArray['php-branch'];
123+
if ($site->file_url === null) {
124+
$phpVersion = 0;
125+
$statusCode = 999;
126+
$webServerType = 0;
127+
$phpBranch = 0;
128+
} else {
129+
$httpClient = new Client();
130+
$url = ($site->https === 1) ? 'https://' . $site->url . '/' . $site->file_url : 'http://' . $site->url . '/' . $site->file_url;
131+
$request = $httpClient->request('GET', $url, ['allow_redirects' => false]);
132+
if ($request->getStatusCode() === 200) {
133+
$response = $request->getBody();
134+
$responseArray = json_decode($response, true);
135+
$phpVersion = $responseArray['php-version'];
136+
$statusCode = $request->getStatusCode();
137+
$webServerType = $responseArray['web-server'];
138+
$phpBranch = $responseArray['php-branch'];
139+
} else {
140+
$phpVersion = 0;
141+
$statusCode = $request->getStatusCode();
142+
$webServerType = 0;
143+
$phpBranch = 0;
144+
}
145+
}
131146
} else {
132147
$url = ($site->https === 1 && $site->checksList->check_https === 1) ? 'https://' . $site->url : 'http://' . $site->url;
133148
$ch = curl_init();
134149
curl_setopt($ch, CURLOPT_URL, $url);
150+
curl_setopt($ch, CURLOPT_USERAGENT, Config::get('moring.userAgent'));
135151
curl_setopt($ch, CURLOPT_HEADER, true);
136152
curl_setopt($ch, CURLOPT_NOBODY, true);
137153
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

app/Console/Kernel.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ protected function schedule(Schedule $schedule)
4949
$schedule->command('ServersPings')->everyFiveMinutes();
5050
$schedule->command('SnmpDevicesChecker')->everyMinute();
5151
$schedule->command('SystemChecker')->daily();
52+
53+
$schedule->command('scraper:ftp --interval=1')->hourly()->between('01:00', '23:55');
54+
$schedule->command('scraper:ftp --interval=3')->hourlyAt([3, 6, 9, 12, 15, 18, 21]);
55+
$schedule->command('scraper:ftp --interval=3')->dailyAt('23:55');
56+
$schedule->command('scraper:ftp --interval=6')->hourlyAt([6, 12, 18]);
57+
$schedule->command('scraper:ftp --interval=6')->dailyAt('23:55');
58+
$schedule->command('scraper:ftp --interval=12')->hourlyAt(12);
59+
$schedule->command('scraper:ftp --interval=12')->dailyAt('23:55');
60+
$schedule->command('scraper:ftp --interval=24')->dailyAt('23:55');
61+
62+
$schedule->command('backup:yandex-connectors-keeper')->everyMinute();
5263
}
5364

5465
/**

app/Helpers/SystemLog.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace App\Helpers;
4+
5+
use App\Models\SystemLogs;
6+
7+
/**
8+
* Class SystemLog.
9+
*/
10+
class SystemLog
11+
{
12+
/**
13+
* @param $functionName
14+
* @param $request
15+
* @return mixed
16+
*/
17+
public static function createUserEvent($functionName, $request)
18+
{
19+
if (isset(\Auth::user()->id)) {
20+
$userId = \Auth::user()->id;
21+
} else {
22+
$userId = 0;
23+
}
24+
25+
$logArray = [
26+
'service' => \Config::get('moring.service_system'),
27+
'debug_info' => $request->method(),
28+
'status' => $request->server('REDIRECT_STATUS'),
29+
'user_id' => $userId,
30+
'route' => \Route::getCurrentRoute()->getActionName() . PHP_EOL,
31+
'callable_function' => $functionName,
32+
];
33+
34+
return SystemLogs::create($logArray);
35+
}
36+
37+
/**
38+
* @param $functionName
39+
* @param null $service
40+
* @param null $status
41+
* @param null $debugInfo
42+
* @return mixed
43+
*/
44+
public static function createServiceEvent($functionName, $service = null, $status = null, $debugInfo = null)
45+
{
46+
if (isset(\Auth::user()->id)) {
47+
$userId = \Auth::user()->id;
48+
} else {
49+
$userId = 0;
50+
}
51+
52+
if ($service === 'mysql') {
53+
$service = \Config::get('moring.service_mysql');
54+
}
55+
56+
$logArray = [
57+
'service' => $service,
58+
'debug_info' => $debugInfo,
59+
'status' => $status,
60+
'user_id' => $userId,
61+
'route' => \Route::getCurrentRoute()->getActionName() . PHP_EOL,
62+
'callable_function' => $functionName,
63+
];
64+
65+
return SystemLogs::create($logArray);
66+
}
67+
}

0 commit comments

Comments
 (0)