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, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright (c) 1998 by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 #include <string.h>
30 #include <stdio.h>
31 #include <sys/types.h>
32 #include <limits.h>
33 #include <stdlib.h>
34 #include <netinet/in.h>
35 #include <arpa/inet.h>
36
37 #include "error.h"
38 #include "snmp.h"
39 #include "trap.h"
40 #include "madman_trap.h"
41
42
43 /***** LOCAL CONSTANTS *****/
44
45
46 /***** LOCAL VARIABLES *****/
47
48 static Subid applName_subids[] = { 1, 3, 6, 1, 2, 1, 27, 1, 1, 2, 0 };
49 static Oid applName_name = { applName_subids, 11 };
50
51 static Subid applOperStatus_subids[] = { 1, 3, 6, 1, 2, 1, 27, 1, 1, 6, 0 };
52 static Oid applOperStatus_name = { applOperStatus_subids, 11 };
53
54 static Subid alarmId_subids[] = { 1, 3, 6, 1, 4, 1, 42, 2, 8, 2, 3, 1, 0 };
55 static Oid alarmId_name = { alarmId_subids, 13 };
56
57 static Subid alarmSeverity_subids[] = { 1, 3, 6, 1, 4, 1, 42, 2, 8, 2, 3, 2, 0 };
58 static Oid alarmSeverity_name = { alarmSeverity_subids, 13 };
59
60 static Subid alarmDescr_subids[] = { 1, 3, 6, 1, 4, 1, 42, 2, 8, 2, 3, 3, 0 };
61 static Oid alarmDescr_name = { alarmDescr_subids, 13 };
62
63
64 /***********************************************************************/
65
send_trap_appl_status_changed(int applIndex,char * applName,int applOperStatus)66 void send_trap_appl_status_changed(int applIndex, char *applName, int applOperStatus)
67 {
68 SNMP_variable *list = NULL;
69 SNMP_value value;
70
71
72 /* applName */
73 value.v_string.chars = (u_char *) applName;
74 if(applName == NULL)
75 value.v_string.len = 0;
76 else
77 /* LINTED */
78 value.v_string.len = (int32_t)strlen(applName);
79 applName_name.subids[applName_name.len - 1] = applIndex;
80 list = snmp_typed_variable_append(list, &applName_name,
81 STRING, &value, error_label);
82 if(list == NULL)
83 {
84 error("send_trap_appl_status_changed(%d, %s, %d) failed: %s",
85 applIndex, applName, applOperStatus,
86 error_label);
87 return;
88 }
89
90
91 /* applOperStatus */
92 value.v_integer = applOperStatus;
93 applOperStatus_name.subids[applOperStatus_name.len - 1] = applIndex;
94 list = snmp_typed_variable_append(list, &applOperStatus_name,
95 INTEGER, &value, error_label);
96 if(list == NULL)
97 {
98 error("send_trap_appl_status_changed(%d, %s, %d) failed: %s",
99 applIndex, applName, applOperStatus,
100 error_label);
101 return;
102 }
103
104
105 if(trap_send_to_all_destinators(NULL,
106 SNMP_TRAP_ENTERPRISESPECIFIC, TRAP_APPL_ALARM,
107 list, error_label))
108 {
109 error("send_trap_appl_status_changed(%d, %s, %d) failed: %s",
110 applIndex, applName, applOperStatus,
111 error_label);
112 snmp_variable_list_free(list);
113 return;
114 }
115 snmp_variable_list_free(list);
116
117
118 return;
119 }
120
121
122 /***********************************************************************/
123
send_trap_appl_alarm(int applIndex,char * applName,int alarmId,int alarmSeverity,char * alarmDescr)124 void send_trap_appl_alarm(int applIndex, char *applName, int alarmId, int alarmSeverity, char *alarmDescr)
125 {
126 SNMP_variable *list = NULL;
127 SNMP_value value;
128
129
130 /* applName */
131 value.v_string.chars = (u_char *) applName;
132 if(applName == NULL)
133 value.v_string.len = 0;
134 else
135 /* LINTED */
136 value.v_string.len = (int32_t)strlen(applName);
137 applName_name.subids[applName_name.len - 1] = applIndex;
138 list = snmp_typed_variable_append(list, &applName_name,
139 STRING, &value, error_label);
140 if(list == NULL)
141 {
142 error("send_trap_appl_alarm(%d, %s, %d, %d, %s) failed: %s",
143 applIndex, applName, alarmId, alarmSeverity, alarmDescr,
144 error_label);
145 return;
146 }
147
148
149 /* alarmId */
150 value.v_integer = alarmId;
151 list = snmp_typed_variable_append(list, &alarmId_name,
152 INTEGER, &value, error_label);
153 if(list == NULL)
154 {
155 error("send_trap_appl_alarm(%d, %s, %d, %d, %s) failed: %s",
156 applIndex, applName, alarmId, alarmSeverity, alarmDescr,
157 error_label);
158 return;
159 }
160
161
162 /* alarmSeverity */
163 value.v_integer = alarmSeverity;
164 list = snmp_typed_variable_append(list, &alarmSeverity_name,
165 INTEGER, &value, error_label);
166 if(list == NULL)
167 {
168 error("send_trap_appl_alarm(%d, %s, %d, %d, %s) failed: %s",
169 applIndex, applName, alarmId, alarmSeverity, alarmDescr,
170 error_label);
171 return;
172 }
173
174
175 /* alarmDescr */
176 value.v_string.chars = (u_char *) alarmDescr;
177 if(alarmDescr == NULL)
178 value.v_string.len = 0;
179 else
180 /* LINTED */
181 value.v_string.len = (int32_t)strlen(alarmDescr);
182 list = snmp_typed_variable_append(list, &alarmDescr_name,
183 STRING, &value, error_label);
184 if(list == NULL)
185 {
186 error("send_trap_appl_alarm(%d, %s, %d, %d, %s) failed: %s",
187 applIndex, applName, alarmId, alarmSeverity, alarmDescr,
188 error_label);
189 return;
190 }
191
192
193 if(trap_send_to_all_destinators(NULL,
194 SNMP_TRAP_ENTERPRISESPECIFIC, TRAP_APPL_ALARM,
195 list, error_label))
196 {
197 error("send_trap_appl_alarm(%d, %s, %d, %d, %s) failed: %s",
198 applIndex, applName, alarmId, alarmSeverity, alarmDescr,
199 error_label);
200 snmp_variable_list_free(list);
201 return;
202 }
203 snmp_variable_list_free(list);
204
205
206 return;
207 }
208
209
210 /***********************************************************************/
211
alarmSeverity_string(int severity)212 char *alarmSeverity_string(int severity)
213 {
214 static char buffer[20] = "";
215
216
217 switch(severity)
218 {
219 case SEVERITY_LOW:
220 sprintf(buffer, "low");
221 break;
222 case SEVERITY_MEDIUM:
223 sprintf(buffer, "medium");
224 break;
225 case SEVERITY_HIGH:
226 sprintf(buffer, "high");
227 break;
228 default:
229 sprintf(buffer, "unknown(%d)", severity);
230 break;
231 }
232
233 return buffer;
234 }
235
236
237