# LibreNMS 外部整合

# LibreNMS Smokeping 安裝設定

<p class="callout info"><span style="color: rgb(0, 0, 0);">**SmokePing為開源的網路品質監控專案，LibreNMS可整合Smokeping方便監測設備**</span></p>

##### <span style="color: rgb(0, 0, 0);">**安裝Smokeping**</span>

<span style="color: rgb(0, 0, 0);">**下載Smokeping**</span>

```
apt-get install smokeping
```

<span style="color: rgb(0, 0, 0);">**複製Librenms smokeping腳本到cron**</span>

```
sudo cp /opt/librenms/misc/smokeping-debian.example /etc/cron.hourly/librenms-smokeping
sudo chmod +x /etc/cron.hourly/librenms-smokeping
```

<span style="color: rgb(0, 0, 0);">**手動執行cron一次並確認有建立檔案**</span>

```
/etc/cron.hourly/librenms-smokeping
ls -l /etc/smokeping/config.d/librenms-targets.conf
ls -l /etc/smokeping/config.d/librenms-probes.conf 
```

<span style="color: rgb(0, 0, 0);">**[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-11/scaled-1680-/Zzvimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-11/Zzvimage.png)**</span>

<span style="color: rgb(0, 0, 0);">**刪除`/etc/smokeping/config.d/Probes`內容並新增以下**</span>

```
*** Probes ***

@include /etc/smokeping/config.d/librenms-probes.conf
```

<span style="color: rgb(0, 0, 0);">**刪除`/etc/smokeping/config.d/Targets`內容並新增以下**</span>

```
*** Targets ***

probe = FPing

menu = Top
title = Network Latency Grapher
remark = Welcome to the SmokePing website of <b>Insert Company Name Here</b>. \
         Here you will learn all about the latency of our network.

@include /etc/smokeping/config.d/librenms-targets.conf
```

<span style="color: rgb(0, 0, 0);">**建立Smokeping資料儲存位置**</span>

```
mkdir /opt/librenms/rrd/smokeping
```

<span style="color: rgb(0, 0, 0);">**由於Smokeping執行會無法寫入`/opt/librenms/rrd/smokeping`**</span>

<span style="color: rgb(0, 0, 0);">**須將smokeping加入librenms群組對`/opt/librenms/rrd/smokeping`可讀寫**</span>

```
chown librenms:librenms /opt/librenms/rrd/smokeping

usermod -a -G librenms smokeping
```

<span style="color: rgb(0, 0, 0);">**網頁上設定剛剛建立的目錄，並設定每次測試發 20 個封包**</span>

