The Net-SNMP agent can be instructed to re-read the various configuration files,
either via an \fBsnmpset\fR assignment of integer(1) to
\fCUCD\-SNMP\-MIB::versionUpdateConfig.0\fR (.1.3.6.1.4.1.2021.100.11.0),
or by sending a \fBkill \-HUP\fR signal to the agent process.
.IP o
1.snmpd.conf 添加
repeat 60 1.3.6.1.4.1.2021.100.11.0 = 1
每60秒更新一次配置文件
2.net-snmp-5.9.1\agent\snmpd.c 中
static int receive(void)函数,截取部分如下,应该可以通过添加相关处理实现配置功能热更新
reconfig = 0;
#if defined(WIN32)
create_stdin_waiter_thread();
#endif
/*
* Loop-forever: execute message handlers for sockets with data
*/
while (netsnmp_running) {
if (reconfig) {
#if HAVE_SIGPROCMASK
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGHUP);
ret = sigprocmask(SIG_BLOCK, &set, NULL);
netsnmp_assert(ret == 0);
#endif
reconfig = 0;
snmp_log(LOG_INFO, "Reconfiguring daemon\n");
/* Stop and restart logging. This allows logfiles to be
rotated etc. */
netsnmp_logging_restart();
snmp_log(LOG_INFO, "NET-SNMP version %s restarted\n",
netsnmp_get_version());
update_config();
send_easy_trap(SNMP_TRAP_ENTERPRISESPECIFIC, 3);
#if HAVE_SIGPROCMASK
ret = sigprocmask(SIG_UNBLOCK, &set, NULL);
netsnmp_assert(ret == 0);
#endif
}
3.经测试,repeat 热更新会出问题,调用会不断增多,而且Ubuntu上权限会有问题,可能是repeat 产生定时器的BUG,推荐在脚本里加
./snmpset -v2c -c private 192.168.186.215 .1.3.6.1.4.1.2021.100.12.0 i 1
来热更新SNMP 的配置文件