Recently we’ve moved from an aged Opsview instance to Zabbix for our system health monitoring, which in turn facilitated moving data collector agents from Nagios to snmp.
Many of our PBX’s were deployed from the vendors ISO and so run atop of Gentoo, and it has a couple of issues:
- We’ve been told not to “emerge” anything by the vendor, as the base OS on the image is not maintained.
- Portage (Gentoo’s package manager) has fallen out of date, meaning even if emerge is attempted, it’ll fail as all repository links are broke.
If faced with the same issue, this is how to install net-snmpd from source, add it a startup service and be able to monitor via snmp…
Installation
On the Gentoo box, move to your home directory
cd ~
Download the source .tar.gz file
wget https://sourceforge.net/projects/net-snmp/files/net-snmp/5.9.4/net-snmp-5.9.4.tar.gz
Visit http://www.net-snmp.org/download.html for the latest version. When I was downloading SourceForge’s SSL cert had expired, if this happens add –no-check-certificate after wget in the command above.
Untar the file to your home directory, and change into it
tar -xzvf net-snmp-5.9.4.tar.gz
cd net-snmp-5.9.4
Run the configuration script
./configure
This allows you to set snmp version, file installation locations and snmp details, with exception of snmp version these can be left as default (Hit enter at the prompt). snmp details will look like this if left default…
Compile and install snmpd
make
make install
The make process is quite CPU intensive, may want to do this during a quiet period for the server.
Some libraries are not where they need to be, namely:
libnetsnmpagent.so.40
libnetsnmpmibs.so.40
libnetsnmp.so.40
Find where they were installed
find / -name libnetsnmpagent.so.40
Pick the result that is not in your current working folder (the install setup) and link it to /usr/lib
ln -s /usr/local/lib64/libnetsnmpagent.so.40 /usr/lib/
Repeat this process with the other two files
ln -s /usr/local/lib64/libnetsnmpmibs.so.40 /usr/lib/
ln -s /usr/local/lib64/libnetsnmp.so.40 /usr/lib/
Now can test to see if snmpd can run
snmpd -v
Configuration
Create a configuration file, the “snmpconf” command can be used but I found it easier to create from scratch
nano /usr/local/share/snmp/snmpd.conf
For my needs, only this line is needed
rocommunity {community} {ip address}
Save and exit the editor.
Testing
If you’d like to test your configuration, run snmpd
snmpd
Test on the snmp target machine, for quick results snmpwalk can be run
snmpwalk -c {community} -v 2c {ip address}
When run, snmpd automatically switches to a background process. To stop the process ID needs to be found and killed
ps aux | grep snmpd
Here the process ID (PID) is 5716, use this with the kill command
kill -9 {PID}
Add Service
Create the new service file
nano /etc/init.d/snmpd
Paste the following
#!/sbin/openrc-run
depend() {
after modules
}
start() {
ebegin "Starting snmpd"
start-stop-daemon --background --start --exec /usr/local/sbin/snmpd --pidfile /var/run/snmpd.pid \
-- -p /var/run/snmpd.pid -c /usr/local/share/snmp/snmpd.conf
eend $?
}
stop() {
ebegin "Stopping snmpd"
start-stop-daemon --stop --exec /usr/local/sbin/snmpd \
--pidfile /var/run/snmpd.pid
eend $?
}
restart() {
ebegin "Restarting snmpd"
start-stop-daemon --stop --exec /usr/local/sbin/snmpd
start-stop-daemon --background --start --exec /usr/local/sbin/snmpd --pidfile /var/run/snmpd.pid \
-- -p /var/run/snmpd.pid -c /usr/local/share/snmp/snmpd.conf
eend $?
}
Save and exit the text editor, then make the file executable
chmod +x /etc/init.d/snmpd
Start the service, and check its running
/etc/init.d/snmpd start
/etc/init.d/snmpd status
Finally, to make snmpd start with the system, run
rc-update add snmpd default
References
Help Creating init.d file
https://big-elephants.com/2013-01/writing-your-own-init-scripts/
https://tecadmin.net/startup-shutdown-script-on-gentoo/
Experienced issue where the process-id in the PID file was not matching the PID of process. With help of below found flag for snmpd to specify PID file, and match that to init.d