SNMP 添加MIB 节点 (十一) --- snmp配置文件热更新

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 的配置文件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值