# Linux Server Monitoring dengan Menggunakan Telegram Bot

<figure><img src="https://nos.wjv-1.neo.id/cdn.medusa.my.id/Linux%20Bot.png" alt=""><figcaption></figcaption></figure>

## Introduction

Berikut ini adalah tulisan mengenai bagaimana cara melakukan monitoring server yang menggunakan sistem operasi GNU/Linux dengan memanfaatkan bantuan dari Telegram Bot, yang mana bot ini dibuat dengan menggunakan bahasa pemrograman [**PHP (Hypertext Preprocessor)**](https://www.php.net).

Dengan adanya bot ini diharapkan dapat memudahkan proses monitoring tanpa harus masuk ke dalam server secara langsung dengan melakukan SSH.

## Requirements

* [**Git**](https://git-scm.com/downloads).
* [**Nginx**](http://nginx.org/en/download.html).
* [**PHP-FPM**](https://php-fpm.org/download).
* [**PHP**](https://www.php.net/downloads.php).
* [**BIND**](https://www.isc.org/download/).
* [**Certbot**](https://certbot.eff.org/instructions?ws=nginx\&os=centosrhel7).
* [**Telegram**](https://telegram.org/apps).

## Installation

### Konfigurasi Web Server & SSL

Konfigurasi Web Server dan juga SSL, untuk instalasi Certbot silakan mengikuti tautan berikut:

{% code overflow="wrap" fullWidth="false" %}

```url
https://certbot.eff.org/lets-encrypt/centosrhel7-nginx
```

{% endcode %}

### Cloning Source Code PHP

Kemudian lakukan cloning PHP source code berikut ke root directory website atau domain (Misal: **`/var/www/[DOMAIN]/public_html`**):

{% code overflow="wrap" lineNumbers="true" %}

```bash
cd /var/www/[DOMAIN]/public_html
git clone https://github.com/madfxr/SERVBot.git
```

{% endcode %}

## Configuration

### Membuat Bot Baru di BotFather

Setelah itu lakukan chat ke [**@BotFather**](https://t.me/BotFather) di Telegram dan buat bot baru (Misal: **BOT\_NAME**).

### Generate HTTP API Token

Kemudian buat HTTP API Token baru di [**@BotFather**](https://t.me/BotFather) (Misal: **613961047:AZFWy0k603kLssujSIkKacmKuxxxTnq8Wl4**).

### Integrasi Telegram Bot

Ubah file **`index.php`**&#x64;an sesuaikan **\[AUTHORIZATION\_TOKEN]**  dengan menggunakan HTTP API Token yang sebelumnya kita dapat dari [**@BotFather**](https://t.me/BotFather) di Telegram (Misal: **613961047:AZFWy0k603kLssujSIkKacmKuxxxTnq8Wl4**).

### Upload File PHP

Setelah itu upload file **index.php** ke Web Server yang sudah ter-install sertifikat SSL sebelumnya.

### Verifikasi Webhook Telegram Bot

Akses URL berikut ini melalui web browser untuk mengeset webhook \*\*<https://api.telegram.org/bot\\[AUTHORIZATION\\_TOKEN]/setWebhook?url=https://domain.tld/index.php**:&#x20>;

{% code overflow="wrap" %}

```url
https://api.telegram.org/bot613961047:AZFWy0k603kLssujSIkKacmKuxxxTnq8Wl4/setWebhook?url=https://domain.tld/index.php
```

{% endcode %}

### Membuat Command Bot

Terakhir chat ke [**@BotFather**](https://t.me/BotFather) di Telegram dan edit **`@BOT_NAME`** command:

{% hint style="info" %}

```markdown
df - Report file system disk space usage
free - Display amount of free and used memory in the system 
ps - Report a snapshot of the current processes
top - Report a snapshot of the current processes
namedstatus - Show Internet domain name server service status
nginxstatus - Show HTTP and reverse proxy server, mail proxy server service status
phpfpmstatus - Show PHP FastCGI Process Manager service status
sshdstatus - Show OpenSSH SSH service status
date - Print or set the system date and time
uptime - Tell how long the system has been running
id - Print real and effective user and group IDs
ls - List directory contents
pwd - Print name of current/working directory
last - Show a listing of last logged in users
w - Show who is logged on and what they are doing
phpversion - Show PHP version number
sysinfo - Print system operation information
uname - Print system information
nc - Arbitrary TCP and UDP connections and listens
ping - Send ICMP ECHO_REQUEST to network hosts
telnet - User interface to the TELNET protocol
traceroute - Print the route packets trace to network host
curl - Transfer data from or to a server
dig - DNS lookup utility
whois - Client for the whois directory service
```

{% endhint %}

> **Catatan:**
>
> * SERVBot hanya dicoba di sistem operasi CentOS 7 x86\_64 saja.
> * Jika menggunakan sistem operasi lain, jangan lupa untuk melakukan perubahan pada source code PHP yang sudah ada.

Demikian sedikit pengetahuan dan pengalaman yang dapat saya bagikan, semoga apa yang telah saya sampaikan dapat bermanfaat bagi kita semua.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.madfxr.my.id/documentation/categories/linux/linux-server-monitoring-dengan-menggunakan-telegram-bot.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
