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