226 lines
6.5 KiB
PHP
226 lines
6.5 KiB
PHP
<?php
|
|
class Morning extends MY_Controller
|
|
{
|
|
var $folder_db, $is_ganjil_genap, $is_ver_3;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
// $this->folder_db = "/backupdisk/db"; // matraman cimahi
|
|
$this->folder_db = "/var/backup-data/db/"; // backup v2
|
|
$this->is_ganjil_genap = false;
|
|
$this->is_ver_3 = true; // cikditiro
|
|
}
|
|
function test()
|
|
{
|
|
$this->sasone("Testing", "XA");
|
|
}
|
|
function index()
|
|
{
|
|
$this->log("Start Monitoring Pagi");
|
|
$sql = "select * from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
|
$branchName = "No Branch";
|
|
$branchCode = "";
|
|
$qry = $this->db->query($sql);
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
$branchName = $rows[0]["M_BranchName"];
|
|
$branchCode = $rows[0]["M_BranchCode"];
|
|
} else {
|
|
$this->log("Error Pending Merujuk : " . $this->db->error()["message"]);
|
|
}
|
|
$msg_service = $this->service();
|
|
$msg = "[ $branchCode | $branchName]\n";
|
|
$msg .= " DATE : " . date("Y-m-d H:i:s") . "\n";
|
|
$msg .= " UP : " . $this->uptime();
|
|
$msg .= " ----------\n";
|
|
$msg .= " Service : \n";
|
|
$msg .= $msg_service;
|
|
$msg .= " ----------\n";
|
|
$msg .= " Resource : \n";
|
|
$msg .= $this->resource();
|
|
$msg .= " ----------\n";
|
|
$msg .= " Connectivity:\n";
|
|
$msg .= $this->connectivity();
|
|
$msg .= " Backup:\n";
|
|
$msg .= $this->backup();
|
|
$this->log($msg);
|
|
$this->sasone($msg, $branchCode);
|
|
$this->log("End Monitoring Pagi");
|
|
}
|
|
function uptime()
|
|
{
|
|
exec("uptime", $output, $return);
|
|
$s_output = preg_split("/\s+/", $output[0]);
|
|
if (count($s_output) >= 5) {
|
|
$msg = "";
|
|
for ($i = 3; $i <= 5; $i++) {
|
|
$msg .= $s_output[$i] . " ";
|
|
}
|
|
if (!strpos($s_output[5], ":")) {
|
|
$msg .= $s_output[6];
|
|
}
|
|
return $msg . "\n";
|
|
}
|
|
return $output . "\n";
|
|
}
|
|
function service()
|
|
{
|
|
exec("pgrep apache2", $output, $return);
|
|
$result = "";
|
|
if ($return == 0) {
|
|
$result .= " Web Server running\n";
|
|
} else {
|
|
$result .= " Web Server NOT RUNNING\n";
|
|
}
|
|
exec("ps -ef | grep tomcat | grep java | awk ' { print $2 } '", $output, $return);
|
|
if ($return == 0) {
|
|
$result .= " Report Server running\n";
|
|
} else {
|
|
$result .= " Report Server NOT RUNNING\n";
|
|
}
|
|
exec("pgrep mysqld", $output, $return);
|
|
if ($return == 0) {
|
|
$result .= " MariaDB Server running\n";
|
|
} else {
|
|
$result .= " MariaDB Server NOT RUNNING\n";
|
|
}
|
|
return $result;
|
|
}
|
|
function resource()
|
|
{
|
|
$df = exec("df -h", $output, $return);
|
|
$result = "";
|
|
$is_pac = false;
|
|
$pac_tgt = "";
|
|
foreach ($output as $line) {
|
|
$parts = preg_split("/\s+/", $line);
|
|
$mount = $parts[5];
|
|
if ($mount == "/" || $mount == "/var") {
|
|
$result .= " folder $mount sisa " . $parts[3] . "\n";
|
|
}
|
|
if ($mount == "/data-pacs") {
|
|
$is_pac = true;
|
|
$pac_tgt = $parts[0];
|
|
}
|
|
}
|
|
if ($is_pac) {
|
|
$result .= " Pacs /data-pacs => $pac_tgt \n";
|
|
$folder = "/data-pacs/" . Date("Ymd", strtotime("now - 1 day"));
|
|
if (file_exists($folder)) {
|
|
$result .= " $folder exists\n";
|
|
} else {
|
|
$result .= " $folder not exists\n";
|
|
}
|
|
$folder = "/data-pacs/" . Date("Ymd", strtotime("now - 2 day"));
|
|
if (file_exists($folder)) {
|
|
$result .= " $folder exists\n";
|
|
} else {
|
|
$result .= " $folder not exists\n";
|
|
}
|
|
} else {
|
|
$result .= " Pacs not mounted \n";
|
|
}
|
|
return $result;
|
|
}
|
|
function backup($debug = "")
|
|
{
|
|
$msg = "";
|
|
$dow = date("w");
|
|
$org_dow = $dow;
|
|
if ($this->is_ganjil_genap) {
|
|
$dow = $org_dow % 2;
|
|
}
|
|
if ($this->is_ver_3) {
|
|
if ($dow == "3") $dow = "0";
|
|
if ($dow == "4") $dow = "1";
|
|
if ($dow == "5") $dow = "2";
|
|
if ($dow == "6") $dow = "0";
|
|
}
|
|
|
|
$file = $this->folder_db . "/one/daily/backup_one_dow_${dow}.sql";
|
|
$stat = stat($file);
|
|
$msg .= " " . str_pad(basename($file), 30, " ") . round($stat["size"] / (1024 * 1024 * 1024), 1) . "G"
|
|
. " " . date("Y-m-d H:i", $stat["ctime"]) . "\n";
|
|
$file = $this->folder_db . "/one_log/daily/backup_one_log_dow_${dow}.sql";
|
|
$stat = stat($file);
|
|
$msg .= " " . str_pad(basename($file), 30, " ") . round($stat["size"] / (1024 * 1024 * 1024), 1) . "G"
|
|
. " " . date("Y-m-d H:i", $stat["ctime"]) . "\n";
|
|
if ($debug != "") {
|
|
echo $msg . "\n";
|
|
}
|
|
return $msg;
|
|
}
|
|
function connectivity()
|
|
{
|
|
$regionalIP = trim($this->getRegionalIP());
|
|
$regonlineIP = "mobile.pramita.co.id";
|
|
$email = "email.pramita.co.id";
|
|
$result = "result.pramita.co.id";
|
|
$msg = "";
|
|
$msg .= $this->ping($regionalIP, 80, 5, true);
|
|
$msg .= $this->ping($regonlineIP, 443, 5);
|
|
$msg .= $this->ping($email, 587, 5);
|
|
$msg .= $this->ping($result, 443, 5);
|
|
return $msg;
|
|
}
|
|
function ping($host, $port, $timeout, $is_reg = false)
|
|
{
|
|
$tB = microtime(true);
|
|
$fP = fSockOpen($host, $port, $errno, $errstr, $timeout);
|
|
$s_target = "$host:$port";
|
|
if ($is_reg) $s_target = "[Reg]$s_target";
|
|
$s_target = str_pad($s_target, 38, " ");
|
|
if (!$fP) {
|
|
return " $s_target down ( connect timeout in $timeout s)\n";
|
|
}
|
|
$tA = microtime(true);
|
|
return " $s_target " . round((($tA - $tB) * 1000), 0) . " ms\n";
|
|
}
|
|
function log($msg)
|
|
{
|
|
$sdate = Date("Y-m-d H:i:s");
|
|
echo "$sdate $msg\n";
|
|
}
|
|
function getRegionalIP()
|
|
{
|
|
$sql = "select S_SystemIPAddressRegional from conf_systems";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
return "devone.aplikasi.web.id";
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) > 0) return $rows[0]["S_SystemIPAddressRegional"];
|
|
return "devone.aplikasi.web.id";
|
|
}
|
|
function clean_up_message($msg)
|
|
{
|
|
return $msg;
|
|
}
|
|
function sasone($msg, $branchCode)
|
|
{
|
|
$url = "http://bandungraya.aplikasi.web.id/one-api/tgram/xone_bot/chat_id_v2";
|
|
// chat id upgraded to -1001166991228
|
|
$data = json_encode(array(
|
|
"type" => "monitoring.pagi",
|
|
"branchCode" => $branchCode,
|
|
"text" => $msg,
|
|
"id" => "-1001166991228"
|
|
));
|
|
$z_data = gzdeflate($data, 9);
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $z_data);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt(
|
|
$ch,
|
|
CURLOPT_HTTPHEADER,
|
|
array(
|
|
'Content-Type: application/json',
|
|
'Content-Length: ' . strlen($z_data)
|
|
)
|
|
);
|
|
$result = curl_exec($ch);
|
|
echo $result;
|
|
}
|
|
}
|