xref: /illumos-gate/usr/src/lib/fm/libfmd_snmp/common/init.c (revision 581cede61ac9c14d8d4ea452562a567189eead78)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <fm/fmd_snmp.h>
30 #include <net-snmp/net-snmp-config.h>
31 #include <net-snmp/net-snmp-includes.h>
32 #include <net-snmp/agent/net-snmp-agent-includes.h>
33 #include "sunFM_impl.h"
34 #include "module.h"
35 #include "resource.h"
36 #include "problem.h"
37 
38 static const sunFm_table_t sun_fm_tables[] = {
39 	TABLE_REG(sunFmModuleTable),
40 	TABLE_REG(sunFmResourceTable),
41 	TABLE_REG(sunFmProblemTable),
42 	TABLE_REG(sunFmFaultEventTable),
43 	TABLE_NULL
44 };
45 
46 /*
47  * This is our entry point for initialization by the agent, which
48  * (for reasons unknown) ignores the return value.  The name is fixed
49  * by the agent API.
50  */
51 int
52 init_sunFM(void)
53 {
54 	int			max_err = MIB_REGISTERED_OK;
55 	const sunFm_table_t	*table;
56 
57 	for (table = sun_fm_tables; table->t_name != NULL; table++) {
58 		int err = table->t_init();
59 
60 		switch (err) {
61 		case MIB_REGISTERED_OK:
62 			DEBUGMSGTL((MODNAME_STR, "registered table %s\n",
63 			    table->t_name));
64 			break;
65 		case MIB_DUPLICATE_REGISTRATION:
66 			(void) snmp_log(LOG_ERR, MODNAME_STR
67 			    ": table %s initialization failed: duplicate "
68 			    "registration\n", table->t_name);
69 			break;
70 		case MIB_REGISTRATION_FAILED:
71 			(void) snmp_log(LOG_ERR, MODNAME_STR
72 			    ": table %s initialization failed: agent "
73 			    "registration failure\n", table->t_name);
74 			break;
75 		default:
76 			snmp_log(LOG_ERR, MODNAME_STR
77 			    ": table %s initialization failed: "
78 			    "unknown reason\n", table->t_name);
79 		}
80 
81 		if (err > max_err)
82 			max_err = err;
83 	}
84 
85 	return (max_err);
86 }
87