db = $this->load->database("regional", 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 s_regional where S_RegionalIsActive = 'Y' and S_RegionalIsDefault = 'Y'"; $regionalName = "No Regional"; $regionalID = 0; $qry = $this->db->query($sql); if ($qry) { $rows = $qry->result_array(); $regionalName = $rows[0]["S_RegionalName"]; $regionalID = $rows[0]["S_RegionalID"]; } else { print_r($this->db->error()); } $sql = "show slave status"; $qry = $this->db->query($sql); $msg = ""; if ($qry) { $rows = $qry->result_array(); 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"; } } } else { print_r($this->db->error()); } //get per branch $sql = "select * from m_branch where M_BranchS_RegionalID = ?"; $qry = $this->db->query($sql, array($regionalID)) ; if ($qry) { $rows = $qry->result_array( ); foreach($rows as $r) { $name = $r["M_BranchName"]; $ip = $r["M_BranchIPAddress"]; $xdebug = ""; if($debug) $xdebug = "true"; $b_msg = $this->info($ip,$xdebug); if ($b_msg != "" ) { $msg .= "Cabang $name\n$b_msg\n"; } } } else { print_r($this->db->error()); } if($msg != "" ) { $msg = "[REPLIKASI] $regionalName :\n$msg"; if ($debug || $err_no > 0 ) { $msg = $this->clean_up_message($msg); $this->sasone($msg); } } } function print_chr($inp) { for($i=0;$i " . ord($chr) . "\n"; } } function info($ip,$debug="") { $url = "http://$ip/one-api/tools/monitoring/xdb/replikasi/$debug"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, 20); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data)) ); $result = curl_exec($ch); return $result; } 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; } }