當前位置:首頁 » 編程軟體 » netsnmp編譯

netsnmp編譯

發布時間: 2023-07-07 19:56:04

A. net-snmp是如何收集信息的

在windows下編譯net-snmp其實很簡單,我用的是net-snmp5.2.1.2的版本。只需把源碼下的win32目錄中的幾個庫的工程編譯就行了。但記住,把netsnmp.lib放在最後編譯,要不然編譯結果不一樣,切記,切記。然後再用編譯出來的四個庫文件: netsnmp.lib,netsnmpagent.lib,netsnmphelpers.lib,netsnmpmibs.lib,來編譯netsnmp.dll。注意還要加上wsock32.lib。如果編譯出錯,提示跟VC默認的庫有沖突,按提示在編譯環境中用NODEFAULTLIB:XXX來去掉VC的預設庫文件。

下面介紹一下幾個例子程序,例子源代碼都可以通過net-snmp的幫助超鏈接連到其網站下載

1.編譯例子example-demon;

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <signal.h>

#include "nstAgentSubagentObject.h"

static int keep_running;

RETSIGTYPE
stop_server(int a) {
keep_running = 0;
}

int
main(int argc, char *argv[])

{
int agentx_subagent=0; /* change this if you want to be a SNMP master agent */
/*為了編譯成為主代理,這里設為0*/
int background = 0; /* change this if you want to run in the background */
int syslog = 0; /* change this if you want to use syslog */

/* print log errors to syslog or stderr */
if (syslog)
snmp_enable_calllog();
else
snmp_enable_stderrlog();

/* we're an agentx subagent? */
if (agentx_subagent) {
/* make us a agentx client. */
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
}

/* run in background, if requested */
if (background && netsnmp_daemonize(1, !syslog))
exit(1);

/* initialize tcpip, if necessary */
SOCK_STARTUP;

/* initialize the agent library */
init_agent("example-demon");

/* initialize mib code here */

/* mib code: init_nstAgentSubagentObject from nstAgentSubagentObject.C */
init_nstAgentSubagentObject();

/* initialize vacm/usm access control */
if (!agentx_subagent) {
void init_vacm_vars();/*---------------小修改一下---------------*/
void init_usmUser();
}

/* example-demon will be used to read example-demon.conf files. */
/*這里會讀取一個為example-demon.conf 的配置文件--關鍵*/
init_snmp("example-demon");

/* If we're going to be a snmp master agent, initial the ports */
if (!agentx_subagent)
init_master_agent(); /* open the port to listen on (defaults to udp:161) */

/* In case we recevie a request to stop (kill -TERM or kill -INT) */
keep_running = 1;
signal(SIGTERM, stop_server);
signal(SIGINT, stop_server);

snmp_log(LOG_INFO,"example-demon is up and running.\n");

/* your main loop here... */
while(keep_running) {
/* if you use select(), see snmp_select_info() in snmp_api(3) */
/* --- OR --- */
agent_check_and_process(1); /* 0 == don't block */
}

/* at shutdown time */
snmp_shutdown("example-demon");
SOCK_CLEANUP;

return 0;
}

這里都有很詳細的注釋,就不說明了。
在vc的工程中,把所用到的例子mib庫文件nstAgentSubagentObject.h,nstAgentSubagentObject.c添加進去。並設置好所需的四個庫文件,如文開頭所述,看是否需要加wsock32.lib,和NODEFAULTLIB。接著就應該可以編譯通過了,無錯誤無警告。

2.關於運行
運行就必須設置配置文件的路徑,最好下一個NET-SNMP的二進制包,按預設路徑安裝C:\USR。安裝時提示還需要下載一個PERL的安裝包,用來運行mib2c工具,這個網上都有介紹。配置文件放在
c:\,c:\usr\etc\snmp或C:\usr\share\snmp都有效。但如果你是運行例子主代理程序,會在etc目錄下找配置文件。例子的配置文件應和init_snmp("example-demon");中初始化的名字相同:example-demon.conf。配置文件只需設兩個值就夠了:

#community 的讀寫根據需要設,這里設的是readonly
rocommunity public
agentaddress 161

另外,如果是運行二進制包,snmp.conf文件不要手工修改,要通過snmpconf生成,手工修改的好像不起作用。例子程序的配置可以手工設置。
最後,把example-demon.conf放到c:\usr\etc\snmp下。關掉二進制包的snmpd.exe服務(如果在運行的話)。然後運行example-demon.exe。正常情況下,如果安裝了二進制包,例子可以在編譯目錄下運行,不行就把netsnmp.dll拷進來,或直接把例子放到二進制包的bin目錄下。有問題檢查配置文件的路徑和設置。最好下載一個叫getif的管理端軟體,很方便小巧的查詢工具,來側試。

