2 * Copyright (C) 2006 Voop as
3 * Thorsten Lockert <tholo@voop.as>
5 * This program is free software, distributed under the terms of
6 * the GNU General Public License Version 2. See the LICENSE file
7 * at the top of the source tree.
12 * \brief SNMP Agent / SubAgent support for Asterisk
14 * \author Thorsten Lockert <tholo@voop.as>
18 <support_level>extended</support_level>
23 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
26 * There is some collision collision between netsmp and asterisk names,
27 * causing build under AST_DEVMODE to fail.
29 * The following PACKAGE_* macros are one place.
30 * Also netsnmp has an improper check for HAVE_DMALLOC_H, using
31 * #if HAVE_DMALLOC_H instead of #ifdef HAVE_DMALLOC_H
32 * As a countermeasure we define it to 0, however this will fail
33 * when the proper check is implemented.
38 #ifdef PACKAGE_BUGREPORT
39 #undef PACKAGE_BUGREPORT
44 #ifdef PACKAGE_TARNAME
45 #undef PACKAGE_TARNAME
47 #ifdef PACKAGE_VERSION
48 #undef PACKAGE_VERSION
50 #ifndef HAVE_DMALLOC_H
51 #define HAVE_DMALLOC_H 0 /* XXX we shouldn't do this */
54 #if defined(__OpenBSD__)
56 * OpenBSD uses old "legacy" cc which has a rather pedantic builtin preprocessor.
57 * Using a macro which is not #defined throws an error.
59 #define __NetBSD_Version__ 0
62 #include <net-snmp/net-snmp-config.h>
63 #include <net-snmp/net-snmp-includes.h>
64 #include <net-snmp/agent/net-snmp-agent-includes.h>
66 #include "asterisk/paths.h" /* need ast_config_AST_SOCKET */
67 #include "asterisk/channel.h"
68 #include "asterisk/logger.h"
69 #include "asterisk/options.h"
70 #include "asterisk/indications.h"
71 #include "asterisk/ast_version.h"
72 #include "asterisk/pbx.h"
74 /* Colission between Net-SNMP and Asterisk */
75 #define unload_module ast_unload_module
76 #include "asterisk/module.h"
81 /* Helper functions in Net-SNMP, header file not installed by default */
82 int header_generic(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **);
83 int header_simple_table(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **, int);
84 int register_sysORTable(oid *, size_t, const char *);
85 int unregister_sysORTable(oid *, size_t);
87 /* Forward declaration */
88 static void init_asterisk_mib(void);
91 * Anchor for all the Asterisk MIB values
93 static oid asterisk_oid[] = { 1, 3, 6, 1, 4, 1, 22736, 1 };
96 * MIB values -- these correspond to values in the Asterisk MIB,
97 * and MUST be kept in sync with the MIB for things to work as
101 #define ASTVERSTRING 1
104 #define ASTCONFIGURATION 2
105 #define ASTCONFUPTIME 1
106 #define ASTCONFRELOADTIME 2
108 #define ASTCONFSOCKET 4
109 #define ASTCONFACTIVECALLS 5
110 #define ASTCONFPROCESSEDCALLS 6
113 #define ASTMODCOUNT 1
115 #define ASTINDICATIONS 4
116 #define ASTINDCOUNT 1
117 #define ASTINDCURRENT 2
119 #define ASTINDTABLE 3
120 #define ASTINDINDEX 1
121 #define ASTINDCOUNTRY 2
122 #define ASTINDALIAS 3
123 #define ASTINDDESCRIPTION 4
125 #define ASTCHANNELS 5
126 #define ASTCHANCOUNT 1
128 #define ASTCHANTABLE 2
129 #define ASTCHANINDEX 1
130 #define ASTCHANNAME 2
131 #define ASTCHANLANGUAGE 3
132 #define ASTCHANTYPE 4
133 #define ASTCHANMUSICCLASS 5
134 #define ASTCHANBRIDGE 6
135 #define ASTCHANMASQ 7
136 #define ASTCHANMASQR 8
137 #define ASTCHANWHENHANGUP 9
138 #define ASTCHANAPP 10
139 #define ASTCHANDATA 11
140 #define ASTCHANCONTEXT 12
141 #define ASTCHANMACROCONTEXT 13
142 #define ASTCHANMACROEXTEN 14
143 #define ASTCHANMACROPRI 15
144 #define ASTCHANEXTEN 16
145 #define ASTCHANPRI 17
146 #define ASTCHANACCOUNTCODE 18
147 #define ASTCHANFORWARDTO 19
148 #define ASTCHANUNIQUEID 20
149 #define ASTCHANCALLGROUP 21
150 #define ASTCHANPICKUPGROUP 22
151 #define ASTCHANSTATE 23
152 #define ASTCHANMUTED 24
153 #define ASTCHANRINGS 25
154 #define ASTCHANCIDDNID 26
155 #define ASTCHANCIDNUM 27
156 #define ASTCHANCIDNAME 28
157 #define ASTCHANCIDANI 29
158 #define ASTCHANCIDRDNIS 30
159 #define ASTCHANCIDPRES 31
160 #define ASTCHANCIDANI2 32
161 #define ASTCHANCIDTON 33
162 #define ASTCHANCIDTNS 34
163 #define ASTCHANAMAFLAGS 35
164 #define ASTCHANADSI 36
165 #define ASTCHANTONEZONE 37
166 #define ASTCHANHANGUPCAUSE 38
167 #define ASTCHANVARIABLES 39
168 #define ASTCHANFLAGS 40
169 #define ASTCHANTRANSFERCAP 41
171 #define ASTCHANTYPECOUNT 3
173 #define ASTCHANTYPETABLE 4
174 #define ASTCHANTYPEINDEX 1
175 #define ASTCHANTYPENAME 2
176 #define ASTCHANTYPEDESC 3
177 #define ASTCHANTYPEDEVSTATE 4
178 #define ASTCHANTYPEINDICATIONS 5
179 #define ASTCHANTYPETRANSFER 6
180 #define ASTCHANTYPECHANNELS 7
182 #define ASTCHANSCALARS 5
183 #define ASTCHANBRIDGECOUNT 1
185 void *agent_thread(void *arg)
187 ast_verb(2, "Starting %sAgent\n", res_snmp_agentx_subagent ? "Sub" : "");
189 snmp_enable_stderrlog();
191 if (res_snmp_agentx_subagent)
192 netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
193 NETSNMP_DS_AGENT_ROLE,
196 init_agent("asterisk");
200 init_snmp("asterisk");
202 if (!res_snmp_agentx_subagent)
205 while (res_snmp_dont_stop)
206 agent_check_and_process(1);
208 snmp_shutdown("asterisk");
210 ast_verb(2, "Terminating %sAgent\n", res_snmp_agentx_subagent ? "Sub" : "");
216 ast_var_channels(struct variable *vp, oid *name, size_t *length,
217 int exact, size_t *var_len, WriteMethod **write_method)
219 static unsigned long long_ret;
221 if (header_generic(vp, name, length, exact, var_len, write_method))
224 if (vp->magic != ASTCHANCOUNT)
227 long_ret = ast_active_channels();
229 return (u_char *)&long_ret;
232 static u_char *ast_var_channels_table(struct variable *vp, oid *name, size_t *length,
233 int exact, size_t *var_len, WriteMethod **write_method)
235 static unsigned long long_ret;
236 static u_char bits_ret[2];
237 static char string_ret[256];
238 struct ast_channel *chan, *bridge;
242 struct ast_str *out = ast_str_alloca(2048);
243 struct ast_channel_iterator *iter;
245 if (header_simple_table(vp, name, length, exact, var_len, write_method, ast_active_channels()))
248 i = name[*length - 1] - 1;
250 if (!(iter = ast_channel_iterator_all_new())) {
254 while ((chan = ast_channel_iterator_next(iter)) && i) {
255 ast_channel_unref(chan);
259 iter = ast_channel_iterator_destroy(iter);
265 *var_len = sizeof(long_ret);
267 ast_channel_lock(chan);
271 long_ret = name[*length - 1];
272 ret = (u_char *)&long_ret;
275 if (!ast_strlen_zero(ast_channel_name(chan))) {
276 ast_copy_string(string_ret, ast_channel_name(chan), sizeof(string_ret));
277 *var_len = strlen(string_ret);
278 ret = (u_char *)string_ret;
281 case ASTCHANLANGUAGE:
282 if (!ast_strlen_zero(ast_channel_language(chan))) {
283 ast_copy_string(string_ret, ast_channel_language(chan), sizeof(string_ret));
284 *var_len = strlen(string_ret);
285 ret = (u_char *)string_ret;
289 ast_copy_string(string_ret, ast_channel_tech(chan)->type, sizeof(string_ret));
290 *var_len = strlen(string_ret);
291 ret = (u_char *)string_ret;
293 case ASTCHANMUSICCLASS:
294 if (!ast_strlen_zero(ast_channel_musicclass(chan))) {
295 ast_copy_string(string_ret, ast_channel_musicclass(chan), sizeof(string_ret));
296 *var_len = strlen(string_ret);
297 ret = (u_char *)string_ret;
301 if ((bridge = ast_channel_bridge_peer(chan)) != NULL) {
302 ast_copy_string(string_ret, ast_channel_name(bridge), sizeof(string_ret));
303 *var_len = strlen(string_ret);
304 ret = (u_char *)string_ret;
305 ast_channel_unref(bridge);
309 if (ast_channel_masq(chan) && !ast_strlen_zero(ast_channel_name(ast_channel_masq(chan)))) {
310 ast_copy_string(string_ret, ast_channel_name(ast_channel_masq(chan)), sizeof(string_ret));
311 *var_len = strlen(string_ret);
312 ret = (u_char *)string_ret;
316 if (ast_channel_masqr(chan) && !ast_strlen_zero(ast_channel_name(ast_channel_masqr(chan)))) {
317 ast_copy_string(string_ret, ast_channel_name(ast_channel_masqr(chan)), sizeof(string_ret));
318 *var_len = strlen(string_ret);
319 ret = (u_char *)string_ret;
322 case ASTCHANWHENHANGUP:
323 if (!ast_tvzero(*ast_channel_whentohangup(chan))) {
324 gettimeofday(&tval, NULL);
325 long_ret = difftime(ast_channel_whentohangup(chan)->tv_sec, tval.tv_sec) * 100 - tval.tv_usec / 10000;
326 ret= (u_char *)&long_ret;
330 if (ast_channel_appl(chan)) {
331 ast_copy_string(string_ret, ast_channel_appl(chan), sizeof(string_ret));
332 *var_len = strlen(string_ret);
333 ret = (u_char *)string_ret;
337 if (ast_channel_data(chan)) {
338 ast_copy_string(string_ret, ast_channel_data(chan), sizeof(string_ret));
339 *var_len = strlen(string_ret);
340 ret = (u_char *)string_ret;
344 ast_copy_string(string_ret, ast_channel_context(chan), sizeof(string_ret));
345 *var_len = strlen(string_ret);
346 ret = (u_char *)string_ret;
348 case ASTCHANMACROCONTEXT:
349 ast_copy_string(string_ret, ast_channel_macrocontext(chan), sizeof(string_ret));
350 *var_len = strlen(string_ret);
351 ret = (u_char *)string_ret;
353 case ASTCHANMACROEXTEN:
354 ast_copy_string(string_ret, ast_channel_macroexten(chan), sizeof(string_ret));
355 *var_len = strlen(string_ret);
356 ret = (u_char *)string_ret;
358 case ASTCHANMACROPRI:
359 long_ret = ast_channel_macropriority(chan);
360 ret = (u_char *)&long_ret;
363 ast_copy_string(string_ret, ast_channel_exten(chan), sizeof(string_ret));
364 *var_len = strlen(string_ret);
365 ret = (u_char *)string_ret;
368 long_ret = ast_channel_priority(chan);
369 ret = (u_char *)&long_ret;
371 case ASTCHANACCOUNTCODE:
372 if (!ast_strlen_zero(ast_channel_accountcode(chan))) {
373 ast_copy_string(string_ret, ast_channel_accountcode(chan), sizeof(string_ret));
374 *var_len = strlen(string_ret);
375 ret = (u_char *)string_ret;
378 case ASTCHANFORWARDTO:
379 if (!ast_strlen_zero(ast_channel_call_forward(chan))) {
380 ast_copy_string(string_ret, ast_channel_call_forward(chan), sizeof(string_ret));
381 *var_len = strlen(string_ret);
382 ret = (u_char *)string_ret;
385 case ASTCHANUNIQUEID:
386 ast_copy_string(string_ret, ast_channel_uniqueid(chan), sizeof(string_ret));
387 *var_len = strlen(string_ret);
388 ret = (u_char *)string_ret;
390 case ASTCHANCALLGROUP:
391 long_ret = ast_channel_callgroup(chan);
392 ret = (u_char *)&long_ret;
394 case ASTCHANPICKUPGROUP:
395 long_ret = ast_channel_pickupgroup(chan);
396 ret = (u_char *)&long_ret;
399 long_ret = ast_channel_state(chan) & 0xffff;
400 ret = (u_char *)&long_ret;
403 long_ret = ast_channel_state(chan) & AST_STATE_MUTE ? 1 : 2;
404 ret = (u_char *)&long_ret;
407 long_ret = ast_channel_rings(chan);
408 ret = (u_char *)&long_ret;
411 if (ast_channel_dialed(chan)->number.str) {
412 ast_copy_string(string_ret, ast_channel_dialed(chan)->number.str, sizeof(string_ret));
413 *var_len = strlen(string_ret);
414 ret = (u_char *)string_ret;
418 if (ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str) {
419 ast_copy_string(string_ret, ast_channel_caller(chan)->id.number.str, sizeof(string_ret));
420 *var_len = strlen(string_ret);
421 ret = (u_char *)string_ret;
425 if (ast_channel_caller(chan)->id.name.valid && ast_channel_caller(chan)->id.name.str) {
426 ast_copy_string(string_ret, ast_channel_caller(chan)->id.name.str, sizeof(string_ret));
427 *var_len = strlen(string_ret);
428 ret = (u_char *)string_ret;
432 if (ast_channel_caller(chan)->ani.number.valid && ast_channel_caller(chan)->ani.number.str) {
433 ast_copy_string(string_ret, ast_channel_caller(chan)->ani.number.str, sizeof(string_ret));
434 *var_len = strlen(string_ret);
435 ret = (u_char *)string_ret;
438 case ASTCHANCIDRDNIS:
439 if (ast_channel_redirecting(chan)->from.number.valid && ast_channel_redirecting(chan)->from.number.str) {
440 ast_copy_string(string_ret, ast_channel_redirecting(chan)->from.number.str, sizeof(string_ret));
441 *var_len = strlen(string_ret);
442 ret = (u_char *)string_ret;
446 long_ret = ast_party_id_presentation(&ast_channel_caller(chan)->id);
447 ret = (u_char *)&long_ret;
450 long_ret = ast_channel_caller(chan)->ani2;
451 ret = (u_char *)&long_ret;
454 long_ret = ast_channel_caller(chan)->id.number.plan;
455 ret = (u_char *)&long_ret;
458 long_ret = ast_channel_dialed(chan)->transit_network_select;
459 ret = (u_char *)&long_ret;
461 case ASTCHANAMAFLAGS:
462 long_ret = ast_channel_amaflags(chan);
463 ret = (u_char *)&long_ret;
466 long_ret = ast_channel_adsicpe(chan);
467 ret = (u_char *)&long_ret;
469 case ASTCHANTONEZONE:
470 if (ast_channel_zone(chan)) {
471 ast_copy_string(string_ret, ast_channel_zone(chan)->country, sizeof(string_ret));
472 *var_len = strlen(string_ret);
473 ret = (u_char *)string_ret;
476 case ASTCHANHANGUPCAUSE:
477 long_ret = ast_channel_hangupcause(chan);
478 ret = (u_char *)&long_ret;
480 case ASTCHANVARIABLES:
481 if (pbx_builtin_serialize_variables(chan, &out)) {
482 *var_len = ast_str_strlen(out);
483 ret = (u_char *)ast_str_buffer(out);
488 for (bit = 0; bit < 8; bit++)
489 bits_ret[0] |= ((ast_channel_flags(chan)->flags & (1 << bit)) >> bit) << (7 - bit);
491 for (bit = 0; bit < 8; bit++)
492 bits_ret[1] |= (((ast_channel_flags(chan)->flags >> 8) & (1 << bit)) >> bit) << (7 - bit);
496 case ASTCHANTRANSFERCAP:
497 long_ret = ast_channel_transfercapability(chan);
498 ret = (u_char *)&long_ret;
503 ast_channel_unlock(chan);
504 chan = ast_channel_unref(chan);
509 static u_char *ast_var_channel_types(struct variable *vp, oid *name, size_t *length,
510 int exact, size_t *var_len, WriteMethod **write_method)
512 static unsigned long long_ret;
513 struct ast_variable *channel_types, *next;
515 if (header_generic(vp, name, length, exact, var_len, write_method))
518 if (vp->magic != ASTCHANTYPECOUNT)
521 for (long_ret = 0, channel_types = next = ast_channeltype_list(); next; next = next->next)
523 ast_variables_destroy(channel_types);
525 return (u_char *)&long_ret;
528 static u_char *ast_var_channel_types_table(struct variable *vp, oid *name, size_t *length,
529 int exact, size_t *var_len, WriteMethod **write_method)
531 const struct ast_channel_tech *tech = NULL;
532 struct ast_variable *channel_types, *next;
533 static unsigned long long_ret;
534 struct ast_channel *chan;
537 if (header_simple_table(vp, name, length, exact, var_len, write_method, -1))
540 channel_types = ast_channeltype_list();
541 for (i = 1, next = channel_types; next && i != name[*length - 1]; next = next->next, i++)
544 tech = ast_get_channel_tech(next->name);
545 ast_variables_destroy(channel_types);
546 if (next == NULL || tech == NULL)
550 case ASTCHANTYPEINDEX:
551 long_ret = name[*length - 1];
552 return (u_char *)&long_ret;
553 case ASTCHANTYPENAME:
554 *var_len = strlen(tech->type);
555 return (u_char *)tech->type;
556 case ASTCHANTYPEDESC:
557 *var_len = strlen(tech->description);
558 return (u_char *)tech->description;
559 case ASTCHANTYPEDEVSTATE:
560 long_ret = tech->devicestate ? 1 : 2;
561 return (u_char *)&long_ret;
562 case ASTCHANTYPEINDICATIONS:
563 long_ret = tech->indicate ? 1 : 2;
564 return (u_char *)&long_ret;
565 case ASTCHANTYPETRANSFER:
566 long_ret = tech->transfer ? 1 : 2;
567 return (u_char *)&long_ret;
568 case ASTCHANTYPECHANNELS:
570 struct ast_channel_iterator *iter;
574 if (!(iter = ast_channel_iterator_all_new())) {
578 while ((chan = ast_channel_iterator_next(iter))) {
579 if (ast_channel_tech(chan) == tech) {
582 chan = ast_channel_unref(chan);
585 ast_channel_iterator_destroy(iter);
587 return (u_char *)&long_ret;
595 static u_char *ast_var_channel_bridge(struct variable *vp, oid *name, size_t *length,
596 int exact, size_t *var_len, WriteMethod **write_method)
598 static unsigned long long_ret;
599 struct ast_channel *chan = NULL;
600 struct ast_channel_iterator *iter;
604 if (header_generic(vp, name, length, exact, var_len, write_method)) {
608 if (!(iter = ast_channel_iterator_all_new())) {
612 while ((chan = ast_channel_iterator_next(iter))) {
613 ast_channel_lock(chan);
614 if (ast_channel_is_bridged(chan)) {
617 ast_channel_unlock(chan);
618 chan = ast_channel_unref(chan);
621 ast_channel_iterator_destroy(iter);
623 *var_len = sizeof(long_ret);
625 return (vp->magic == ASTCHANBRIDGECOUNT) ? (u_char *) &long_ret : NULL;
628 static u_char *ast_var_Config(struct variable *vp, oid *name, size_t *length,
629 int exact, size_t *var_len, WriteMethod **write_method)
631 static unsigned long long_ret;
634 if (header_generic(vp, name, length, exact, var_len, write_method))
639 gettimeofday(&tval, NULL);
640 long_ret = difftime(tval.tv_sec, ast_startuptime.tv_sec) * 100 + tval.tv_usec / 10000 - ast_startuptime.tv_usec / 10000;
641 return (u_char *)&long_ret;
642 case ASTCONFRELOADTIME:
643 gettimeofday(&tval, NULL);
644 if (ast_lastreloadtime.tv_sec)
645 long_ret = difftime(tval.tv_sec, ast_lastreloadtime.tv_sec) * 100 + tval.tv_usec / 10000 - ast_lastreloadtime.tv_usec / 10000;
647 long_ret = difftime(tval.tv_sec, ast_startuptime.tv_sec) * 100 + tval.tv_usec / 10000 - ast_startuptime.tv_usec / 10000;
648 return (u_char *)&long_ret;
651 return (u_char *)&long_ret;
653 *var_len = strlen(ast_config_AST_SOCKET);
654 return (u_char *)ast_config_AST_SOCKET;
655 case ASTCONFACTIVECALLS:
656 long_ret = ast_active_calls();
657 return (u_char *)&long_ret;
658 case ASTCONFPROCESSEDCALLS:
659 long_ret = ast_processed_calls();
660 return (u_char *)&long_ret;
667 static u_char *ast_var_indications(struct variable *vp, oid *name, size_t *length,
668 int exact, size_t *var_len, WriteMethod **write_method)
670 static unsigned long long_ret;
671 static char ret_buf[128];
672 struct ast_tone_zone *tz = NULL;
674 if (header_generic(vp, name, length, exact, var_len, write_method))
680 struct ao2_iterator i;
684 i = ast_tone_zone_iterator_init();
685 while ((tz = ao2_iterator_next(&i))) {
686 tz = ast_tone_zone_unref(tz);
689 ao2_iterator_destroy(&i);
691 return (u_char *) &long_ret;
694 tz = ast_get_indication_zone(NULL);
696 ast_copy_string(ret_buf, tz->country, sizeof(ret_buf));
697 *var_len = strlen(ret_buf);
698 tz = ast_tone_zone_unref(tz);
699 return (u_char *) ret_buf;
709 static u_char *ast_var_indications_table(struct variable *vp, oid *name, size_t *length,
710 int exact, size_t *var_len, WriteMethod **write_method)
712 static unsigned long long_ret;
713 static char ret_buf[256];
714 struct ast_tone_zone *tz = NULL;
716 struct ao2_iterator iter;
718 if (header_simple_table(vp, name, length, exact, var_len, write_method, -1)) {
722 i = name[*length - 1] - 1;
724 iter = ast_tone_zone_iterator_init();
726 while ((tz = ao2_iterator_next(&iter)) && i) {
727 tz = ast_tone_zone_unref(tz);
730 ao2_iterator_destroy(&iter);
738 ast_tone_zone_unref(tz);
739 long_ret = name[*length - 1];
740 return (u_char *)&long_ret;
742 ast_copy_string(ret_buf, tz->country, sizeof(ret_buf));
743 ast_tone_zone_unref(tz);
744 *var_len = strlen(ret_buf);
745 return (u_char *) ret_buf;
747 /* No longer exists */
748 ast_tone_zone_unref(tz);
750 case ASTINDDESCRIPTION:
751 ast_tone_zone_lock(tz);
752 ast_copy_string(ret_buf, tz->description, sizeof(ret_buf));
753 ast_tone_zone_unlock(tz);
754 ast_tone_zone_unref(tz);
755 *var_len = strlen(ret_buf);
756 return (u_char *) ret_buf;
758 ast_tone_zone_unref(tz);
764 static int countmodule(const char *mod, const char *desc, int use, const char *status, const char *like)
769 static u_char *ast_var_Modules(struct variable *vp, oid *name, size_t *length,
770 int exact, size_t *var_len, WriteMethod **write_method)
772 static unsigned long long_ret;
774 if (header_generic(vp, name, length, exact, var_len, write_method))
777 if (vp->magic != ASTMODCOUNT)
780 long_ret = ast_update_module_list(countmodule, NULL);
782 return (u_char *)&long_ret;
785 static u_char *ast_var_Version(struct variable *vp, oid *name, size_t *length,
786 int exact, size_t *var_len, WriteMethod **write_method)
788 static unsigned long long_ret;
790 if (header_generic(vp, name, length, exact, var_len, write_method))
796 const char *version = ast_get_version();
797 *var_len = strlen(version);
798 return (u_char *)version;
801 sscanf(ast_get_version_num(), "%30lu", &long_ret);
802 return (u_char *)&long_ret;
809 static int term_asterisk_mib(int majorID, int minorID, void *serverarg, void *clientarg)
811 unregister_sysORTable(asterisk_oid, OID_LENGTH(asterisk_oid));
815 static void init_asterisk_mib(void)
817 static struct variable4 asterisk_vars[] = {
818 {ASTVERSTRING, ASN_OCTET_STR, RONLY, ast_var_Version, 2, {ASTVERSION, ASTVERSTRING}},
819 {ASTVERTAG, ASN_UNSIGNED, RONLY, ast_var_Version, 2, {ASTVERSION, ASTVERTAG}},
820 {ASTCONFUPTIME, ASN_TIMETICKS, RONLY, ast_var_Config, 2, {ASTCONFIGURATION, ASTCONFUPTIME}},
821 {ASTCONFRELOADTIME, ASN_TIMETICKS, RONLY, ast_var_Config, 2, {ASTCONFIGURATION, ASTCONFRELOADTIME}},
822 {ASTCONFPID, ASN_INTEGER, RONLY, ast_var_Config, 2, {ASTCONFIGURATION, ASTCONFPID}},
823 {ASTCONFSOCKET, ASN_OCTET_STR, RONLY, ast_var_Config, 2, {ASTCONFIGURATION, ASTCONFSOCKET}},
824 {ASTCONFACTIVECALLS, ASN_GAUGE, RONLY, ast_var_Config, 2, {ASTCONFIGURATION, ASTCONFACTIVECALLS}},
825 {ASTCONFPROCESSEDCALLS, ASN_COUNTER, RONLY, ast_var_Config, 2, {ASTCONFIGURATION, ASTCONFPROCESSEDCALLS}},
826 {ASTMODCOUNT, ASN_INTEGER, RONLY, ast_var_Modules , 2, {ASTMODULES, ASTMODCOUNT}},
827 {ASTINDCOUNT, ASN_INTEGER, RONLY, ast_var_indications, 2, {ASTINDICATIONS, ASTINDCOUNT}},
828 {ASTINDCURRENT, ASN_OCTET_STR, RONLY, ast_var_indications, 2, {ASTINDICATIONS, ASTINDCURRENT}},
829 {ASTINDINDEX, ASN_INTEGER, RONLY, ast_var_indications_table, 4, {ASTINDICATIONS, ASTINDTABLE, 1, ASTINDINDEX}},
830 {ASTINDCOUNTRY, ASN_OCTET_STR, RONLY, ast_var_indications_table, 4, {ASTINDICATIONS, ASTINDTABLE, 1, ASTINDCOUNTRY}},
831 {ASTINDALIAS, ASN_OCTET_STR, RONLY, ast_var_indications_table, 4, {ASTINDICATIONS, ASTINDTABLE, 1, ASTINDALIAS}},
832 {ASTINDDESCRIPTION, ASN_OCTET_STR, RONLY, ast_var_indications_table, 4, {ASTINDICATIONS, ASTINDTABLE, 1, ASTINDDESCRIPTION}},
833 {ASTCHANCOUNT, ASN_GAUGE, RONLY, ast_var_channels, 2, {ASTCHANNELS, ASTCHANCOUNT}},
834 {ASTCHANINDEX, ASN_INTEGER, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANINDEX}},
835 {ASTCHANNAME, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANNAME}},
836 {ASTCHANLANGUAGE, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANLANGUAGE}},
837 {ASTCHANTYPE, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANTYPE}},
838 {ASTCHANMUSICCLASS, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANMUSICCLASS}},
839 {ASTCHANBRIDGE, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANBRIDGE}},
840 {ASTCHANMASQ, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANMASQ}},
841 {ASTCHANMASQR, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANMASQR}},
842 {ASTCHANWHENHANGUP, ASN_TIMETICKS, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANWHENHANGUP}},
843 {ASTCHANAPP, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANAPP}},
844 {ASTCHANDATA, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANDATA}},
845 {ASTCHANCONTEXT, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANCONTEXT}},
846 {ASTCHANMACROCONTEXT, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANMACROCONTEXT}},
847 {ASTCHANMACROEXTEN, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANMACROEXTEN}},
848 {ASTCHANMACROPRI, ASN_INTEGER, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANMACROPRI}},
849 {ASTCHANEXTEN, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANEXTEN}},
850 {ASTCHANPRI, ASN_INTEGER, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANPRI}},
851 {ASTCHANACCOUNTCODE, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANACCOUNTCODE}},
852 {ASTCHANFORWARDTO, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANFORWARDTO}},
853 {ASTCHANUNIQUEID, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANUNIQUEID}},
854 {ASTCHANCALLGROUP, ASN_UNSIGNED, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANCALLGROUP}},
855 {ASTCHANPICKUPGROUP, ASN_UNSIGNED, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANPICKUPGROUP}},
856 {ASTCHANSTATE, ASN_INTEGER, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANSTATE}},
857 {ASTCHANMUTED, ASN_INTEGER, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANMUTED}},
858 {ASTCHANRINGS, ASN_INTEGER, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANRINGS}},
859 {ASTCHANCIDDNID, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANCIDDNID}},
860 {ASTCHANCIDNUM, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANCIDNUM}},
861 {ASTCHANCIDNAME, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANCIDNAME}},
862 {ASTCHANCIDANI, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANCIDANI}},
863 {ASTCHANCIDRDNIS, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANCIDRDNIS}},
864 {ASTCHANCIDPRES, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANCIDPRES}},
865 {ASTCHANCIDANI2, ASN_INTEGER, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANCIDANI2}},
866 {ASTCHANCIDTON, ASN_INTEGER, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANCIDTON}},
867 {ASTCHANCIDTNS, ASN_INTEGER, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANCIDTNS}},
868 {ASTCHANAMAFLAGS, ASN_INTEGER, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANAMAFLAGS}},
869 {ASTCHANADSI, ASN_INTEGER, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANADSI}},
870 {ASTCHANTONEZONE, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANTONEZONE}},
871 {ASTCHANHANGUPCAUSE, ASN_INTEGER, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANHANGUPCAUSE}},
872 {ASTCHANVARIABLES, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANVARIABLES}},
873 {ASTCHANFLAGS, ASN_OCTET_STR, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANFLAGS}},
874 {ASTCHANTRANSFERCAP, ASN_INTEGER, RONLY, ast_var_channels_table, 4, {ASTCHANNELS, ASTCHANTABLE, 1, ASTCHANTRANSFERCAP}},
875 {ASTCHANTYPECOUNT, ASN_INTEGER, RONLY, ast_var_channel_types, 2, {ASTCHANNELS, ASTCHANTYPECOUNT}},
876 {ASTCHANTYPEINDEX, ASN_INTEGER, RONLY, ast_var_channel_types_table, 4, {ASTCHANNELS, ASTCHANTYPETABLE, 1, ASTCHANTYPEINDEX}},
877 {ASTCHANTYPENAME, ASN_OCTET_STR, RONLY, ast_var_channel_types_table, 4, {ASTCHANNELS, ASTCHANTYPETABLE, 1, ASTCHANTYPENAME}},
878 {ASTCHANTYPEDESC, ASN_OCTET_STR, RONLY, ast_var_channel_types_table, 4, {ASTCHANNELS, ASTCHANTYPETABLE, 1, ASTCHANTYPEDESC}},
879 {ASTCHANTYPEDEVSTATE, ASN_INTEGER, RONLY, ast_var_channel_types_table, 4, {ASTCHANNELS, ASTCHANTYPETABLE, 1, ASTCHANTYPEDEVSTATE}},
880 {ASTCHANTYPEINDICATIONS, ASN_INTEGER, RONLY, ast_var_channel_types_table, 4, {ASTCHANNELS, ASTCHANTYPETABLE, 1, ASTCHANTYPEINDICATIONS}},
881 {ASTCHANTYPETRANSFER, ASN_INTEGER, RONLY, ast_var_channel_types_table, 4, {ASTCHANNELS, ASTCHANTYPETABLE, 1, ASTCHANTYPETRANSFER}},
882 {ASTCHANTYPECHANNELS, ASN_GAUGE, RONLY, ast_var_channel_types_table, 4, {ASTCHANNELS, ASTCHANTYPETABLE, 1, ASTCHANTYPECHANNELS}},
883 {ASTCHANBRIDGECOUNT, ASN_GAUGE, RONLY, ast_var_channel_bridge, 3, {ASTCHANNELS, ASTCHANSCALARS, ASTCHANBRIDGECOUNT}},
886 register_sysORTable(asterisk_oid, OID_LENGTH(asterisk_oid),
887 "ASTERISK-MIB implementation for Asterisk.");
889 REGISTER_MIB("res_snmp", asterisk_vars, variable4, asterisk_oid);
891 snmp_register_callback(SNMP_CALLBACK_LIBRARY,
892 SNMP_CALLBACK_SHUTDOWN,
893 term_asterisk_mib, NULL);
899 * c-file-offsets: ((case-label . 0))
901 * indent-tabs-mode: t