Blog Andri Wiratmono

Pagut Asri Blok D No.2 - Kelurahan Blabak - Pesantren Kota Kediri

back

NETWATCH Monitoring Perangkat Menggunakan Bot Whatsapp

11 Januari 2021 || 17:02:21 WIB || ClassyID

Topologi :

Mikrotik -> Server Web (php get) -> Bot WhatsApp

Untuk Script UP/DOWN di Netwatch Mikrotik, sama seperti yang dipakai jika kita pakai telegram.

:local idrouter [/system identity get name];
:local idtime [/system clock get time];
:local iddate [/system clock get date];
/tool fetch url="https://kirimwa.classy.id/kirimwa.php?pesan=*PING*%20Google.DNS%20*UP*%20Melalui%20Router%20*$idrouter*%20$iddate%20$idtime&handphone=6285648811419" keep-result=no

sebagai catatan, Webserver (php get) scriptnya seperti ini :

<?php
if( $_GET["pesan"] || $_GET["handphone"])
$message = $_GET['pesan'];
$phone_no = $_GET['handphone'];
//$message = preg_replace( "/(\n)/", "%0A", $message );
//$message = preg_replace( "/(\r)/", "%0A", $message );
$phone_no = preg_replace( "/(\n)/", ",", $phone_no );
$phone_no = preg_replace( "/(\r)/", "", $phone_no );
$data = array("to" => $phone_no, "pesan" => $message);
$data_string = json_encode($data);
$ch = curl_init('http://server.bot.whatsapp:1122/waapi/sendText');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
?>

Jika sudah running, setiap jaringan down/up,kita dikirimi Pesan Singkat melalui whatsapp