3.編譯自己的mib庫
第一種可以通過mib2c生成模版框架,在相關地方添上數據導入指針及其他。
第二種可以參考nstAgentSubagentObject.c。
第三種可以參考net-snmp-xxx\agent\mibgroup\examples下的幾個實現方式。

總結
主要是環境設置,庫的編譯順序,配置文件設置。參考例子基本沒多大問題。

B. linux下簡單配置安裝cactisnmp再次安裝怎麼解決

以前確認過機器上安裝了snmp,但是這是redhat自帶的,據說裡面是沒有snmpwalk,snmpget這些命令的,所以我這里要重新
編譯安裝NET-SNMP
官方網站
http://www.net-snmp.org/
下載文件
wget http://nchc.dl.sourceforge.net/project/net-snmp/net-snmp/5.5/net-snmp-5.5.tar.gz
解開壓縮
tar zxvf net-snmp-5.5.tar.gz
配置
./configure --prefix=/usr/local/net-snmp --enable-developer
中間有提示,一路回車下去
make
報錯如下:
grep: /usr/lib/libbeecrypt.la: No such file or directory
/bin/sed: can't read /usr/lib/libbeecrypt.la: No such file or directory
libtool: link: `/usr/lib/libbeecrypt.la' is not a valid libtool archive
make[1]: *** [libnetsnmpmibs.la] 錯誤 1
make[1]: Leaving directory `/var/tmp/net-snmp-5.5/agent'
make: *** [subdirs] 錯誤 1
解決辦法:
安裝beecrypt
wget http://nchc.dl.sourceforge.net/sourceforge/beecrypt/beecrypt-4.1.2.tar.gz
tar zxvf beecrypt-4.1.2.tar.gz
./configure --prefix=/usr
make
make install

