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.
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.
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]
23 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
26 #include <sys/types.h>
28 #include <fm/fmd_api.h>
29 #include <sys/fm/protocol.h>
30 #include <sys/fm/util.h>
31 #include <sys/sysevent.h>
35 static evchan_t
*fmevt_outbound_chan
;
37 static struct fmevt_outbound_stats
{
38 fmd_stat_t recv_calls
;
40 fmd_stat_t recv_ireport
;
41 fmd_stat_t recv_other
;
42 fmd_stat_t fwd_success
;
43 fmd_stat_t fwd_failure
;
45 { "outbound_recv_calls", FMD_TYPE_UINT64
,
46 "total events received for forwarding" },
47 { "outbound_cat1class_list", FMD_TYPE_UINT64
,
48 "events received matching list.*" },
49 { "outbound_cat1class_ireport", FMD_TYPE_UINT64
,
50 "events received matching ireport.*" },
51 { "outbound_cat1class_other", FMD_TYPE_UINT64
,
52 "events of other classes" },
53 { "outbound_fwd_success", FMD_TYPE_UINT64
,
54 "events forwarded successfully" },
55 { "outbound_fwd_failure", FMD_TYPE_UINT64
,
56 "events we failed to forward" }
59 #define BUMPSTAT(stat) outbound_stats.stat.fmds_value.ui64++
62 * In the .conf file we subscribe to list.* and ireport.* event classes.
63 * Any additions to that set could cause some unexpected behaviour.
64 * For example adding fault.foo won't work (since we don't publish
65 * faults directly but only within a list.suspect) but we will get
66 * any list.* including fault.foo as a suspect.
70 fmevt_recv(fmd_hdl_t
*hdl
, fmd_event_t
*ep
, nvlist_t
*nvl
, const char *class)
74 if (strncmp(class, "list.", 5) == 0)
76 else if (strncmp(class, "ireport.", 8) == 0)
77 BUMPSTAT(recv_ireport
);
81 if (sysevent_evc_publish(fmevt_outbound_chan
, class, "",
82 SUNW_VENDOR
, FM_PUB
, nvl
, EVCH_SLEEP
) == 0) {
83 BUMPSTAT(fwd_success
);
85 BUMPSTAT(fwd_failure
);
86 fmd_hdl_debug(hdl
, "sysevent_evc_publish failed:");
91 fmevt_init_outbound(fmd_hdl_t
*hdl
)
93 int32_t channel_depth
;
97 if (fmd_prop_get_int32(hdl
, "protocol_forward_disable") == B_TRUE
) {
98 fmd_hdl_debug(hdl
, "protocol forwarding disabled "
99 "through .conf file setting\n");
103 (void) fmd_stat_create(hdl
, FMD_STAT_NOALLOC
, sizeof (outbound_stats
) /
104 sizeof (fmd_stat_t
), (fmd_stat_t
*)&outbound_stats
);
107 * Allow simulation environment to change outbound channel name.
109 channel_name
= fmd_prop_get_string(hdl
, "outbound_channel");
111 if (sysevent_evc_bind(channel_name
, &fmevt_outbound_chan
,
112 EVCH_CREAT
| EVCH_HOLD_PEND_INDEF
) != 0) {
113 fmd_hdl_abort(hdl
, "Unable to bind channel %s",
118 channel_depth
= fmd_prop_get_int32(hdl
, "outbound_channel_depth");
120 if (sysevent_evc_control(fmevt_outbound_chan
, EVCH_SET_CHAN_LEN
,
121 (uint32_t)channel_depth
) != 0) {
122 fmd_hdl_abort(hdl
, "Unable to set depth of channel %s to %d",
123 channel_name
, channel_depth
);
125 fmd_prop_free_string(hdl
, channel_name
);
127 nvl
= fmd_nvl_alloc(hdl
, FMD_SLEEP
);
128 (void) nvlist_add_nvlist(nvl
, "fmdauth",
129 (nvlist_t
*)fmd_hdl_fmauth(hdl
));
130 (void) sysevent_evc_setpropnvl(fmevt_outbound_chan
, nvl
);
137 fmevt_fini_outbound(fmd_hdl_t
*hdl
)
139 if (fmevt_outbound_chan
!= NULL
) {
140 (void) sysevent_evc_unbind(fmevt_outbound_chan
);
141 fmevt_outbound_chan
= NULL
;