# OpenNMS 學習紀錄 (with CentOS 7.6)
## Installation
[toc]
下連結為 [OpenNMS官方網站](http://www.adventuresinoss.org/en/install-centos
) 提供的 安裝影片連結
:::danger
現今的版本依照影片的步驟做會遇到問題:
* Postgresql 的版本太舊導致於無法安裝
* 即使更新 Postgresql 版本也會遭遇到安裝包執行失敗
:::
:::info
調整過後的安裝包連結如下:
[https://drive.google.com/file/d/1ResM29-n2QznGYeTQK70Jytb-3ErrQT2/view?usp=sharing](https://drive.google.com/file/d/1ResM29-n2QznGYeTQK70Jytb-3ErrQT2/view?usp=sharing)
:::
### 1.Download 後解壓縮
```bash=
tar xvf opennmsinstall.tar
```
```bash=2
cd opennms-install-1.4/
```
### 2.安裝 **java-11-openjdk-devel**
```bash=3
yum install -y java-11-openjdk-devel
```
### 3.安裝 PostgreSQL (建議直接到官方網站下載)
[https://www.postgresql.org/download/](https://www.postgresql.org/download/)
選擇所需要的 OS 
使用 10 版當作 範例
依序進行官網上的操作
```bash=4
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum -y install postgresql10
yum -y install postgresql10-server
```
### 4.將Postgresql 的服務加入 .bashrc
```bash=5
vi ~/.bashrc
```
```cmake
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias postgresql-setup='postgresql-10-setup' #新增此行
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export PATH=/usr/pgsql-10/bin:$PATH #以及此行
```
```bash=6
source ~/.bashrc
```
### 5.開始安裝 opennms
```bash=7
bash bootstrap-yum.sh
```
照著安裝步驟走即可完成
### 6.開通防火牆
```bash=8
firewall-cmd --permanent --add-port=8980/tcp
systemctl restart firewalld
```

-------------------------------------------------------------------
## 監控功能 - Discover Device
:::info
OpenNMS 透過 Discovery 功能可以進行特定 IP 監控或是進行整個IP區段的監控
OpenNMS 使用 thread (1個 By Default)來執行 Ping
:::
-------------------------------------------------------------------
### Discovery By Specifics IP
1. 進入主畫面右上角齒輪件

:::spoiler
有些較舊版本的 會是要點擊 Admin -> Configure OpenNMS
:::
2. 選擇 Provisioning 裡面的 Configure Discovery
3. 選擇 Specific Addresses

4. 依照項目依序填寫出需要監控的 IP -> Add
5. 新增完畢後可以看到在 Include Ranges 多了需要監控的 IP 範圍
下一步直接點擊 "Save and Restart Discovery"
-------------------------------------------------------------------
### Discovery By IP Range
1. 進入主畫面右上角齒輪件

:::spoiler
有些較舊版本的 會是要點擊 Admin -> Configure OpenNMS
:::
2. 選擇 Provisioning 裡面的 Configure Discovery

3. 選擇 Include Ranges -> Add New

4. 依照項目依序填寫出需要監控的 IP 範圍 -> Add

:::warning
所填寫之 IP 範圍皆需要是 OpenNMS Server 可以 Ping 得到的
:::
5. 新增完畢後可以看到在 Include Ranges 多了需要監控的 IP 範圍
下一步直接點擊 "Save and Restart Discovery"

-------------------------------------------------------------------
### Discovery By TXT (大量部署)
1. 進入主畫面右上角齒輪件

:::spoiler
有些較舊版本的 會是要點擊 Admin -> Configure OpenNMS
:::
2. 選擇 Provisioning 裡面的 Configure Discovery

3. 選擇 Include URLs
4. 將 IP 的檔案位置填寫至項目中

-------------------------------------------------------------------
### Discovery Exclude Ranges
1. 進入主畫面右上角齒輪件

:::spoiler
有些較舊版本的 會是要點擊 Admin -> Configure OpenNMS
:::
2. 選擇 Provisioning 裡面的 Configure Discovery

3. 選擇 Exclude Ranges
4. 將 IP 範圍依照項目輸入進去即可
-------------------------------------------------------------------
### Discovery Configure
:::info
Configure 設定檔底層路徑為
/[OpenNMSPath]/opennms/etc/discovery-configuration.xml
:::
Example:
```xml=1
<discovery-configuration xmlns="http://xmlns.opennms.org/xsd/config/discovery" location="Default" packets-per-second="1.0" initial-sleep-time="30000" restart-sleep-time="86400000">
<!--設定 Specifics IP -->
<specific retries="1" timeout="2000">8.8.8.8</specific>
<!-- 設定 Include Ranges -->
<include-range retries="1" timeout="2000">
<begin xmlns="">192.168.0.1</begin>
<end xmlns="">192.168.0.254</end>
</include-range>
<!-- 這裡設定 Exclude Ranges -->
<exclude-range>
<begin xmlns="">192.168.0.5</begin>
<end xmlns="">192.168.0.26</end>
</exclude-range>
</discovery-configuration>
```
Attributes 介紹:
**1. packets-per-second**
:::info
設置 OpenNMS 透過 ICMP 每秒產生的風包數量(Ping 幾次的意思)
:::spoiler
This is the number of ICMP packets that will be generated each second. The default is 1. Note that there is a relationship between the packets-per-second and the number of threads. If your network has an average latency of 500ms, then setting packets-per-second to 2 would double the speed at which NewSuspect messages were created. But if there is only one thread available, setting this number to 3 would have little effect - the single thread would be processing as many packets as it could as fast as it could.
::::::
**2. timeout**
:::info
設定 Ping 的回應 Timeout 時間(ms)
:::spoiler
this is the amount of time, in milliseconds, that the discovery process will wait for a response from a given IP address before deciding that there is nothing there. This can be overridden later in the file.
:::
**3. retries**
:::info
若發生 Timeout 的狀況 OpenNMS 會進行 Retry ,若Retry 的次數超過設定則認定IP 不存在
:::spoiler
this is the number of attempts that will be made to query a given IP address before deciding that there is nothing there. This can be overridden later in the file.
:::
**4. threads**
:::info
Discovery 功能是透過 OpenNMS 底層啟動 預設一個 Thread 來進行 可以調整 thread 的數量來加速監控
:::spoiler
This is the number of threads that will be used for discovery. By default this is set to 1.
:::
**5. restart-sleep-time**
:::info
重新執行 Discovery 功能的時間間隔
:::spoiler
Once the discovery process has completed, this is the time, in milliseconds, before it will start again. By default, the process will repeat 24 hours after the last discovery run has completed.
:::
**6. initial-sleep-time**
:::info
類似 Delay 開始的功能 設定好之後經過多久在開始執行 Discovery
:::spoiler
This is the time, in milliseconds, before the discovery process will commence after OpenNMS is started (by default 5 minutes). This delay is put in place to allow the product to fully start before generating new events.
:::
-------------------------------------------------------------------
### Discovery Detail
:::info
OpenNMS 透過 Auto Discovery 自動找到可以監控的主機,及主機上所擁有服務,在設定完後待功能掃描後回到首頁就會看到類似像這樣子的畫面!
[](https://i.imgur.com/H7LYBCl.png)
:::
***New Suspect Event***
newSuspect 是一種在 Discovery 功能發現新增 IP 所觸發的一種事件
這個事件會將新的 IP 傳送給 Provisioned 進行掃描新增項目
Auto Discovery 功能是透過 ICMP 的幫是來辨別主機的存在與否,如果今天遭遇到一個無法進行 ICMP 的主機 則可以手動下以下指令來協助自動監控
```shell=
/opt/opennms/bin/send-event.pl --interface <IP> uei.opennms.org/internal/discovery/newSuspect
```
====================================================================