重新make,又報錯了,報錯如下:
/usr/bin/ld: cannot find -lelf
collect2: ld returned 1 exit status
make[1]: *** [libnetsnmpmibs.la] 錯誤 1
make[1]: Leaving directory `/var/tmp/net-snmp-5.5/agent'
make: *** [subdirs] 錯誤 1
解決辦法:
ln -s libelf.so.1 /usr/lib/libelf.so

繼續make,成功了:)
make install
安裝成功。

鏈接過去
ln -s /usr/local/net-snmp/bin/* /usr/local/bin/

cp EXAMPLE.conf /usr/local/net-snmp/share/snmp/snmpd.conf

/usr/local/net-snmp/sbin/snmpd //啟動SNMP服務

vi /etc/rc.d/rc.local
//在rc.local上加入一行/usr/local/net-snmp/sbin/snmpd,系統啟動時啟動SNMP服務

現在再回頭看看cacti的錯誤
錯誤:/usr/local/bin/snmpwalk
錯誤:/usr/local/bin/snmpget
錯誤:/usr/local/bin/snmpbulkwalk
錯誤:/usr/local/bin/snmpgetnext
再次點開,這次就沒有以上的錯誤啦。點Finish
輸入用戶名和密碼admin/admin

登陸後點擊graph圖標,圖沒有出來。繼續查找下原因,快要成功了:)
查看後台日誌cacti裡面的log/cacti.log,日誌如下:
POLLER: Poller[0] Maximum runtime of 298 seconds exceeded. Exiting

點擊控制面板console----->Data Sources
選擇列表中的一個Localhost-Load Average
點擊右上角的Turn Off Data Source Debug Mode
下面會出現對應的命令Data Source Debug
/usr/local/bin/rrdtool create \
/usr/local/apache2/htdocs/cacti/rra/localhost_load_1min_5.rrd \
--step 300 \
DS:load_1min:GAUGE:600:0:500 \
DS:load_5min:GAUGE:600:0:500 \
DS:load_15min:GAUGE:600:0:500 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797 \

su cacti,執行該命令,報錯如下:
ERROR: creating '/usr/local/apache2/htdocs/cacti/rra/localhost_load_1min_5.rrd': 許可權不夠
暈,前面不是賦予了許可權了嘛,難道搞錯了。再賦予一次。
chown -R cacti rra
chown -R cacti log
執行命令,OK了,檢查一下目錄rra,哈哈,已經有一個文件了。去看看圖看。圖有了,但是是否有正確的每5分鍾採集一次
就要等等,等好幾個5分鍾再來看看了。等了一會兒,還是沒有數據,唉,好事多磨啊,有圖像了,又沒有數據。。。。
檢查snmp
snmpwalk -c public -v 2c 10.206.19.59 if 有很多信息返回
檢查數據
rrdtool fetch localhost_mem_swap_4.rrd AVERAGE,返回的都是
1261452300: nan
1261452600: nan
文件更新信息
rrdtool lastupdate localhost_mem_swap_4.rrd --template,返回數據
users
1261535656: U
文件信息
rrdtool info localhost_users_6.rrd,返回信息:
filename = "localhost_users_6.rrd"
rrd_version = "0003"
step = 300
last_update = 1261535656
ds[users].type = "GAUGE"
ds[users].minimal_heartbeat = 600
ds[users].min = 0.0000000000e+00
ds[users].max = 5.0000000000e+02
ds[users].last_ds = "U"
ds[users].value = 0.0000000000e+00

網上搜索資料,可能是SNMP沒有配置好
vi /usr/local/net-snmp/share/snmp/snmpd.conf
cp /etc/snmp/snmpd.conf /usr/local/net-snmp/share/snmp/snmpd.conf
重啟snmp
/usr/local/net-snmp/sbin/snmpd

修改定時任務
[root@dev1 snmp]# crontab -e -u cacti
*/5 * * * * /usr/local/bin/php -q /usr/local/apache2/htdocs/cacti/poller.php > /var/log/poller.log 2>&1

檢查定時任務是否啟動了
/etc/init.d/crond status

一切正常

檢查log/cacti.log日誌
12/23/2009 01:14:16 PM - POLLER: Poller[0] WARNING: Cron is out of sync with the Poller Interval! The Poller Interval is '300' seconds, with a maximum of a '300' second Cron, but 4754 seconds have passed since the last poll!
12/23/2009 01:20:01 PM - POLLER: Poller[0] WARNING: Cron is out of sync with the Poller Interval! The Poller Interval is '300' seconds, with a maximum of a '300' second Cron, but 345 seconds have passed since the last poll!
12/23/2009 01:25:00 PM - POLLER: Poller[0] Maximum runtime of 298 seconds exceeded. Exiting.
12/23/2009 01:25:00 PM - SYSTEM STATS: Time:298.7072 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:0
12/23/2009 01:30:00 PM - POLLER: Poller[0] Maximum runtime of 298 seconds exceeded. Exiting.

手工執行了幾次
php cacti/cmd.php
php cacti/poller.php

PHP Deprecated錯誤的解決
vi /usr/local/lib/php.ini
加入:
php_flag allow_call_time_pass_reference On
php_value error_reporting "E_ALL & ~E_NOTICE & ~E_DEPRECATED"

終於有數據了,發現好像是執行了php cacti/cmd.php,但是最後還是有些問題

C. net-snmp代理(snmpd)擴展開發:

其實get和set對應的調用函數已經掛載好了,只需要修改對應的函數實現,就可以達到你需要的結果。不過需要在configure文件中添加--with-mib-moles="XXXX"這樣的語句,並且重新configure一遍,才能將新添加的模塊編譯進去。你問的比較寬泛,我回答的可能也不是很清楚,可以追問。

D. 如何用net snmp開發snmp客戶端

Linux下net-snmp的安裝提供的net-snmp安裝包中有以下目錄運行install腳本執行安裝,但不建立用戶運行install_cm腳本執行安裝並建立cm用戶運行install_vg腳本執行安裝並建立vg用戶用戶也可以用命令:net-snmp-config --create-snmpv3-user -a MD5 -A $snmp_auth -x DES -X $snmp_priv $snmp_usr$snmp_auth 是認證密碼,密碼必須大於8位$snmp_priv是加密密碼,密碼必須大於8位$snmp_usr是將要建立的用戶名 安裝完以後自動啟動可以運行 tools/目錄下的snmpwalk命令來檢查是否安裝成功./snmpwalk -v 3 -l authPriv -u cm -aMD5 -A password -xDES -X password 127.0.0.1 Windows下snmp協議的安裝(windows2003,windows xp)控制面板-》添加刪除程序-》添加組件-》管理和監視工具點詳細信息,勾選「簡單網路管理協議」安裝過程中會提示插入系統盤安裝完成後,選擇管理工具-》服務在右邊的列表中選中「SNMP service」, 右鍵-》屬性裡面有一個安全頁面,可以自己添加一個團體,也可以用默認的「public」團體。下面選擇「接受任意主機的snmp數據包」,或者選擇「接受指定主機的snmp數據包」,填入主機的ip地址或主機名。

E. 新人求助windows下netsnmp怎麼連接python

由於需要練手,准備將nagios的bash shell/perl監控腳本改用python寫,而監控機上yum安裝的net-snmp默認沒有啟用python模塊,這里重新編譯安裝一個。

需要准備的安裝包包括:

setuptools-0.6c11-py2.4.egg //提供easy_install指令用來直接在線安裝python模塊,類似於perl的 cpan install;

net-snmp-5.7.2.tar.gz //net-snmp的源碼包。

先安裝setuptools-0.6c11-py2.4.egg,否則net-snmp編譯安裝無法通過。

#chmod 755 setuptools-0.6c11-py2.4.egg

#./setuptools-0.6c11-py2.4.egg

接著,安裝net-snmp

#tar -zxvf net-snmp-5.7.2.tar.gz

#cd net-snmp-5.7.2

#./configure --prefix=/usr/local/netsnmp --with-python-moles

#make

#make install

#cd python

#python setup.py build

#python setup.py test

出現以下錯誤:

ImportError: libnetsnmp.so.30: cannot open shared object file: No such file or directory

由於net-snmp是編譯安裝,且安裝路徑為/usr/local/netsnmp,以至於找不到相應模塊,解決方法:

#echo "/usr/local/netsnmp/lib" >> /etc/ld.so.conf

#ldconfig

#python setup.py test//出現類似下圖內容即正常:

#python setup.py install

測試net-snmp的python模塊的導入:

#python

>>>import netsnmp //如果沒有報錯的話,則net-snmp的python模塊啟用成功。

F. linux 下的snmp++的安裝

1.下載net-snmp -5.3.pre4.tar.gz包.
編譯,安裝
[[email protected] net-snmp -5.2.1]# ./configure –prefix=/usr/local/net-snmp -5.2.1
[[email protected] net-snmp -5.2.1]#make
[[email protected] net-snmp -5.2.1]#make install
2.創建放配置 文件的目錄
[[email protected] net-snmp -5.2.1]# mkdir /etc/snmp
3.拷貝配置 文件
解壓出來的包中的EXAMPLE.conf拷貝到剛創建的目/etc/snmp 中,並命名為snmpd.conf
[[email protected] net-snmp -5.2.1]# cp -R EXAMPLE.conf /etc/snmp /snmpd.conf
4.修改配置 文件
[[email protected] net-snmp -5.2.1]# vi /etc/snmp /snmpd.conf
找到如下行,將其改為你想要的字元串,和網路

# sec.name source community
com2sec local localhost COMMUNITY
com2sec mynetwork NETWORK/24 COMMUNITY
例如
com2sec local localhost COMMUNITY
com2sec mynetwork 192.168.1.0/24 abcpublic
注意要用192.168.1.0/24 MS不能用192.168.1.1/24.另外改後要重啟snmp 才能生效.

5.開啟snmp
[[email protected] net-snmp -5.2.1]# /usr/local/net-snmp -5.2.1/sbin/snmpd -Lsd -Lf /dev/null -p /var/run/snmpd -a -c /etc/snmp /snmpd.conf

6.重啟.
[[email protected] net-snmp -5.2.1]# killall -9 snmpd
[email protected] net-snmp -5.2.1]# /usr/local/net-snmp -5.2.1/sbin/snmpd -Lsd -Lf /dev/null -p /var/run/snmpd -a -c /etc/snmp /snmpd.conf
這樣下來應該行了,
大概的思路吧

G. uclinux下net-snmp編譯完成後程序在目標板(uclinux+arm)上運行時提示Cannot find mole (SNMPv2-MIB):

你的庫文件或模塊代碼有缺失。重新下載個snmpagent開發包吧。

熱點內容
愛思助手如何看配置 發布:2025-02-07 17:32:27 瀏覽:175
自己的電腦怎麼搭建手游伺服器端 發布:2025-02-07 17:21:44 瀏覽:47
怎樣修改蘋果密碼怎麼辦 發布:2025-02-07 17:15:44 瀏覽:716
電腦一般怎麼連接伺服器 發布:2025-02-07 17:12:55 瀏覽:491
ftp用ie打開文件 發布:2025-02-07 17:07:42 瀏覽:271
android列表顯示 發布:2025-02-07 17:01:19 瀏覽:66
芒果tv緩存的視頻在哪個文件里 發布:2025-02-07 16:45:05 瀏覽:817
php郵件群發 發布:2025-02-07 16:45:05 瀏覽:615
mysql資料庫基本語句 發布:2025-02-07 16:41:48 瀏覽:253
醫院門禁密碼多少 發布:2025-02-07 16:41:43 瀏覽:530