94 lines
2.8 KiB
PHP
94 lines
2.8 KiB
PHP
<?php
|
|
class Xdb extends MY_Controller
|
|
{
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->db = $this->load->database("onedev", true);
|
|
}
|
|
function index() {
|
|
$this->cek(true);
|
|
}
|
|
function clean_up_message($msg) {
|
|
$msg = str_replace("-","\-",$msg);
|
|
$msg = str_replace("(","\(",$msg);
|
|
$msg = str_replace(")","\)",$msg);
|
|
$msg = str_replace(".","\.",$msg);
|
|
$msg = str_replace("[","\[",$msg);
|
|
$msg = str_replace("]","\]",$msg);
|
|
$msg = str_replace("|","\|",$msg);
|
|
$msg = str_replace("_","\_",$msg);
|
|
return $msg;
|
|
}
|
|
function replikasi($debug=false) {
|
|
$sql = "select * from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
|
$branchName = "No Branch";
|
|
$qry = $this->db->query($sql);
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
$branchName = $rows[0]["M_BranchName"];
|
|
} else {
|
|
print_r($this->db->error());
|
|
}
|
|
$sql = "show slave status";
|
|
$qry = $this->db->query($sql);
|
|
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
$msg = "";
|
|
if(count($rows) > 0 ) {
|
|
$r = $rows[0];
|
|
$prm = "Slave_IO_Running";
|
|
$msg .= "$prm : " . $r[$prm] . "\n";
|
|
$prm = "Slave_SQL_Running";
|
|
$msg .= "$prm : " . $r[$prm] . "\n";
|
|
$prm = "Seconds_Behind_Master";
|
|
$msg .= "$prm : " . $r[$prm] . "\n";
|
|
|
|
$prm = "Last_Errno";
|
|
$err_no = intval($r[$prm]);
|
|
$msg .= "$prm : " . $r[$prm] . "\n";
|
|
|
|
if ($err_no > 0 ) {
|
|
$prm = "Last_Error";
|
|
$msg .= "$prm : " . $r[$prm] . "\n";
|
|
}
|
|
}
|
|
if ($debug || $err_no > 0 ) {
|
|
echo $msg;
|
|
} else {
|
|
echo "";
|
|
}
|
|
exit;
|
|
if($msg != "" ) {
|
|
$msg = "[REPLIKASI] $branchName :\n$msg";
|
|
if ($debug || $err_no > 0 ) {
|
|
$msg = $this->clean_up_message($msg);
|
|
$this->sasone($msg);
|
|
}
|
|
}
|
|
} else {
|
|
print_r($this->db->error());
|
|
}
|
|
}
|
|
function print_chr($inp) {
|
|
for($i=0;$i<strlen($inp);$i++) {
|
|
$chr = substr($inp,$i,1);
|
|
echo "$i\t$chr => " . ord($chr) . "\n";
|
|
}
|
|
}
|
|
function sasone($msg) {
|
|
$url = "http://bandungraya.aplikasi.web.id/one-api/tgram/xone/sasone";
|
|
$data = json_encode( array("text" => $msg ));
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
'Content-Type: application/json',
|
|
'Content-Length: ' . strlen($data))
|
|
);
|
|
$result = curl_exec($ch);
|
|
echo $result;
|
|
}
|
|
}
|