2024年9月25日 星期三

Proxmox VE8 啟用 SNMP

 apt install libpve-apiclient-perl 

cat >/etc/snmp/cat_serial <<EOF
#!/bin/bash
/bin/cat /sys/devices/virtual/dmi/id/product_serial
EOF

wget https://raw.githubusercontent.com/librenms/librenms-agent/master/agent-local/proxmox -O /etc/snmp/proxmox

wget -O /etc/snmp/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
chmod +x /etc/snmp/distro

chmod a+x /etc/snmp/proxmox /etc/snmp/cat_serial

編輯 /etc/snmp/snmpd.conf
mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.$(date +%Y%m%d-%H%M%S)

cat >/etc/snmp/snmpd.conf <<EOF
# Change RANDOMSTRINGGOESHERE to your preferred SNMP community string
com2sec readonly  default         RANDOMSTRINGGOESHERE
group MyROGroup v2c        readonly
view all    included  .1                               80
access MyROGroup ""      any       noauth    exact  all    none   none
syslocation ROOM 110
syscontact email <email@mail>

#OS Distribution Detection
#extend distro /usr/bin/distro
#Hardware Detection

# (uncomment for x86 platforms)
extend manufacturer '/bin/cat /sys/devices/virtual/dmi/id/sys_vendor'
extend hardware '/bin/cat /sys/devices/virtual/dmi/id/product_name'
#extend serial '/bin/cat /sys/devices/virtual/dmi/id/product_serial'

# (uncomment for ARM platforms)
#extend hardware '/bin/cat /sys/firmware/devicetree/base/model'
#extend serial '/bin/cat /sys/firmware/devicetree/base/serial-number'

extend distro /etc/snmp/distro
extend proxmox  "/usr/bin/sudo /etc/snmp/proxmox"
extend serial   "/usr/bin/sudo /etc/snmp/cat_serial"
EOF

編輯 /etc/sudoers  加入
Debian-snmp     ALL=(ALL) NOPASSWD: /etc/snmp/proxmox
Debian-snmp     ALL=(ALL) NOPASSWD: /etc/snmp/cat_serial

沒有留言: