trafficmonitor init...2
This commit is contained in:
parent
c9671fbfb7
commit
1acec442fe
@ -2,22 +2,24 @@
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
use App\Entities\CommonEntity;
|
||||
use App\Controllers\CommonController;
|
||||
|
||||
use App\DTOs\CommonDTO;
|
||||
use App\Entities\CommonEntity;
|
||||
use App\Traits\LogTrait;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\Validation\Exceptions\ValidationException;
|
||||
use CodeIgniter\HTTP\DownloadResponse;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Html;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
abstract class AdminController extends CommonController
|
||||
{
|
||||
use LogTrait;
|
||||
public const PATH = 'admin';
|
||||
private ?string $_title = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
|
||||
36
app/Controllers/CLI/Collector.php
Normal file
36
app/Controllers/CLI/Collector.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\CLI;
|
||||
|
||||
use App\Controllers\CommonController;
|
||||
use App\DTOs\CollectorDTO;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Collector extends CommonController
|
||||
{
|
||||
public const PATH = 'collector';
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
if ($this->service === null) {
|
||||
$this->service = service('collectorservice');
|
||||
}
|
||||
$this->addActionPaths($this::PATH);
|
||||
}
|
||||
protected function createDTO(array $formDatas): CollectorDTO
|
||||
{
|
||||
return new CollectorDTO($formDatas);
|
||||
}
|
||||
public function execute(): void
|
||||
{
|
||||
$trafficService = service('trafficservice');
|
||||
foreach ($trafficService->getEntities(['status' => STATUS['AVAILABLE']]) as $entity) {
|
||||
$data = $this->service->getCalculatedData($entity);
|
||||
// Collector DB에 결과 저장
|
||||
$this->service->create($this->createDTO($data));
|
||||
log_message('info', "트래픽 계산 및 저장 완료 (UID: {$entity->getPK()}), In: {$data['in_kbits_sec']} Kb/s");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\CLI\DBMigration;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\Database\BaseConnection;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use App\Libraries\DBMigration\Process\MigrationProcessInterface;
|
||||
|
||||
abstract class DBMigration extends BaseController
|
||||
{
|
||||
private $_targetDB = null;
|
||||
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
abstract protected function getSourceDB(): BaseConnection;
|
||||
abstract protected function getClient(): array;
|
||||
abstract protected function getLine(): array;
|
||||
abstract protected function getServerCode(): array;
|
||||
abstract protected function getSWITCHCode(): array;
|
||||
abstract protected function getPartCode(): array;
|
||||
|
||||
final protected function getTargetDB(): BaseConnection
|
||||
{
|
||||
if ($this->_targetDB === null) {
|
||||
$this->_targetDB = \Config\Database::connect('default');
|
||||
}
|
||||
return $this->_targetDB;
|
||||
}
|
||||
|
||||
/**
|
||||
* 공통 마이그레이션 처리 로직
|
||||
*/
|
||||
final protected function migration(MigrationProcessInterface $processor, array $rows, string $functionName): void
|
||||
{
|
||||
$this->getTargetDB()->transStart();
|
||||
try {
|
||||
$cnt = 1;
|
||||
foreach ($rows as $row) {
|
||||
$processor->process($row, $cnt);
|
||||
$cnt++;
|
||||
}
|
||||
echo "{$functionName} 작업을 완료하였습니다.";
|
||||
$this->getTargetDB()->transCommit();
|
||||
} catch (\Exception $e) {
|
||||
$this->getTargetDB()->transRollback();
|
||||
echo "{$functionName} 작업을 실패하였습니다.\n--------------\n" . $e->getMessage() . "\n--------------\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,149 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\CLI\DBMigration;
|
||||
|
||||
use CodeIgniter\Database\BaseConnection;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use App\Libraries\DBMigration\Process\ClientProcess;
|
||||
use App\Libraries\DBMigration\Process\LineProcess;
|
||||
use App\Libraries\DBMigration\Process\ServerCodeProcess;
|
||||
use App\Libraries\DBMigration\Process\SWITCHCodeProcess;
|
||||
use App\Libraries\DBMigration\Process\PartCodeProcess;
|
||||
|
||||
class SourceDB extends DBMigration
|
||||
{
|
||||
private $_sourceDB = null;
|
||||
|
||||
/**
|
||||
* SQL 쿼리 상수 정의
|
||||
*/
|
||||
private const SQL_GET_CLIENT = "SELECT * FROM clientdb";
|
||||
private const SQL_GET_LINE = "SELECT Line_code, line_case, Line_ip, line_client_name, line_gateway, line_id, line_pass, line_name, line_haveip, line_phone, line_mainip FROM linedb";
|
||||
private const SQL_GET_SERVER_CODE = "SELECT DISTINCT(server_code) FROM serverdb WHERE server_code NOT LIKE ?";
|
||||
private const SQL_GET_SWITCH_CODE = "SELECT DISTINCT(service_sw) FROM servicedb WHERE service_sw NOT LIKE ?";
|
||||
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* 소스 데이터베이스 연결 반환
|
||||
*/
|
||||
final protected function getSourceDB(): BaseConnection
|
||||
{
|
||||
if ($this->_sourceDB === null) {
|
||||
$config = [
|
||||
'DSN' => '',
|
||||
'hostname' => env('database.source.hostname', 'localhost'),
|
||||
'username' => env('database.source.username', 'root'),
|
||||
'password' => env('database.source.password', ''),
|
||||
'database' => env('database.source.database', 'primeidc'),
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => '',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'cacheOn' => false,
|
||||
'cacheDir' => '',
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
];
|
||||
$this->_sourceDB = \Config\Database::connect($config);
|
||||
}
|
||||
return $this->_sourceDB;
|
||||
}
|
||||
|
||||
/**
|
||||
* 공통 쿼리 실행 메서드
|
||||
*/
|
||||
private function executeQuery(string $sql, array $params = []): array
|
||||
{
|
||||
return $this->getSourceDB()
|
||||
->query($sql, $params)
|
||||
->getResultArray();
|
||||
}
|
||||
private function executeFile(string $filename, string $deilmeter = ','): array
|
||||
{
|
||||
$datas = [];
|
||||
$lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
foreach ($lines as $line) {
|
||||
$datas[] = explode($deilmeter, $line);
|
||||
}
|
||||
return $datas;
|
||||
}
|
||||
|
||||
protected function getClient(): array
|
||||
{
|
||||
return $this->executeQuery(self::SQL_GET_CLIENT);
|
||||
}
|
||||
|
||||
protected function getLine(): array
|
||||
{
|
||||
return $this->executeQuery(self::SQL_GET_LINE);
|
||||
}
|
||||
|
||||
protected function getServerCode(): array
|
||||
{
|
||||
return $this->executeQuery(self::SQL_GET_SERVER_CODE, ['%일회성%']);
|
||||
}
|
||||
|
||||
protected function getSWITCHCode(): array
|
||||
{
|
||||
return $this->executeQuery(self::SQL_GET_SWITCH_CODE, ['%일회성%']);
|
||||
}
|
||||
protected function getPartCode(): array
|
||||
{
|
||||
return $this->executeFile('/home/donfig/dbmsv2/app/Database/dbmsv2_part.txt');
|
||||
}
|
||||
final public function client(): void
|
||||
{
|
||||
$this->migration(
|
||||
new ClientProcess($this->getTargetDB()),
|
||||
$this->getClient(),
|
||||
__FUNCTION__
|
||||
);
|
||||
}
|
||||
|
||||
final public function line(): void
|
||||
{
|
||||
$this->migration(
|
||||
new LineProcess($this->getTargetDB()),
|
||||
$this->getLine(),
|
||||
__FUNCTION__
|
||||
);
|
||||
}
|
||||
|
||||
final public function servercode(): void
|
||||
{
|
||||
$this->migration(
|
||||
new ServerCodeProcess($this->getTargetDB()),
|
||||
$this->getServerCode(),
|
||||
__FUNCTION__
|
||||
);
|
||||
}
|
||||
|
||||
final public function switchcode(): void
|
||||
{
|
||||
$this->migration(
|
||||
new SWITCHCodeProcess($this->getTargetDB()),
|
||||
$this->getSWITCHCode(),
|
||||
__FUNCTION__
|
||||
);
|
||||
}
|
||||
final public function partcode(): void
|
||||
{
|
||||
$this->migration(
|
||||
new PartCodeProcess($this->getTargetDB()),
|
||||
$this->getPartCode(),
|
||||
__FUNCTION__
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\CLI;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Entities\Customer\ServiceEntity;
|
||||
use App\Services\Customer\ServiceService;
|
||||
use App\Services\PaymentService;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Payment extends BaseController
|
||||
{
|
||||
private ?PaymentService $_paymentService = null;
|
||||
private ?ServiceService $_service = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
public function getService(): ServiceService
|
||||
{
|
||||
if (!$this->_service) {
|
||||
$this->_service = new ServiceService();
|
||||
}
|
||||
return $this->_service;
|
||||
}
|
||||
public function getPaymentService(): PaymentService
|
||||
{
|
||||
if (!$this->_paymentService) {
|
||||
$this->_paymentService = new PaymentService();
|
||||
}
|
||||
return $this->_paymentService;
|
||||
}
|
||||
public function billing(): void
|
||||
{
|
||||
//Transaction Start
|
||||
$db = \Config\Database::connect();
|
||||
$db->transStart();
|
||||
try {
|
||||
log_message("notice", "Billing 작업을 시작.");
|
||||
//결제일이 오늘보다 크고, 상태가 사용중인 서비스정보를 이용해서 결제정보에 신규 추가하기
|
||||
foreach ($this->getService()->getEntities(['billing_at' => date("Y-m-d"), 'status' => STATUS['AVAILABLE']]) as $entity) {
|
||||
// echo $serviceEntity->getPK() . ":" . $serviceEntity->getBillingAt() . "\n";
|
||||
$entity = $this->getPaymentService()->setService('create', $entity, []);
|
||||
$entity = $this->getService()->modify(
|
||||
$entity,
|
||||
[
|
||||
'billing_at' => $this->getService()->getNextMonthDate($entity),
|
||||
'paymentifo_uid' => $entity->getPaymentUID(),
|
||||
'serverinfo_uid' => $entity->getServerInfoUID()
|
||||
]
|
||||
);
|
||||
log_message("notice", sprintf("%s/%s원 결제추가\n", $entity->getCustomTitle(), $entity->getAmount()));
|
||||
}
|
||||
// echo $this->getService()->getModel()->getLastQuery() . "\n";
|
||||
log_message("notice", "Billing 작업을 완료.");
|
||||
$db->transCommit();
|
||||
} catch (\Exception $e) {
|
||||
//Transaction Rollback
|
||||
$db->transRollback();
|
||||
log_message(
|
||||
"error",
|
||||
"Billing 작업을 실패하였습니다.\n--------------\n" .
|
||||
$e->getMessage() .
|
||||
"\n--------------\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,16 +4,13 @@ namespace App\Controllers;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\AuthContext;
|
||||
use App\Traits\LogTrait;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use PhpParser\Node\Scalar\MagicConst\Dir;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
abstract class CommonController extends BaseController
|
||||
{
|
||||
use LogTrait;
|
||||
private array $_action_paths = [];
|
||||
private array $_viewDatas = [];
|
||||
protected $service = null;
|
||||
|
||||
@ -103,7 +103,6 @@ class CollectorService extends CommonService
|
||||
{
|
||||
$currentInOctets = $this->getSNMPOctets($trafficEntity, self::OID_IF_IN_OCTETS);
|
||||
$currentOutOctets = $this->getSNMPOctets($trafficEntity, self::OID_IF_OUT_OCTETS);
|
||||
$currentTime = Time::now()->toDateTimeString();
|
||||
if ($currentInOctets === null || $currentOutOctets === null) {
|
||||
$message = "트래픽 수집 실패: {$trafficEntity->getIP()} - IF{$trafficEntity->getInterface()} (UID: {$trafficEntity->getPK()})";
|
||||
log_message('warning', $message);
|
||||
@ -137,14 +136,6 @@ class CollectorService extends CommonService
|
||||
'out_kbits_sec' => round($outKbitsSec, 2),
|
||||
'raw_in_octets' => $currentInOctets,
|
||||
'raw_out_octets' => $currentOutOctets,
|
||||
'created_at' => $currentTime,
|
||||
];
|
||||
}
|
||||
public function collectAndSave(TrafficEntity $trafficEntity): void
|
||||
{
|
||||
$data = $this->getCalculatedData($trafficEntity);
|
||||
// Collector DB에 결과 저장
|
||||
$this->model->insert($data);
|
||||
log_message('info', "트래픽 계산 및 저장 완료 (UID: {$trafficEntity->getPK()}), In: {$data['in_kbits_sec']} Kb/s");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user