Backup OpenWrt NUT Configuration & Scripts
This commit is contained in:
70
Langkah_Kerja.md
Normal file
70
Langkah_Kerja.md
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
# Panduan Instalasi OpenWrt NUT & Notifikasi MikroTik
|
||||||
|
|
||||||
|
Gunakan panduan ini untuk mengkonfigurasi router OpenWrt baru agar sama persis dengan setingan saat ini.
|
||||||
|
|
||||||
|
## 1. Persiapan Paket
|
||||||
|
Pastikan router terhubung internet, lalu install paket yang dibutuhkan via Terminal (SSH):
|
||||||
|
```bash
|
||||||
|
opkg update
|
||||||
|
opkg install nut usbutils curl ca-bundle ca-certificates
|
||||||
|
```
|
||||||
|
*Catatan: Paket `nut` biasanya sudah mencakup driver dan tools dasar.*
|
||||||
|
|
||||||
|
## 2. Restore File Konfigurasi
|
||||||
|
Upload file-file berikut dari folder backup ini ke router OpenWrt (gunakan SCP atau WinSCP):
|
||||||
|
|
||||||
|
1. **Folder `/etc/nut/`**:
|
||||||
|
- `ups.conf` (Setingan Driver UPS)
|
||||||
|
- `upsd.conf` (Setingan Server Listen Port)
|
||||||
|
- `upsd.users` (User Monitor)
|
||||||
|
- `upsmon.conf` (Setingan Monitor & Notifikasi)
|
||||||
|
- `nut.conf` (Mode Netserver)
|
||||||
|
- `notify_mikrotik.sh` (Script Notifikasi Utama)
|
||||||
|
|
||||||
|
2. **Folder `/etc/init.d/`**:
|
||||||
|
- `nut-server` (Script Startup Server)
|
||||||
|
- `nut-monitor` (Script Startup Monitor)
|
||||||
|
|
||||||
|
## 3. Set Permission (Hak Akses)
|
||||||
|
Setelah file di-upload, jalankan perintah ini di terminal OpenWrt agar script bisa dijalankan:
|
||||||
|
```bash
|
||||||
|
chmod +x /etc/nut/notify_mikrotik.sh
|
||||||
|
chmod +x /etc/init.d/nut-server
|
||||||
|
chmod +x /etc/init.d/nut-monitor
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4. Aktifkan Service
|
||||||
|
Nyalakan service agar jalan otomatis saat router nyala:
|
||||||
|
```bash
|
||||||
|
/etc/init.d/nut-server enable
|
||||||
|
/etc/init.d/nut-monitor enable
|
||||||
|
/etc/init.d/nut-server start
|
||||||
|
/etc/init.d/nut-monitor start
|
||||||
|
```
|
||||||
|
|
||||||
|
## 5. Konfigurasi Kunci SSH (PENTING!)
|
||||||
|
Agar OpenWrt bisa kirim perintah ke MikroTik tanpa password, Anda harus membuat kunci rahasia (SSH Key) baru di OpenWrt.
|
||||||
|
|
||||||
|
1. **Buat Key di OpenWrt**:
|
||||||
|
```bash
|
||||||
|
ssh-keygen
|
||||||
|
```
|
||||||
|
*(Tekan Enter terus sampai selesai, biarkan default)*
|
||||||
|
|
||||||
|
2. **Lihat Public Key**:
|
||||||
|
```bash
|
||||||
|
cat /root/.ssh/id_rsa.pub
|
||||||
|
```
|
||||||
|
*(Copy tulisan yang muncul, biasanya diawali `ssh-rsa ...`)*
|
||||||
|
|
||||||
|
3. **Import ke MikroTik**:
|
||||||
|
- Login ke Winbox MikroTik (192.168.7.1 & 103.125.50.7).
|
||||||
|
- Masuk ke menu **System -> Users -> SSH Keys**.
|
||||||
|
- Import key tersebut untuk user `upsuser`.
|
||||||
|
|
||||||
|
## 6. Test Sistem
|
||||||
|
Coba test apakah notifikasi berjalan:
|
||||||
|
```bash
|
||||||
|
/etc/nut/notify_mikrotik.sh "TEST_INSTALL"
|
||||||
|
```
|
||||||
|
Jika sukses, log akan muncul di MikroTik dan pesan masuk ke Telegram.
|
||||||
27
notify_mikrotik.sh
Normal file
27
notify_mikrotik.sh
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# $1 = event type (ONLINE, ONBATT, LOWBATT, FSD, etc.)
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
MIKROTIK_TARGETS="192.168.7.1 103.125.50.7"
|
||||||
|
TELEGRAM_BOT_TOKEN="6770207225:AAG3yNPepyhhGXqNh8BYjLYUMctc1DSfrH4"
|
||||||
|
TELEGRAM_CHAT_ID="6796478523"
|
||||||
|
|
||||||
|
# Message for Telegram
|
||||||
|
DATE=$(date "+%Y-%m-%d %H:%M:%S")
|
||||||
|
MESSAGE="UPS Notification: $1 at $DATE"
|
||||||
|
|
||||||
|
# 1. Send to Telegram using CURL (Secure)
|
||||||
|
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" -d chat_id="$TELEGRAM_CHAT_ID" -d text="$MESSAGE" > /dev/null 2>&1 &
|
||||||
|
|
||||||
|
# 2. Send to MikroTik Routers
|
||||||
|
for IP in $MIKROTIK_TARGETS; do
|
||||||
|
# Log event
|
||||||
|
ssh -i /root/.ssh/id_rsa -y upsuser@$IP "/log warning \"UPS Notification: $1\"" &
|
||||||
|
|
||||||
|
# Shutdown on Critical
|
||||||
|
if [ "$1" = "LOWBATT" ] || [ "$1" = "FSD" ]; then
|
||||||
|
ssh -i /root/.ssh/id_rsa -y upsuser@$IP "/system shutdown" &
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
wait
|
||||||
21
nut-monitor
Normal file
21
nut-monitor
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/sh /etc/rc.common
|
||||||
|
|
||||||
|
START=60
|
||||||
|
USE_PROCD=1
|
||||||
|
|
||||||
|
restart() {
|
||||||
|
stop_service
|
||||||
|
start_service
|
||||||
|
}
|
||||||
|
|
||||||
|
start_service() {
|
||||||
|
upsmon -p
|
||||||
|
}
|
||||||
|
|
||||||
|
stop_service() {
|
||||||
|
upsmon -c stop
|
||||||
|
}
|
||||||
|
|
||||||
|
reload_service() {
|
||||||
|
upsmon -c reload
|
||||||
|
}
|
||||||
23
nut-server
Normal file
23
nut-server
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/sh /etc/rc.common
|
||||||
|
|
||||||
|
START=50
|
||||||
|
USE_PROCD=1
|
||||||
|
|
||||||
|
restart() {
|
||||||
|
stop_service
|
||||||
|
start_service
|
||||||
|
}
|
||||||
|
|
||||||
|
start_service() {
|
||||||
|
upsdrvctl start
|
||||||
|
upsd
|
||||||
|
}
|
||||||
|
|
||||||
|
stop_service() {
|
||||||
|
upsd -c stop
|
||||||
|
upsdrvctl stop
|
||||||
|
}
|
||||||
|
|
||||||
|
reload_service() {
|
||||||
|
upsd -c reload
|
||||||
|
}
|
||||||
6
ups.conf
Normal file
6
ups.conf
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[myups]
|
||||||
|
driver = blazer_usb
|
||||||
|
port = auto
|
||||||
|
vendorid = 0665
|
||||||
|
productid = 5161
|
||||||
|
desc = "UPS 0665:5161"
|
||||||
5
upsd.users
Normal file
5
upsd.users
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[monuser]
|
||||||
|
password = secret
|
||||||
|
upsmon master
|
||||||
|
actions = SET
|
||||||
|
instcmds = ALL
|
||||||
6
upsmon.conf
Normal file
6
upsmon.conf
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
MONITOR myups@localhost 1 monuser secret master
|
||||||
|
|
||||||
|
NOTIFYCMD /etc/nut/notify_mikrotik.sh
|
||||||
|
NOTIFYFLAG ONLINE SYSLOG+EXEC
|
||||||
|
NOTIFYFLAG ONBATT SYSLOG+EXEC
|
||||||
|
NOTIFYFLAG LOWBATT SYSLOG+EXEC
|
||||||
Reference in New Issue
Block a user