xref: /illumos-gate/usr/src/lib/fm/libfmd_snmp/common/init.c (revision 598f4ceed9327d2d6c2325dd67cae3aa06f7fea6)
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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <fm/fmd_snmp.h>
28 #include <net-snmp/net-snmp-config.h>
29 #include <net-snmp/net-snmp-includes.h>
30 #include <net-snmp/agent/net-snmp-agent-includes.h>
31 #include "sunFM_impl.h"
32 #include "module.h"
33 #include "resource.h"
34 #include "problem.h"
35 
36 static const sunFm_table_t sun_fm_tables[] = {
37 	TABLE_REG(sunFmModuleTable),
38 	TABLE_REG(sunFmResourceTable),
39 	TABLE_REG(sunFmProblemTable),
40 	TABLE_REG(sunFmFaultEventTable),
41 	TABLE_NULL
42 };
43 
44 /*
45  * This is our entry point for initialization by the agent, which
46  * (for reasons unknown) ignores the return value.  The name is fixed
47  * by the agent API.
48  */
49 int
50 init_sunFM(void)
51 {
52 	int			max_err = MIB_REGISTERED_OK;
53 	const sunFm_table_t	*table;
54 
55 	for (table = sun_fm_tables; table->t_name != NULL; table++) {
56 		int err = table->t_init();
57 
58 		switch (err) {
59 		case MIB_REGISTERED_OK:
60 			DEBUGMSGTL((MODNAME_STR, "registered table %s\n",
61 			    table->t_name));
62 			break;
63 		case MIB_DUPLICATE_REGISTRATION:
64 			(void) snmp_log(LOG_ERR, MODNAME_STR
65 			    ": table %s initialization failed: duplicate "
66 			    "registration\n", table->t_name);
67 			break;
68 		case MIB_REGISTRATION_FAILED:
69 			(void) snmp_log(LOG_ERR, MODNAME_STR
70 			    ": table %s initialization failed: agent "
71 			    "registration failure\n", table->t_name);
72 			break;
73 		default:
74 			(void) snmp_log(LOG_ERR, MODNAME_STR
75 			    ": table %s initialization failed: "
76 			    "unknown reason\n", table->t_name);
77 		}
78 
79 		if (err > max_err)
80 			max_err = err;
81 	}
82 
83 	return (max_err);
84 }
85