2011-01-21 21:05:01 +01:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
* Copyright (C) 2005-2011, Anthony Minessale II <anthm@freeswitch.org>
|
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Daniel Swarbrick <daniel.swarbrick@seventhsignal.de>
|
|
|
|
* Stefan Knoblich <s.knoblich@axsentis.de>
|
|
|
|
*
|
|
|
|
* mod_snmp.c -- SNMP AgentX Subagent Module
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <switch.h>
|
|
|
|
|
|
|
|
#include <net-snmp/net-snmp-config.h>
|
|
|
|
#include <net-snmp/net-snmp-includes.h>
|
|
|
|
#include <net-snmp/agent/net-snmp-agent-includes.h>
|
|
|
|
|
|
|
|
#include "subagent.h"
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
switch_memory_pool_t *pool;
|
2011-01-25 19:19:17 +01:00
|
|
|
switch_mutex_t *mutex;
|
2011-01-21 21:05:01 +01:00
|
|
|
int shutdown;
|
|
|
|
} globals;
|
|
|
|
|
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_snmp_load);
|
|
|
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_snmp_shutdown);
|
|
|
|
SWITCH_MODULE_RUNTIME_FUNCTION(mod_snmp_runtime);
|
|
|
|
SWITCH_MODULE_DEFINITION(mod_snmp, mod_snmp_load, mod_snmp_shutdown, mod_snmp_runtime);
|
|
|
|
|
|
|
|
|
|
|
|
static int snmp_callback_log(int major, int minor, void *serverarg, void *clientarg)
|
|
|
|
{
|
|
|
|
struct snmp_log_message *slm = (struct snmp_log_message *) serverarg;
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, slm->priority, "%s", slm->msg);
|
|
|
|
return SNMP_ERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static switch_status_t load_config(switch_memory_pool_t *pool)
|
|
|
|
{
|
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
memset(&globals, 0, sizeof(globals));
|
|
|
|
globals.pool = pool;
|
2011-01-25 19:19:17 +01:00
|
|
|
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool);
|
2011-01-21 21:05:01 +01:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_snmp_load)
|
|
|
|
{
|
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
load_config(pool);
|
|
|
|
|
|
|
|
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
|
|
|
|
|
|
|
/* Register callback function so we get Net-SNMP logging handled by FreeSWITCH */
|
|
|
|
snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_LOGGING, snmp_callback_log, NULL);
|
|
|
|
snmp_enable_calllog();
|
|
|
|
|
|
|
|
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PERSIST_STATE, 1);
|
|
|
|
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
|
|
|
|
|
|
|
|
init_agent("mod_snmp");
|
2011-01-25 00:26:58 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Override master/subagent ping interval to 5s, to ensure that
|
|
|
|
* agent_check_and_process() never blocks for longer than that.
|
|
|
|
*/
|
|
|
|
netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_AGENTX_PING_INTERVAL, 5);
|
|
|
|
|
2011-01-21 21:05:01 +01:00
|
|
|
init_subagent();
|
|
|
|
init_snmp("mod_snmp");
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SWITCH_MODULE_RUNTIME_FUNCTION(mod_snmp_runtime)
|
|
|
|
{
|
2011-01-25 19:19:17 +01:00
|
|
|
if (!globals.shutdown) {
|
|
|
|
switch_mutex_lock(globals.mutex);
|
2011-01-25 20:00:32 +01:00
|
|
|
/* Block on select() */
|
2011-01-25 00:26:58 +01:00
|
|
|
agent_check_and_process(1);
|
2011-01-25 19:19:17 +01:00
|
|
|
switch_mutex_unlock(globals.mutex);
|
2011-01-25 00:26:58 +01:00
|
|
|
}
|
2011-01-21 21:05:01 +01:00
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_snmp_shutdown)
|
|
|
|
{
|
|
|
|
globals.shutdown = 1;
|
|
|
|
|
2011-01-25 19:19:17 +01:00
|
|
|
switch_mutex_lock(globals.mutex);
|
2011-01-21 21:05:01 +01:00
|
|
|
snmp_shutdown("mod_snmp");
|
2011-01-25 19:19:17 +01:00
|
|
|
switch_mutex_unlock(globals.mutex);
|
|
|
|
|
|
|
|
switch_mutex_destroy(globals.mutex);
|
2011-01-21 21:05:01 +01:00
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
|
|
|
* indent-tabs-mode:t
|
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
|
|
|
*/
|