The first part: Install snmp program and service.
There are two ways to install snmp support in Ubuntu. The first is to install it directly through apt-get. The second is to download the source code net-snmp-5.7.3.tar.gz from the netsnmp official website, and compile and install it.
Regarding the second method, I have checked the methods on the Internet. Unfortunately, I have not succeeded in the end, so I recommend the first method here.
The first step is to install snmpd, snmp, and snmp-mibs-downloader
The following is the installation command:
~$sudo apt-get install snmp
~$sudo apt-get install snmpd
~$sudo apt-get install snmp-mibs-download
The second step is to start the snmpd service
~$sudo service snmpd restart
Finally, test whether the following is successful
~$snmpwalk -v 2c -c public localhost
If the data is returned correctly, it means that the installed snmp can be used normally.
The second part: install the python programming package corresponding to netsnmp.
Here is mainly to install netsnmp-py, https://pypi.org/project/netsnmp-py/.
First, install the corresponding dependent libraries.
~$sudo apt-get install libsnmp30 libsnmp-dev libczmq-dev
Second, install pyzmq, pyczmq. http://pyzmq.readthedocs.io/en/latest/index.html
~$sudo pip install pyczmq
Next, install netsnmp-py and you are done.
~$sudo pip install netsnmp-py
Finally, it is to test whether the netsnmp-py function is available in python in the program.
For details, please refer to: sample in usr/local/lib/python3.6/dist-packages/netsnmp/init.py.
example:
~$python
Python 3.6.5 (default, Apr 1 2018, 05:46:30) [GCC 7.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import netsnmp >>> with netsnmp.SNMPSession('localhost', 'public') as ss: ... ss.get(['.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.3.0']) ... [('.1.3.6.1.2.1.1.1.0', 'STRING', '"Linux laosierLinux 4.15.0-22-generic #24-Ubuntu SMP Wed May 16 12:15:17 UTC 2018 x86_64"'), ('.1.3.6.1.2.1.1.3.0', 'Timeticks', '0:3:13:31.57')] >>>
If the above information is returned, haha, I wish you success.
Recommended Posts