76 lines
2.4 KiB
PHP
76 lines
2.4 KiB
PHP
<?php
|
|
class Cabang extends MY_Controller
|
|
{
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->db = $this->load->database("regional", true);
|
|
}
|
|
function pingAddress($ip) {
|
|
$pingresult = exec("/bin/ping -c 3 $ip", $outcome, $status);
|
|
$i_status = $status;
|
|
if (0 == $status) {
|
|
$status = "alive";
|
|
} else {
|
|
$status = "dead";
|
|
}
|
|
return array($i_status, "The IP address, $ip, is ".$status ."\n" .
|
|
$pingresult . "\n");
|
|
}
|
|
|
|
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);
|
|
$msg = str_replace(":","\:",$msg);
|
|
return $msg;
|
|
}
|
|
function index() {
|
|
$this->check();
|
|
}
|
|
function check($is_cek=false) {
|
|
$sql = "select m_branch.* from m_branch
|
|
join s_regional on M_BranchS_RegionalID = S_RegionalID and
|
|
S_RegionalIsActive = 'Y' and S_RegionalIsDefault = 'Y' and M_BranchIsActive = 'Y'";
|
|
$branchName = "No Branch";
|
|
$qry = $this->db->query($sql);
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
$result = "";
|
|
$have_err = false;
|
|
foreach($rows as $r) {
|
|
$branchName = $r["M_BranchName"];
|
|
$branchIP = $r["M_BranchIPAddress"];
|
|
list($code,$xresult) = $this->pingAddress($branchIP);
|
|
if ($code != 0 ) $have_err = true;
|
|
$result .= "[$branchName]:\n" . $xresult . "\n";
|
|
}
|
|
if ($have_err || $is_cek) {
|
|
$this->sasone($result);
|
|
}
|
|
} else {
|
|
print_r($this->db->error());
|
|
}
|
|
}
|
|
|
|
function sasone($msg) {
|
|
$msg = $this->clean_up_message($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;
|
|
}
|
|
}
|