snmpd装载一个动态链接库(so文件),以扩充MIB
来源:互联网 发布:java行业薪资 编辑:程序博客网 时间:2024/05/23 01:24
一、概述
1、agent端
2、管理端
n
二、逻辑图
三、扩充MIB流程
1、下载最新的net-snmp源码并tar
[root@localhost Desktop]# tar zxvf net-snmp-5.5.tar.gz
2、配置
[root@localhost net-snmp-5.5]# ./configure --with-mib-modules="ucd_snmp $OTHER_MIBS" $OTHER_OPTIONS
2、配置
3、编译snmpd及工具
4、安装snmpd及工具
5、编译so
6、在snmpd.conf中最后增加一行 :
7、然后重新启动 snmpd
8、测试一下:
9、支持V3 的测试
snmp的版本有 v1, v2c, v3。其中v3版本对包采取了加密、验证的方式,安全性更高。
在配置文件snmpd.conf中增加以下一段
view demoWrite included .1.3.6.1.4.1.8072.2.4.1.1.3
view demoRead included .1.3.6.1.4.1.8072.2.4.1.1.3
access demogroup "" any auth prefix demoRead demoWrite none
group demogroup usm MD5DESUser
createUser MD5DESUser MD5 "The Net-SNMP Demo password" DES "The Net-SNMP Demo password"
重新启动snmpd, 就可以测试了,以下是测试过程。
四、自制管理端工具
1、自己写测试工具【代替snmpget等工具】
通过调用 net-snmp提供的api, 按照SNMP包的格式,自行组装一个SNMP包,发给agent, 然后解析agent返回的应答包。将某个OID的值显示出来。
具体步骤如下:
1)、编译程序【生成 snmpdemoapp可执行程序(工具)】
[root@localhost net-snmp-5.5]# make -f Makefile_snmpdemoapp
两个源文件 Makefile_snmpdemoapp 和 snmpdemoapp.c 参见后面
2)、测试
[root@localhost net-snmp-5.5]# snmpget -v 3 -n "" -u MD5DESUser -a MD5 -A "The Net-SNMP Demo password" -x DES -X "The Net-SNMP Demo password" -l authPriv localhost .1.3.6.1.4.1.8072.2.4.1.1.3.0
NET-SNMP-EXAMPLES-MIB::netSnmpExamples.4.1.1.3.0 = INTEGER: 3
1、nstAgentPluginObject.h
#ifndef NSTAGENTPLUGINOBJECT_H
#define NSTAGENTPLUGINOBJECT_H
void
#endif
2、nstAgentPluginObject.c
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "nstAgentPluginObject.h"
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "nstAgentPluginObject.h"
static int nstAgentPluginObject = 3;
static oid nstAgentPluginObject_oid[] =
{ 1, 3, 6, 1, 4, 1, 8072, 2, 4, 1, 1, 3, 0 };
static oid
void
init_nstAgentPluginObject(void)
{
}
void
deinit_nstAgentPluginObject(void)
{
unregister_mib(nstAgentPluginObject_oid,OID_LENGTH(nstAgentPluginObject_oid));
}
deinit_nstAgentPluginObject(void)
{
}
3、Makefile_so
#
# Warning: you may need more libraries than are included here on the
# build line. The agent frequently needs various libraries in order
# to compile pieces of it, but is OS dependent and we can't list all
# the combinations here. Instead, look at the libraries that were
# used when linking the snmpd master agent and copy those to this
# file.
#
# Warning: you may need more libraries than are included here on the
# build line.
# to compile pieces of it, but is OS dependent and we can't list all
# the combinations here.
# used when linking the snmpd master agent and copy those to this
# file.
#
CC=gcc
OBJS1=snmpdemoapp.o
OBJS2=example-demon.o nstAgentSubagentObject.o
OBJS3=asyncapp.o
TARGETS=nstAgentPluginObject.so
OBJS2=example-demon.o nstAgentSubagentObject.o
OBJS3=asyncapp.o
TARGETS=nstAgentPluginObject.so
CFLAGS=-I. `net-snmp-config --cflags`
BUILDLIBS=`net-snmp-config --libs`
BUILDAGENTLIBS=`net-snmp-config --agent-libs`
BUILDLIBS=`net-snmp-config --libs`
BUILDAGENTLIBS=`net-snmp-config --agent-libs`
# shared library flags (assumes gcc)
DLFLAGS=-fPIC -shared
DLFLAGS=-fPIC -shared
all: $(TARGETS)
clean:
nstAgentPluginObject.so: nstAgentPluginObject.c Makefile
$(CC) $(CFLAGS) $(DLFLAGS) -c -o nstAgentPluginObject.o nstAgentPluginObject.c
$(CC) $(CFLAGS) $(DLFLAGS) -o nstAgentPluginObject.so nstAgentPluginObject.o
4、snmpdemoapp.c
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <string.h>
#include <net-snmp/net-snmp-includes.h>
#include <string.h>
#define DEMO_USE_SNMP_VERSION_3
#ifdef DEMO_USE_SNMP_VERSION_3
const char *our_v3_passphrase = "The Net-SNMP Demo Password";
#endif
const char *our_v3_passphrase = "The Net-SNMP Demo Password";
#endif
char
//const char*
int main(int argc, char ** argv)
{
if(argc==2)
strcpy(local_oid, argv[1]);
//
netsnmp_session session, *ss;
netsnmp_pdu *pdu;
netsnmp_pdu *response;
{
#ifdef DEMO_USE_SNMP_VERSION_3
#else
#endif
#if OTHER_METHODS
#endif
}
5、Makefile_snmpdemoapp
#
# Warning: you may need more libraries than are included here on the
# build line. The agent frequently needs various libraries in order
# to compile pieces of it, but is OS dependent and we can't list all
# the combinations here. Instead, look at the libraries that were
# used when linking the snmpd master agent and copy those to this
# file.
#
# Warning: you may need more libraries than are included here on the
# build line.
# to compile pieces of it, but is OS dependent and we can't list all
# the combinations here.
# used when linking the snmpd master agent and copy those to this
# file.
#
CC=gcc
OBJS1=snmpdemoapp.o
TARGETS=snmpdemoapp
TARGETS=snmpdemoapp
CFLAGS=-I. `net-snmp-config --cflags`
BUILDLIBS=`net-snmp-config --libs`
BUILDAGENTLIBS=`net-snmp-config --agent-libs`
BUILDLIBS=`net-snmp-config --libs`
BUILDAGENTLIBS=`net-snmp-config --agent-libs`
# shared library flags (assumes gcc)
DLFLAGS=-fPIC -shared
DLFLAGS=-fPIC -shared
all: $(TARGETS)
snmpdemoapp: $(OBJS1)
$(CC) -o snmpdemoapp $(OBJS1) $(BUILDLIBS)
clean:
6、snmpd.conf
###########################################################################
#
# snmpd.conf
#
# - created by the snmpconf configuration program
#
###########################################################################
# SECTION: Monitor Various Aspects of the Running Host
#
# The following check up on various aspects of a host.
#
# snmpd.conf
#
#
#
###########################################################################
# SECTION: Monitor Various Aspects of the Running Host
#
#
# proc: Check for processes that should be running.
# proc NAME [MAX=0] [MIN=0]
#
# NAME: the name of the process to check for. It must match
# exactly (ie, http will not find httpd processes).
# MAX: the maximum number allowed to be running. Defaults to 0.
# MIN: the minimum number to be running. Defaults to 0.
#
# The results are reported in the prTable section of the UCD-SNMP-MIB tree
# Special Case: When the min and max numbers are both 0, it assumes
# you want a max of infinity and a min of 1.
#
#
#
#
#
#
#
#
#
#
proc "1 0"
proc aaa_process 2
proc
# disk: Check for disk space usage of a partition.
# The agent can check the amount of available disk space, and make
# sure it is above a set limit.
#
# disk PATH [MIN=100000]
#
# PATH: mount path to the disk in question.
# MIN: Disks with space below this value will have the Mib's errorFlag set.
# Can be a raw integer value (units of kB) or a percentage followed by the %
# symbol. Default value = 100000.
#
# The results are reported in the dskTable section of the UCD-SNMP-MIB tree
#
#
#
#
#
#
#
#
#
#
#
disk
disk sda1 10
disk
# load: Check for unreasonable load average values.
# Watch the load average levels on the machine.
#
# load [1MAX=12.0] [5MAX=12.0] [15MAX=12.0]
#
# 1MAX: If the 1 minute load average is above this limit at query
# time, the errorFlag will be set.
# 5MAX: Similar, but for 5 min average.
# 15MAX: Similar, but for 15 min average.
#
# The results are reported in the laTable section of the UCD-SNMP-MIB tree
#
#
#
#
#
#
#
#
#
#
load 12.0 60 180
load 12 60 180
load
###########################################################################
# SECTION: System Information Setup
#
# This section defines some of the information reported in
# the "system" mib group in the mibII tree.
# SECTION: System Information Setup
#
#
#
# syslocation: The [typically physical] location of the system.
# Note that setting this value here means that when trying to
# perform an snmp SET operation to the sysLocation.0 variable will make
# the agent return the "notWritable" error code. IE, including
# this token in the snmpd.conf file will disable write access to
# the variable.
# arguments: location_string
#
#
#
#
#
#
syslocation aa
syslocation
syslocation
# syscontact: The contact information for the administrator
# Note that setting this value here means that when trying to
# perform an snmp SET operation to the sysContact.0 variable will make
# the agent return the "notWritable" error code. IE, including
# this token in the snmpd.conf file will disable write access to
# the variable.
# arguments: contact_string
#
#
#
#
#
#
syscontact bb
syscontact
syscontact
# sysservices: The proper value for the sysServices object.
# arguments: sysservices_number
#
sysservices 79
###########################################################################
# SECTION: Extending the Agent
#
#
#
# dlmod: dynamically extend the agent using a shared-object
# arguments: module-name module-path
#
dlmod nstAgentPluginObject /root/Desktop/net-snmp-5.5/nstAgentPluginObject.so
###########################################################################
# SECTION: Access Control Setup
#
# This section defines who is allowed to talk to your running
# snmp agent.
# SECTION: Access Control Setup
#
#
#
# rwuser: a SNMPv3 read-write user
# arguments: user [noauth|auth|priv] [restriction_oid]
#
rwuser root
# rouser: a SNMPv3 read-only user
#
rouser tduan
# rocommunity: a SNMPv1/SNMPv2c read-only access community name
# arguments: community [default|hostname|network/bits] [oid]
#
rocommunity opublic
# rwcommunity: a SNMPv1/SNMPv2c read-write access community name
# arguments: community [default|hostname|network/bits] [oid]
#
rwcommunity public
rwcommunity public_semi
rwcommunity
###########################################################################
# SECTION: Trap Destinations
#
# Here we define who the agent will send traps to.
# SECTION: Trap Destinations
#
#
# trapsink: A SNMPv1 trap receiver
# arguments: host [community] [portnum]
#
trapsink
# trap2sink: A SNMPv2c trap receiver
# arguments: host [community] [portnum]
#
trap2sink
# informsink: A SNMPv2c inform (acknowledged trap) receiver
# arguments: host [community] [portnum]
#
informsink
# trapcommunity: Default trap sink community to use
# arguments: community-string
#
trapcommunity
# authtrapenable: Should we send traps when authentication failures occur
# arguments: 1 | 2 (1 = yes, 2 = no)
#
authtrapenable 1
view demoWrite included .1.3.6.1.4.1.2021.14.1.1
view demoWrite included .1.3.6.1.4.1.8072.2.4.1.1.3
view demoWrite included .1.3.6.1.4.1.8072.2.4.1.1.3
view demoRead included .1.3.6.1.4.1.2021.14.1.1
view demoRead included .1.3.6.1.2.1.1
view demoRead included .1.3.6.1.4.1.8072
view demoRead
view demoRead
access demogroup "" any auth prefix demoRead demoWrite none
group demogroup usm MD5DESUser
createUser MD5DESUser MD5 "The Net-SNMP Demo password" DES "The Net-SNMP Demo password"
group demogroup usm noAuthUser
group demogroup usm MD5User
group demogroup usm SHAUser
group demogroup usm SHADESUser
createUser noAuthUser
createUser MD5User MD5 "The Net-SNMP Demo Password"
createUser SHAUser SHA "The Net-SNMP Demo Password"
createUser SHADESUser SHA "The Net-SNMP Demo Password" DES "The Net-SNMP Demo Password"
FROM: http://blog.sina.com.cn/s/blog_49f761940100pp30.html
group demogroup usm MD5User
group demogroup usm SHAUser
group demogroup usm SHADESUser
createUser noAuthUser
createUser MD5User MD5 "The Net-SNMP Demo Password"
createUser SHAUser SHA "The Net-SNMP Demo Password"
createUser SHADESUser SHA "The Net-SNMP Demo Password" DES "The Net-SNMP Demo Password"
FROM: http://blog.sina.com.cn/s/blog_49f761940100pp30.html
0 0
- snmpd装载一个动态链接库(so文件),以扩充MIB
- android动态链接库(so文件)
- Linux下升成动态链接库.so文件
- QT生成动态链接库.so文件
- Linux动态共享对象(动态链接库)装载过程
- Linux动态共享对象(动态链接库)装载过程
- 动态链接库(.so)
- 动态链接库 .so
- 动态链接库.so
- 链接、装载与库:动态链接
- linux动态链接库(***.so)
- 如何用gcc编译器生成动态链接库*.so文件(动态库)
- Linux动态链接库同名符号装载问题(一)
- Linux动态链接库同名符号装载问题(二)
- snmpd运行库文件找不到
- linux下调用动态链接库so文件
- linux下生成动态链接库so文件
- linux下生成动态链接库so文件
- 刚写的EXCEL分类处理程序
- SSH框架之Hibernate数据库外键如何插入值的问题
- POJ 2239 二分图最大匹配模版
- 关于Reveal的使用与注意事项
- Android中AsyncTask的使用
- snmpd装载一个动态链接库(so文件),以扩充MIB
- R语言程序
- IE下当a标签使用position:absolute绝对定位时没有点击区域的bug
- 《软件架构师应该知道的97件事》
- 10分钟实现android聊天机器人
- IOS自定义UIAlertView样式,实现可替换背景和按钮
- 【划屏/滚屏】划屏/滚屏效果demo
- android UI 操作 不要在子线程中操作UI
- DiskSim 4.0 with DIXtrac 在 ubuntu 12.04 32位 下的安装