Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
be3483b9
提交
be3483b9
authored
1月 28, 2011
作者:
Raymond Chandler
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of fs-git:freeswitch
上级
e6e4bcea
068d36a5
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
246 行增加
和
12 行删除
+246
-12
FREESWITCH-MIB
src/mod/event_handlers/mod_snmp/FREESWITCH-MIB
+84
-0
mod_snmp.c
src/mod/event_handlers/mod_snmp/mod_snmp.c
+1
-1
subagent.c
src/mod/event_handlers/mod_snmp/subagent.c
+140
-10
subagent.h
src/mod/event_handlers/mod_snmp/subagent.h
+21
-1
没有找到文件。
src/mod/event_handlers/mod_snmp/FREESWITCH-MIB
浏览文件 @
be3483b9
...
...
@@ -107,4 +107,88 @@ maxSessionsPerSecond OBJECT-TYPE
"Maximum permissible sessions per second"
::= { systemStats 7 }
ChannelEntry ::= SEQUENCE {
chanUUID DisplayString,
chanDirection DisplayString,
chanCreated DisplayString,
chanName DisplayString,
chanState DisplayString,
chanCIDName DisplayString,
chanCIDNum DisplayString
}
channelList OBJECT-TYPE
SYNTAX SEQUENCE OF ChannelEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"A table containing a list of active channels"
::= { core 9 }
channelEntry OBJECT-TYPE
SYNTAX ChannelEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"A channel entry"
INDEX { chanIndex }
::= { channelList 1 }
chanUUID OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The channel UUID."
::= { channelEntry 1 }
chanDirection OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The channel direction."
::= { channelEntry 2 }
chanCreated OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Channel creation timestamp."
::= { channelEntry 3 }
chanName OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The channel name."
::= { channelEntry 4 }
chanState OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The channel state."
::= { channelEntry 5 }
chanCIDName OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The channel caller ID name."
::= { channelEntry 6 }
chanCIDNum OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The channel caller ID number."
::= { channelEntry 7 }
END
src/mod/event_handlers/mod_snmp/mod_snmp.c
浏览文件 @
be3483b9
...
...
@@ -109,7 +109,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_snmp_load)
*/
netsnmp_ds_set_int
(
NETSNMP_DS_APPLICATION_ID
,
NETSNMP_DS_AGENT_AGENTX_PING_INTERVAL
,
2
);
init_subagent
(
);
init_subagent
(
pool
);
init_snmp
(
"mod_snmp"
);
return
status
;
...
...
src/mod/event_handlers/mod_snmp/subagent.c
浏览文件 @
be3483b9
...
...
@@ -36,27 +36,108 @@
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "subagent.h"
netsnmp_table_registration_info
*
ch_table_info
;
netsnmp_tdata
*
ch_table
;
netsnmp_handler_registration
*
ch_reginfo
;
uint32_t
idx
;
void
init_subagent
(
void
)
static
int
sql_count_callback
(
void
*
pArg
,
int
argc
,
char
**
argv
,
char
**
columnNames
)
{
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
};
uint32_t
*
count
=
(
uint32_t
*
)
pArg
;
*
count
=
atoi
(
argv
[
0
]);
return
0
;
}
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
(
"systemStats"
,
handle_systemStats
,
systemStats_oid
,
OID_LENGTH
(
systemStats_oid
),
HANDLER_CAN_RONLY
),
1
,
7
);
static
int
channelList_callback
(
void
*
pArg
,
int
argc
,
char
**
argv
,
char
**
columnNames
)
{
chan_entry_t
*
entry
;
netsnmp_tdata_row
*
row
;
switch_zmalloc
(
entry
,
sizeof
(
chan_entry_t
));
if
(
!
entry
)
return
0
;
row
=
netsnmp_tdata_create_row
();
if
(
!
row
)
{
switch_safe_free
(
entry
);
return
0
;
}
row
->
data
=
entry
;
entry
->
idx
=
idx
++
;
strncpy
(
entry
->
uuid
,
argv
[
0
],
sizeof
(
entry
->
uuid
));
strncpy
(
entry
->
direction
,
argv
[
1
],
sizeof
(
entry
->
direction
));
strncpy
(
entry
->
created
,
argv
[
2
],
sizeof
(
entry
->
created
));
strncpy
(
entry
->
name
,
argv
[
4
],
sizeof
(
entry
->
name
));
strncpy
(
entry
->
state
,
argv
[
5
],
sizeof
(
entry
->
state
));
strncpy
(
entry
->
cid_name
,
argv
[
6
],
sizeof
(
entry
->
cid_name
));
strncpy
(
entry
->
cid_num
,
argv
[
7
],
sizeof
(
entry
->
cid_num
));
netsnmp_tdata_row_add_index
(
row
,
ASN_INTEGER
,
&
entry
->
idx
,
sizeof
(
entry
->
idx
));
netsnmp_tdata_add_row
(
ch_table
,
row
);
return
0
;
}
static
int
sql_count_callback
(
void
*
pArg
,
int
argc
,
char
**
argv
,
char
**
columnNames
)
void
channelList_free
(
netsnmp_cache
*
cache
,
void
*
magic
)
{
uint32_t
*
count
=
(
uint32_t
*
)
pArg
;
*
count
=
atoi
(
argv
[
0
]);
netsnmp_tdata_row
*
row
=
netsnmp_tdata_row_first
(
ch_table
);
/* Delete table rows one by one */
while
(
row
)
{
netsnmp_tdata_remove_and_delete_row
(
ch_table
,
row
);
switch_safe_free
(
row
->
data
);
row
=
netsnmp_tdata_row_first
(
ch_table
);
}
}
int
channelList_load
(
netsnmp_cache
*
cache
,
void
*
vmagic
)
{
switch_cache_db_handle_t
*
dbh
;
char
sql
[
1024
]
=
""
,
hostname
[
256
]
=
""
;
channelList_free
(
cache
,
NULL
);
if
(
switch_core_db_handle
(
&
dbh
)
!=
SWITCH_STATUS_SUCCESS
)
{
return
0
;
}
idx
=
1
;
gethostname
(
hostname
,
sizeof
(
hostname
));
sprintf
(
sql
,
"SELECT * FROM channels WHERE hostname='%s' ORDER BY created_epoch"
,
hostname
);
switch_cache_db_execute_sql_callback
(
dbh
,
sql
,
channelList_callback
,
NULL
,
NULL
);
switch_cache_db_release_db_handle
(
&
dbh
);
return
0
;
}
void
init_subagent
(
switch_memory_pool_t
*
pool
)
{
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
};
static
oid
channelList_oid
[]
=
{
1
,
3
,
6
,
1
,
4
,
1
,
27880
,
1
,
9
};
DEBUGMSGTL
((
"init_subagent"
,
"mod_snmp 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
(
"systemStats"
,
handle_systemStats
,
systemStats_oid
,
OID_LENGTH
(
systemStats_oid
),
HANDLER_CAN_RONLY
),
1
,
7
);
ch_table_info
=
switch_core_alloc
(
pool
,
sizeof
(
netsnmp_table_registration_info
));
netsnmp_table_helper_add_index
(
ch_table_info
,
ASN_INTEGER
);
ch_table_info
->
min_column
=
1
;
ch_table_info
->
max_column
=
7
;
ch_table
=
netsnmp_tdata_create_table
(
"channelList"
,
0
);
ch_reginfo
=
netsnmp_create_handler_registration
(
"channelList"
,
handle_channelList
,
channelList_oid
,
OID_LENGTH
(
channelList_oid
),
HANDLER_CAN_RONLY
);
netsnmp_tdata_register
(
ch_reginfo
,
ch_table
,
ch_table_info
);
netsnmp_inject_handler
(
ch_reginfo
,
netsnmp_get_cache_handler
(
5
,
channelList_load
,
channelList_free
,
channelList_oid
,
OID_LENGTH
(
channelList_oid
)));
}
int
handle_identity
(
netsnmp_mib_handler
*
handler
,
netsnmp_handler_registration
*
reginfo
,
netsnmp_agent_request_info
*
reqinfo
,
netsnmp_request_info
*
requests
)
{
netsnmp_request_info
*
request
=
NULL
;
...
...
@@ -97,7 +178,7 @@ int handle_systemStats(netsnmp_mib_handler *handler, netsnmp_handler_registratio
netsnmp_request_info
*
request
=
NULL
;
oid
subid
;
switch_time_t
uptime
;
uint32_t
int_val
;
uint32_t
int_val
=
0
;
switch
(
reqinfo
->
mode
)
{
case
MODE_GET
:
...
...
@@ -160,6 +241,55 @@ int handle_systemStats(netsnmp_mib_handler *handler, netsnmp_handler_registratio
}
int
handle_channelList
(
netsnmp_mib_handler
*
handler
,
netsnmp_handler_registration
*
reginfo
,
netsnmp_agent_request_info
*
reqinfo
,
netsnmp_request_info
*
requests
)
{
netsnmp_request_info
*
request
;
netsnmp_table_request_info
*
table_info
;
chan_entry_t
*
entry
;
switch
(
reqinfo
->
mode
)
{
case
MODE_GET
:
for
(
request
=
requests
;
request
;
request
=
request
->
next
)
{
table_info
=
netsnmp_extract_table_info
(
request
);
entry
=
(
chan_entry_t
*
)
netsnmp_tdata_extract_entry
(
request
);
switch
(
table_info
->
colnum
)
{
case
CH_UUID
:
snmp_set_var_typed_value
(
request
->
requestvb
,
ASN_OCTET_STR
,
(
u_char
*
)
entry
->
uuid
,
strlen
(
entry
->
uuid
));
break
;
case
CH_DIRECTION
:
snmp_set_var_typed_value
(
request
->
requestvb
,
ASN_OCTET_STR
,
(
u_char
*
)
entry
->
direction
,
strlen
(
entry
->
direction
));
break
;
case
CH_CREATED
:
snmp_set_var_typed_value
(
request
->
requestvb
,
ASN_OCTET_STR
,
(
u_char
*
)
entry
->
created
,
strlen
(
entry
->
created
));
break
;
case
CH_NAME
:
snmp_set_var_typed_value
(
request
->
requestvb
,
ASN_OCTET_STR
,
(
u_char
*
)
entry
->
name
,
strlen
(
entry
->
name
));
break
;
case
CH_STATE
:
snmp_set_var_typed_value
(
request
->
requestvb
,
ASN_OCTET_STR
,
(
u_char
*
)
entry
->
state
,
strlen
(
entry
->
state
));
break
;
case
CH_CID_NAME
:
snmp_set_var_typed_value
(
request
->
requestvb
,
ASN_OCTET_STR
,
(
u_char
*
)
entry
->
cid_name
,
strlen
(
entry
->
cid_name
));
break
;
case
CH_CID_NUM
:
snmp_set_var_typed_value
(
request
->
requestvb
,
ASN_OCTET_STR
,
(
u_char
*
)
entry
->
cid_num
,
strlen
(
entry
->
cid_num
));
break
;
default:
snmp_log
(
LOG_WARNING
,
"Unregistered OID-suffix requested (%d)
\n
"
,
table_info
->
colnum
);
netsnmp_set_request_error
(
reqinfo
,
request
,
SNMP_NOSUCHOBJECT
);
}
}
break
;
default:
/* we should never get here, so this is a really bad error */
snmp_log
(
LOG_ERR
,
"Unknown mode (%d) in handle_foo
\n
"
,
reqinfo
->
mode
);
return
SNMP_ERR_GENERR
;
}
return
SNMP_ERR_NOERROR
;
}
/* For Emacs:
* Local Variables:
...
...
src/mod/event_handlers/mod_snmp/subagent.h
浏览文件 @
be3483b9
...
...
@@ -14,9 +14,29 @@
#define SS_SESSIONS_PER_SECOND 6
#define SS_MAX_SESSIONS_PER_SECOND 7
/* .1.3.6.1.4.1.27880.1.9 */
#define CH_UUID 1
#define CH_DIRECTION 2
#define CH_CREATED 3
#define CH_NAME 4
#define CH_STATE 5
#define CH_CID_NAME 6
#define CH_CID_NUM 7
void
init_subagent
(
void
);
typedef
struct
{
uint32_t
idx
;
char
uuid
[
38
];
char
direction
[
32
];
char
created
[
128
];
char
name
[
1024
];
char
state
[
64
];
char
cid_name
[
1024
];
char
cid_num
[
256
];
}
chan_entry_t
;
void
init_subagent
(
switch_memory_pool_t
*
pool
);
Netsnmp_Node_Handler
handle_identity
;
Netsnmp_Node_Handler
handle_systemStats
;
Netsnmp_Node_Handler
handle_channelList
;
#endif
/* subagent_H */
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论