mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-15 00:22:35 +00:00
tidy up subagent and #defines
This commit is contained in:
parent
636c1ecb4e
commit
4b731fd64c
@ -101,8 +101,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_snmp_load)
|
|||||||
SWITCH_MODULE_RUNTIME_FUNCTION(mod_snmp_runtime)
|
SWITCH_MODULE_RUNTIME_FUNCTION(mod_snmp_runtime)
|
||||||
{
|
{
|
||||||
if (!globals.shutdown) {
|
if (!globals.shutdown) {
|
||||||
/* Block on select() */
|
|
||||||
switch_mutex_lock(globals.mutex);
|
switch_mutex_lock(globals.mutex);
|
||||||
|
/* Block on select() */
|
||||||
agent_check_and_process(1);
|
agent_check_and_process(1);
|
||||||
switch_mutex_unlock(globals.mutex);
|
switch_mutex_unlock(globals.mutex);
|
||||||
}
|
}
|
||||||
|
@ -37,31 +37,12 @@
|
|||||||
#include "subagent.h"
|
#include "subagent.h"
|
||||||
|
|
||||||
|
|
||||||
static oid identity_oid[] = { 1,3,6,1,4,1,27880,1,1 };
|
|
||||||
static oid systemStats_oid[] = { 1,3,6,1,4,1,27880,1,2 };
|
|
||||||
|
|
||||||
/* identity sub-IDs - these must match MIB */
|
|
||||||
enum {
|
|
||||||
versionString_oid = 1,
|
|
||||||
uuid_oid
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* systemStats sub-IDs - these must match MIB */
|
|
||||||
enum {
|
|
||||||
uptime_oid = 1,
|
|
||||||
sessionsSinceStartup_oid,
|
|
||||||
currentSessions_oid,
|
|
||||||
maxSessions_oid,
|
|
||||||
currentCalls_oid,
|
|
||||||
sessionsPerSecond_oid,
|
|
||||||
maxSessionsPerSecond_oid
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void init_subagent(void)
|
void init_subagent(void)
|
||||||
{
|
{
|
||||||
DEBUGMSGTL(("init_nstAgentSubagentObject", "Initializing\n"));
|
static oid identity_oid[] = { 1,3,6,1,4,1,27880,1,1 };
|
||||||
|
static oid systemStats_oid[] = { 1,3,6,1,4,1,27880,1,2 };
|
||||||
|
|
||||||
|
DEBUGMSGTL(("init_subagent", "Initializing\n"));
|
||||||
|
|
||||||
netsnmp_register_scalar_group(netsnmp_create_handler_registration("identity", handle_identity, identity_oid, OID_LENGTH(identity_oid), HANDLER_CAN_RONLY), 1, 2);
|
netsnmp_register_scalar_group(netsnmp_create_handler_registration("identity", handle_identity, identity_oid, OID_LENGTH(identity_oid), HANDLER_CAN_RONLY), 1, 2);
|
||||||
netsnmp_register_scalar_group(netsnmp_create_handler_registration("systemStats", handle_systemStats, systemStats_oid, OID_LENGTH(systemStats_oid), HANDLER_CAN_RONLY), 1, 7);
|
netsnmp_register_scalar_group(netsnmp_create_handler_registration("systemStats", handle_systemStats, systemStats_oid, OID_LENGTH(systemStats_oid), HANDLER_CAN_RONLY), 1, 7);
|
||||||
@ -70,28 +51,26 @@ void init_subagent(void)
|
|||||||
|
|
||||||
int handle_identity(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests)
|
int handle_identity(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests)
|
||||||
{
|
{
|
||||||
static char const version[] = SWITCH_VERSION_FULL;
|
|
||||||
char uuid[40] = "";
|
|
||||||
netsnmp_request_info *request = NULL;
|
netsnmp_request_info *request = NULL;
|
||||||
oid subid;
|
oid subid;
|
||||||
|
static char const version[] = SWITCH_VERSION_FULL;
|
||||||
|
char uuid[40] = "";
|
||||||
|
|
||||||
switch(reqinfo->mode) {
|
switch(reqinfo->mode) {
|
||||||
case MODE_GET:
|
case MODE_GET:
|
||||||
for (request = requests; request; request = request->next) {
|
subid = requests->requestvb->name[reginfo->rootoid_len - 2];
|
||||||
subid = request->requestvb->name[reginfo->rootoid_len - 2];
|
|
||||||
|
|
||||||
switch (subid) {
|
switch (subid) {
|
||||||
case versionString_oid:
|
case ID_VERSION_STR:
|
||||||
snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, (u_char *) &version, strlen(version));
|
snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, (u_char *) &version, strlen(version));
|
||||||
break;
|
break;
|
||||||
case uuid_oid:
|
case ID_UUID:
|
||||||
strncpy(uuid, switch_core_get_uuid(), sizeof(uuid));
|
strncpy(uuid, switch_core_get_uuid(), sizeof(uuid));
|
||||||
snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, (u_char *) &uuid, strlen(uuid));
|
snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, (u_char *) &uuid, strlen(uuid));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
snmp_log(LOG_WARNING, "Unregistered OID-suffix requested (%d)\n", (int) subid);
|
snmp_log(LOG_WARNING, "Unregistered OID-suffix requested (%d)\n", (int) subid);
|
||||||
netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
|
netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -114,47 +93,45 @@ int handle_systemStats(netsnmp_mib_handler *handler, netsnmp_handler_registratio
|
|||||||
|
|
||||||
switch(reqinfo->mode) {
|
switch(reqinfo->mode) {
|
||||||
case MODE_GET:
|
case MODE_GET:
|
||||||
for (request = requests; request; request = request->next) {
|
subid = requests->requestvb->name[reginfo->rootoid_len - 2];
|
||||||
subid = request->requestvb->name[reginfo->rootoid_len - 2];
|
|
||||||
|
|
||||||
switch (subid) {
|
switch (subid) {
|
||||||
case uptime_oid:
|
case SS_UPTIME:
|
||||||
uptime = switch_core_uptime() / 10000;
|
uptime = switch_core_uptime() / 10000;
|
||||||
snmp_set_var_typed_value(requests->requestvb, ASN_TIMETICKS, (u_char *) &uptime, sizeof(uptime));
|
snmp_set_var_typed_value(requests->requestvb, ASN_TIMETICKS, (u_char *) &uptime, sizeof(uptime));
|
||||||
break;
|
break;
|
||||||
case sessionsSinceStartup_oid:
|
case SS_SESSIONS_SINCE_STARTUP:
|
||||||
int_val = switch_core_session_id() - 1;
|
int_val = switch_core_session_id() - 1;
|
||||||
snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, (u_char *) &int_val, sizeof(int_val));
|
snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, (u_char *) &int_val, sizeof(int_val));
|
||||||
break;
|
break;
|
||||||
case currentSessions_oid:
|
case SS_CURRENT_SESSIONS:
|
||||||
int_val = switch_core_session_count();
|
int_val = switch_core_session_count();
|
||||||
snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, (u_char *) &int_val, sizeof(int_val));
|
snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, (u_char *) &int_val, sizeof(int_val));
|
||||||
break;
|
break;
|
||||||
case maxSessions_oid:
|
case SS_MAX_SESSIONS:
|
||||||
switch_core_session_ctl(SCSC_MAX_SESSIONS, &int_val);;
|
switch_core_session_ctl(SCSC_MAX_SESSIONS, &int_val);;
|
||||||
snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, (u_char *) &int_val, sizeof(int_val));
|
snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, (u_char *) &int_val, sizeof(int_val));
|
||||||
break;
|
break;
|
||||||
case currentCalls_oid:
|
case SS_CURRENT_CALLS:
|
||||||
/*
|
/*
|
||||||
* This is zero for now, since there is no convenient way to get total call
|
* This is zero for now, since there is no convenient way to get total call
|
||||||
* count (not to be confused with session count), without touching the
|
* count (not to be confused with session count), without touching the
|
||||||
* database.
|
* database.
|
||||||
*/
|
*/
|
||||||
int_val = 0;
|
int_val = 0;
|
||||||
snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, (u_char *) &int_val, sizeof(int_val));
|
snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, (u_char *) &int_val, sizeof(int_val));
|
||||||
break;
|
break;
|
||||||
case sessionsPerSecond_oid:
|
case SS_SESSIONS_PER_SECOND:
|
||||||
switch_core_session_ctl(SCSC_LAST_SPS, &int_val);
|
switch_core_session_ctl(SCSC_LAST_SPS, &int_val);
|
||||||
snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, (u_char *) &int_val, sizeof(int_val));
|
snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, (u_char *) &int_val, sizeof(int_val));
|
||||||
break;
|
break;
|
||||||
case maxSessionsPerSecond_oid:
|
case SS_MAX_SESSIONS_PER_SECOND:
|
||||||
switch_core_session_ctl(SCSC_SPS, &int_val);
|
switch_core_session_ctl(SCSC_SPS, &int_val);
|
||||||
snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, (u_char *) &int_val, sizeof(int_val));
|
snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, (u_char *) &int_val, sizeof(int_val));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
snmp_log(LOG_WARNING, "Unregistered OID-suffix requested (%d)\n", (int) subid);
|
snmp_log(LOG_WARNING, "Unregistered OID-suffix requested (%d)\n", (int) subid);
|
||||||
netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
|
netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1,6 +1,20 @@
|
|||||||
#ifndef subagent_H
|
#ifndef subagent_H
|
||||||
#define subagent_H
|
#define subagent_H
|
||||||
|
|
||||||
|
/* .1.3.6.1.4.1.27880.1.1 */
|
||||||
|
#define ID_VERSION_STR 1
|
||||||
|
#define ID_UUID 2
|
||||||
|
|
||||||
|
/* .1.3.6.1.4.1.27880.1.2 */
|
||||||
|
#define SS_UPTIME 1
|
||||||
|
#define SS_SESSIONS_SINCE_STARTUP 2
|
||||||
|
#define SS_CURRENT_SESSIONS 3
|
||||||
|
#define SS_MAX_SESSIONS 4
|
||||||
|
#define SS_CURRENT_CALLS 5
|
||||||
|
#define SS_SESSIONS_PER_SECOND 6
|
||||||
|
#define SS_MAX_SESSIONS_PER_SECOND 7
|
||||||
|
|
||||||
|
|
||||||
void init_subagent(void);
|
void init_subagent(void);
|
||||||
Netsnmp_Node_Handler handle_identity;
|
Netsnmp_Node_Handler handle_identity;
|
||||||
Netsnmp_Node_Handler handle_systemStats;
|
Netsnmp_Node_Handler handle_systemStats;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user