bsnmp & check_mk_agent

前言

Librenms需要SNMP才能監控,另外也可以使用check_mk_agent來輔助

參考資料

柯仓无居所

bsnmp

FreeBSD有內建的bsnmp

  1. vi /etc/rc.conf
1
2
3
# /etc/rc.conf
--------------------------------------------------------------------------------------------------------------------------------
bsnmpd_enable="YES"
  1. pkg install bsnmp-ucd
  2. vi /etc/snmpd.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# /etc/snmpd.conf 加上以下內容
--------------------------------------------------------------------------------------------------------------------------------
begemotSnmpdModulePath."ucd" = "/usr/local/lib/snmp_ucd.so"
%ucd
updateInterval = 500
extCheckInterval = 100
extUpdateInterval = 3000
extTimeout = 60

memMinimumSwap = 1600
memSwapErrorMsg = "No free swap!"

laConfig.1 = "6.0"
laConfig.2 = "5.0"
laConfig.3 = "4.0"

laErrMessage.1 = "1min load average is high!"
laErrMessage.2 = "5min load average is high!"
laErrMessage.3 = "15min load average is high!"

# Process table

prNames.0 = "httpd"
prMin.0 = 3
prMax.0 = 100

prErrFix.0 = 1
prErrFixCmd.0 = "/usr/local/etc/rc.d/apache22 restart"

# Extension commands (extTable)

extNames.0 = "uname"
extCommand.0 = "/usr/bin/uname -a"

extNames.1 = "uptime"
extCommand.1 = "/usr/bin/uptime"

# example of extension with fix command
extNames.2 = "apache"
extCommand.2 = "/usr/local/etc/rc.d/apache status"
extErrFix.2 = 1
extErrFixCmd.2 = "/usr/local/etc/rc.d/apache restart"
  1. /etc/rc.d/bsnmpd restart
  2. bsnmpwalk -v 2c -c public

確認有取得資料就是OK了

check_mk_agent

pre-install needed

1
pkg install bash ipmitool libstatgrab git

因為check_mk_agent需要用bash跑,沒有bash是不會動的

Install and setup

  1. 取得check_mk_agent & 賦予執行權限
1
2
3
git clone https://github.com/librenms/librenms-agent.git
cp librenms-agent/check_mk_agent_freebsd /usr/local/bin/check_mk_agent
chmod +x /usr/local/bin/check_mk_agent

上述的方法過時了…因為現在port裡面就有支援

/usr/ports/net-mgmt/check_mk_agent/

1
2
cd /usr/ports/net-mgmt/check_mk_agent/
make install clean
  1. vi /etc/services
1
2
3
# /etc/services
--------------------------------------------------------------------------------------------------------------------------------
check_mk 6556/tcp #check_mk agent

這個是加進去的

  1. vi /etc/inetd.conf
1
2
3
#/etc/inetd.conf
--------------------------------------------------------------------------------------------------------------------------------
check_mk stream tcp nowait root /usr/local/bin/check_mk_agent check_mk_agent

這個也是加進去的

  1. vi /etc/rc.conf
1
2
3
4
#/etc/rc.conf
--------------------------------------------------------------------------------------------------------------------------------
inetd_enable=yes
inetd_flags=-wW

這個也是加進去的

  1. vi /etc/hosts.allow
1
2
3
4
5
#/etc/hosts.allow
--------------------------------------------------------------------------------------------------------------------------------
# Allow nagios server to access us
check_mk_agent : 192.168.56.3 : allow
check_mk_agent : ALL : deny

這個也是加進去

  1. /etc/rc.d/inetd start

  2. telnet確認一下

1
2
3
4
telnet bsdhost 6556
<<<check_mk>>>
Version: 1.1.13i1
AgentOS: freebsd

這樣就好了

結論

雖然我不是很喜歡開inetd來跑,不過這些機器跟port基本上都用FW限制死了連線,加上librenms架在裡面,所以問題應該沒有那麼大

勉強還是可以這樣用的