当前位置: 技术问答>linux和unix
关于Linux下net-snmp mib2c 生成.c和.h修改问题
来源: 互联网 发布时间:2016-10-09
本文导语: 在网上看到一篇关于snmp的帖子 .mib 库文件 BVCOM-SYSTEMUPTIME-MIB.txt: BVCOM-SYSTEMUPTIME-MIB DEFINITIONS ::= BEGIN IMPORTS TimeTicks FROM SNMPv2-SMI enterprises FROM SNMPv2-SMI OBJECT-TYPE, Integer32, MODULE-IDENTITY ...
在网上看到一篇关于snmp的帖子
.mib 库文件 BVCOM-SYSTEMUPTIME-MIB.txt:
BVCOM-SYSTEMUPTIME-MIB DEFINITIONS ::= BEGIN
IMPORTS
TimeTicks FROM SNMPv2-SMI
enterprises FROM SNMPv2-SMI
OBJECT-TYPE, Integer32, MODULE-IDENTITY FROM SNMPv2-SMI;
bvcom OBJECT IDENTIFIER ::= { enterprises 26814 }
ipq6800 OBJECT IDENTIFIER ::= { bvcom 6800 }
bvcomAgentModules OBJECT IDENTIFIER ::= { ipq6800 1 }
bvcomAgentModuleObject OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"This is an object that simply supports a writable integer
when compiled into the agent. See
http://www.net-snmp.org/tutorial-5/toolkit/XXX for further
implementation details."
DEFVAL { 1 }
::= { bvcomAgentModules 1 }
bvcomAgentSubagentObject OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"This is an object that simply supports a writable integer
when attached to the agent. The object should be accessible
when the agentx subagent containing this object is attached.
See http://www.net-snmp.org/tutorial-5/toolkit/XXX for
further implementation details."
DEFVAL { 2 }
::= { bvcomAgentModules 2 }
bvcomAgentPluginObject OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"This is an object that simply supports a writable integer
when attached to the agent. This object should be accessible
when the dynamic plugin has been loaded into the agent. See
http://www.net-snmp.org/tutorial-5/toolkit/XXX for further
implementation details."
DEFVAL { 3 }
::= { bvcomAgentModules 3 }
END
mib2c -c mib2c.int_watch.conf bvcomAgentMo
生成.c和.h文件
通过 snmp_agent_api 编写守护程序 example-demon.c:
#include
#include
#include
#include
#include "bvcomAgentModules.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 */
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 our mib code here */
printf("Before init bvcomAgentModules n");
init_bvcomAgentModules(); // 加载节点信息
printf("End init bvcomAgentModules n");
/* 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. */
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) */
printf("---------------------n");
/* 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;
}
8.Makefile:
CC=gcc
OBJS2=example-demon.o bvcomAgentModules.o
TARGETS=example-demon
CFLAGS=-I. `net-snmp-config --cflags`
BUILDLIBS=`net-snmp-config --libs`
BUILDAGENTLIBS=`net-snmp-config --agent-libs`
# shared library flags (assumes gcc)
DLFLAGS=-fPIC -shared
all: $(TARGETS)
example-demon: $(OBJS2)
$(CC) -o example-demon $(OBJS2) $(BUILDAGENTLIBS)
clean:
rm $(OBJS2) $(OBJS2) $(TARGETS)
但是为什么我执行make时报错
Makefile:11: *** missing separator. Stop.
编译不过去呢
http://wifihack.net/blog/2008/11/snmp%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%E4%B9%8B%E4%B8%89%EF%BC%8D%EF%BC%8D%E5%BC%80%E5%8F%91netsnmp-agent/
.mib 库文件 BVCOM-SYSTEMUPTIME-MIB.txt:
BVCOM-SYSTEMUPTIME-MIB DEFINITIONS ::= BEGIN
IMPORTS
TimeTicks FROM SNMPv2-SMI
enterprises FROM SNMPv2-SMI
OBJECT-TYPE, Integer32, MODULE-IDENTITY FROM SNMPv2-SMI;
bvcom OBJECT IDENTIFIER ::= { enterprises 26814 }
ipq6800 OBJECT IDENTIFIER ::= { bvcom 6800 }
bvcomAgentModules OBJECT IDENTIFIER ::= { ipq6800 1 }
bvcomAgentModuleObject OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"This is an object that simply supports a writable integer
when compiled into the agent. See
http://www.net-snmp.org/tutorial-5/toolkit/XXX for further
implementation details."
DEFVAL { 1 }
::= { bvcomAgentModules 1 }
bvcomAgentSubagentObject OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"This is an object that simply supports a writable integer
when attached to the agent. The object should be accessible
when the agentx subagent containing this object is attached.
See http://www.net-snmp.org/tutorial-5/toolkit/XXX for
further implementation details."
DEFVAL { 2 }
::= { bvcomAgentModules 2 }
bvcomAgentPluginObject OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"This is an object that simply supports a writable integer
when attached to the agent. This object should be accessible
when the dynamic plugin has been loaded into the agent. See
http://www.net-snmp.org/tutorial-5/toolkit/XXX for further
implementation details."
DEFVAL { 3 }
::= { bvcomAgentModules 3 }
END
mib2c -c mib2c.int_watch.conf bvcomAgentMo
生成.c和.h文件
通过 snmp_agent_api 编写守护程序 example-demon.c:
#include
#include
#include
#include
#include "bvcomAgentModules.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 */
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 our mib code here */
printf("Before init bvcomAgentModules n");
init_bvcomAgentModules(); // 加载节点信息
printf("End init bvcomAgentModules n");
/* 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. */
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) */
printf("---------------------n");
/* 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;
}
8.Makefile:
CC=gcc
OBJS2=example-demon.o bvcomAgentModules.o
TARGETS=example-demon
CFLAGS=-I. `net-snmp-config --cflags`
BUILDLIBS=`net-snmp-config --libs`
BUILDAGENTLIBS=`net-snmp-config --agent-libs`
# shared library flags (assumes gcc)
DLFLAGS=-fPIC -shared
all: $(TARGETS)
example-demon: $(OBJS2)
$(CC) -o example-demon $(OBJS2) $(BUILDAGENTLIBS)
clean:
rm $(OBJS2) $(OBJS2) $(TARGETS)
但是为什么我执行make时报错
Makefile:11: *** missing separator. Stop.
编译不过去呢
http://wifihack.net/blog/2008/11/snmp%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%E4%B9%8B%E4%B8%89%EF%BC%8D%EF%BC%8D%E5%BC%80%E5%8F%91netsnmp-agent/
|
example-demon: $(OBJS2)
$(CC) -o example-demon $(OBJS2) $(BUILDAGENTLIBS)
clean:
rm $(OBJS2) $(OBJS2) $(TARGETS)
------------------
makefile中的命令(上例中的$(CC)、rm)必须以打头,不能是空格
$(CC) -o example-demon $(OBJS2) $(BUILDAGENTLIBS)
clean:
rm $(OBJS2) $(OBJS2) $(TARGETS)
------------------
makefile中的命令(上例中的$(CC)、rm)必须以打头,不能是空格