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_NULL
41 };
42
43 /*
44 * This is our entry point for initialization by the agent, which
45 * (for reasons unknown) ignores the return value. The name is fixed
46 * by the agent API.
47 */
48 int
49 init_sunFM(void)
50 {
51 static int once = 0;
52 int max_err = MIB_REGISTERED_OK;
53 const sunFm_table_t *table;
54
55 if (once != 0)
56 return (MIB_DUPLICATE_REGISTRATION);
57
58 for (table = sun_fm_tables; table->t_name != NULL; table++) {
59 int err = table->t_init();
60
61 switch (err) {
62 case MIB_REGISTERED_OK:
63 DEBUGMSGTL((MODNAME_STR, "registered table %s\n",
64 table->t_name));
65 break;
66 case MIB_DUPLICATE_REGISTRATION:
67 (void) snmp_log(LOG_ERR, MODNAME_STR
68 ": table %s initialization failed: duplicate "
69 "registration\n", table->t_name);
70 break;
71 case MIB_REGISTRATION_FAILED:
72 (void) snmp_log(LOG_ERR, MODNAME_STR
73 ": table %s initialization failed: agent "
74 "registration failure\n", table->t_name);
75 break;
76 default:
77 (void) snmp_log(LOG_ERR, MODNAME_STR
78 ": table %s initialization failed: "
79 "unknown reason\n", table->t_name);
80 }
81
82 if (err > max_err)
83 max_err = err;
84 }
85
86 once = 1;
87 return (max_err);
88 }