<span style="color: rgb(0, 0, 0);">**[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-11/scaled-1680-/jR6image.png)](https://note.homesitetw.com/uploads/images/gallery/2025-11/jR6image.png)**</span>

<span style="color: rgb(0, 0, 0);">**編輯`/etc/smokeping/config.d/Database`，修改step改為每分鐘做一次測試(預設5分鐘)**</span>

<span style="color: rgb(0, 0, 0);">**[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-11/scaled-1680-/N53image.png)](https://note.homesitetw.com/uploads/images/gallery/2025-11/N53image.png)**</span>

<span style="color: rgb(0, 0, 0);">**編輯`/etc/smokeping/config.d/pathnames`，datadir 改為上面新增的目錄**</span>

<span style="color: rgb(0, 0, 0);">**[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-11/scaled-1680-/ULsimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-11/ULsimage.png)**</span>

<span style="color: rgb(0, 0, 0);">**重啟smokeping**</span>

```
service smokeping restart

service smokeping status
```

<span style="color: rgb(0, 0, 0);">**確認Librenms RRD內的smokeping已有資料**</span>

<span style="color: rgb(0, 0, 0);">**[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-11/scaled-1680-/QUyimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-11/QUyimage.png)**</span>

<span style="color: rgb(0, 0, 0);">**網頁上Latency內已有smokeping數值**</span>

<span style="color: rgb(0, 0, 0);">**[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-11/scaled-1680-/ouIimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-11/ouIimage.png)**</span>

##### <span style="color: rgb(0, 0, 0);">**網頁 Web UI 設定**</span>

<span style="color: rgb(0, 0, 0);">**安裝 fcgiwrap 才能使 CGI 包裝器與 Nginx 互動**</span>

```
apt install fcgiwrap
```

<span style="color: rgb(0, 0, 0);">**編輯`/etc/nginx/conf.d/librenms.conf`設定檔加入smokeping設定**</span>

```
# Browsing to `http://yourlibrenms/smokeping/` should bring up the smokeping web interface

location = /smokeping/ {
        fastcgi_intercept_errors on;

        fastcgi_param   SCRIPT_FILENAME         /usr/lib/cgi-bin/smokeping.cgi;
        fastcgi_param   QUERY_STRING            $query_string;
        fastcgi_param   REQUEST_METHOD          $request_method;
        fastcgi_param   CONTENT_TYPE            $content_type;
        fastcgi_param   CONTENT_LENGTH          $content_length;
        fastcgi_param   REQUEST_URI             $request_uri;
        fastcgi_param   DOCUMENT_URI            $document_uri;
        fastcgi_param   DOCUMENT_ROOT           $document_root;
        fastcgi_param   SERVER_PROTOCOL         $server_protocol;
        fastcgi_param   GATEWAY_INTERFACE       CGI/1.1;
        fastcgi_param   SERVER_SOFTWARE         nginx/$nginx_version;
        fastcgi_param   REMOTE_ADDR             $remote_addr;
        fastcgi_param   REMOTE_PORT             $remote_port;
        fastcgi_param   SERVER_ADDR             $server_addr;
        fastcgi_param   SERVER_PORT             $server_port;
        fastcgi_param   SERVER_NAME             $server_name;
        fastcgi_param   HTTPS                   $https if_not_empty;

        fastcgi_pass unix:/var/run/fcgiwrap.socket;
}

location ^~ /smokeping/ {
        alias /usr/share/smokeping/www/;
        index smokeping.cgi;
        gzip off;
}
```

<span style="color: rgb(0, 0, 0);">**重啟Nginx**</span>

```
nginx -t

service nginx restart
```

<span style="color: rgb(0, 0, 0);">**網頁上URL填入`/smokeping`**</span>

<span style="color: rgb(0, 0, 0);">**[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-11/scaled-1680-/H2Nimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-11/H2Nimage.png)**</span>

<span style="color: rgb(0, 0, 0);">**重整網頁後選擇`工具`&gt;`smokeping`**</span>

`<span style="color: rgb(0, 0, 0);"><strong><a href="https://note.homesitetw.com/uploads/images/gallery/2025-11/NFjimage.png" rel="noopener" style="color: rgb(0, 0, 0);" target="_blank"><img alt="image.png" src="https://note.homesitetw.com/uploads/images/gallery/2025-11/scaled-1680-/NFjimage.png"></img></a></strong></span>`

<span style="color: rgb(0, 0, 0);">**[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-11/scaled-1680-/J4dimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-11/J4dimage.png)**</span>

##### <span style="color: rgb(0, 0, 0);">**自訂監控設定**</span>

<span style="color: rgb(0, 0, 0);">**安裝好Web UI後顯示的是Librenms監控的設備清單，可自行加入host監控**</span>

<span style="color: rgb(0, 0, 0);">**編輯`/etc/smokeping/config.d/Targets`，新增自訂監控設定**</span>

```
@include /etc/smokeping/config.d/custom.conf
```

<span style="color: rgb(0, 0, 0);">**編輯`/etc/smokeping/config.d/custom.conf`，加入想要監控的host**</span>

```
+ Others
menu = Others
title = Others

++ GoogleDNS
menu = Google DNS
title = Google DNS
host = 8.8.8.8

++ CHTDNS
menu = CHT DNS
title = CHT DNS
host = 168.95.1.1
```

<span style="color: rgb(0, 0, 0);">**確認設定正確後重啟服務**</span>

```
smokeping --check

service smokeping restart
```

<span style="color: rgb(0, 0, 0);">**網頁上即可看到剛剛新增的host**</span>

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-11/scaled-1680-/buDimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-11/buDimage.png)

##### <span style="color: rgb(0, 0, 0);">**自訂Probes**</span>

<span style="color: rgb(0, 0, 0);">**除了內建使用fping，也可以下載Github上的<span style="color: rgb(230, 126, 35);">[tcpping](https://github.com/deajan/tcpping "tcpping")</span>，使用traceroute和tcptraceroute的命令，增加TCP PORT的監控**</span>

```
curl -o /usr/bin/tcpping -L https://raw.githubusercontent.com/deajan/tcpping/master/tcpping
chmod +x /usr/bin/tcpping
```

<span style="color: rgb(0, 0, 0);">**<span style="color: rgb(0, 0, 0);">測試tcpping正常</span>**</span>

```
root@librenms:~#  tcpping google.com 443
seq 0: tcp response from nctsaa-ac-in-f14.1e100.net (142.250.196.206)  7.402 ms
seq 1: tcp response from hkg07s38-in-f14.1e100.net (142.250.204.46)  7.545 ms
seq 2: tcp response from lctsaa-aa-in-f14.1e100.net (142.250.66.78)  7.399 ms
```

<span style="color: rgb(0, 0, 0);">**預設情況下，traceroute 需要 root 權限，所以要允許smokeping使用traceroute**</span>

<span style="color: rgb(0, 0, 0);">**建立`<span style="color: rgb(0, 0, 0);">/etc/tcpping.conf</span>`設定檔，並加入`-Z`參數(使用sudo)**</span>

```
TCPPING_EXTRA_ARGS="-Z"
```

<span style="color: rgb(0, 0, 0);">**執行`visudo`，讓 smokeping 以 root 身分執行 traceroute 無須密碼**</span>

```
smokeping ALL=(ALL) NOPASSWD: /usr/bin/traceroute
```

<span style="color: rgb(0, 0, 0);">**編輯`/etc/smokeping/config.d/Probes`，增加tcpping**</span>

```
+ TCPPing
  binary = /usr/bin/tcpping
```

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-11/scaled-1680-/3Znimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-11/3Znimage.png)

<span style="color: rgb(0, 0, 0);">**在監控設定檔內新增需要的host並指定probe和port**</span>

```
++ Google-https
menu = Google https
title = Google https
probe = TCPPing
port = 443
host = google.com
```

<span style="color: rgb(0, 0, 0);">**重啟smokeping後可以看到probe使用TCP Ping**</span>

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-11/scaled-1680-/CCyimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-11/CCyimage.png)