print_table_style(); //ping $origin = $_SERVER["SERVER_NAME"]; $rows = []; $rows[] = ["host" => "Server $origin"]; $this->print_table($rows,array_keys($rows[0]),"Origin"); $output = []; exec("ping -c 3 mobile.pramita.co.id",$output,$result_code); $rows = []; $rows[] = ["Ping Test to mobile.pramita.co.id" => "Result Code : $result_code"]; $rows[] = ["Ping Test to mobile.pramita.co.id" => implode("
",$output)]; $this->print_table($rows,array_keys($rows[0])); //curl to mobile.pramita.co.id echo "
"; $resp = $this->post("https://mobile.pramita.co.id/one-api/info",""); $this->print_table([$resp], array_keys($resp), "curl https://mobile.pramita.co.id/one-api/info"); $rows = $this->get_heartbeat(); echo "
"; $this->print_table($rows,array_keys($rows[0]),"Last HeartBeat status"); echo "
"; $rows = $this->get_upload(); $this->print_table($rows,array_keys($rows[0]),"Last Post Back status"); } function get_upload() { $sql = "select distinct pbUploadCode,pbUploadExecuted from pb_upload"; $qry = $this->db->query($sql); if (!$qry) { echo "Error Get Poll Back status : " . $this->db->error()["message"]; return []; } $rows = $qry->result_array(); return $rows; } function get_heartbeat() { $sql = "select distinct heartbeatCode,heartbeatExecuted,heartbeatStatus from regonline.heartbeat"; $qry = $this->db->query($sql); if (!$qry) { echo "Error Get HeartBeat status : " . $ths->db->error()["message"]; return []; } $rows = $qry->result_array(); foreach($rows as $idx => $r) { switch($r["heartbeatCode"]) { case "CAROUSEL" : $rows[$idx]["heartbeatCode"] = "Caraousel"; break; case "PING" : $rows[$idx]["heartbeatCode"] = "Ping"; break; case "SWAB" : $rows[$idx]["heartbeatCode"] = "Schedule"; break; case "QUOTA_PCR": $rows[$idx]["heartbeatCode"] = "Quota"; break; case "PRICE_PACKET": $rows[$idx]["heartbeatCode"] = "Price and Agreement"; break; case "HS": case "MOU_REG": case "ORDER_BRANCH": unset($rows[$idx]); break; case "BEST_SELLER": $rows[$idx]["heartbeatCode"] = "Best Seller"; break; } } return $rows; } public function post($url, $data) { $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_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data) )); $z_result = curl_exec($ch); if (curl_errno($ch) > 0) { return array( "status" => "ERR", "message" => curl_error($ch) ); } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpCode != 200) { return array( "status" => "ERR", "message" => "Http Response : $httpCode | $z_result" ); } $j_result = ["status" => "OK", "message" => "Connection OK"]; return $j_result; } public function print_table_style() { echo " "; } public function print_table($rows, $keys, $title = false) { echo ""; if ($title) { $col_span = count($keys); echo ""; echo ""; echo ""; } echo ""; foreach ($keys as $k) { echo ""; } echo "\n"; foreach ($rows as $r) { echo ""; foreach ($keys as $k) { echo ""; } echo ""; } echo "
$title
$k
" . $r[$k] . "
"; } } ?>