/********************************************************************** * * (c) Copyright DIGITAL EQUIPMENT CORPORATION 1992. ALL * RIGHTS RESERVED. UNPUBLISHED - RIGHTS RESERVED UNDER * APPLICABLE COPYRIGHT LAWS. * * RESTRICTED RIGHTS LEGEND: USE, DUPLICATION, OR DISCLOSURE * BY THE U.S. GOVERNMENT IS SUBJECT TO RESTRICTIONS AS SET * FORTH IN SUBPARAGRAPH (C) (1) (ii) OF DFARS 252.227-7013, OR * IN FAR 52.227-19, OR IN FAR 52.227-14 ALT.III, AS * APPLICABLE. * * DIGITAL distributes this software as a sample program for a * remote source to inter-operate with DECmcc Data Collector * AM. Solely to facilitate this interoperation, DIGITAL grants * without fee, the right to copy, distribute, or modify this * software at their sole risk, provided this copyright notice * and disclaimer appears in all copies so made, distributed or * modified. * * This software can not be resold for any other purpose * without obtaining permission from Digital Equipment Corp. * Digital makes no claims that this software will perform any * particular function, will perform a similar function with * another release of DECmcc, that DECmcc future versions will * interoperate with this software, or that a similar software * will be made available in any future releases. The user of * this software is responsible to modify and test it * adequately for any desired functions that they desire. * * DIGITAL retains the rights of authorship of the program. * Access to this software in no way limits Digital's ownership * of the Data Collector AM, any DECmcc software component, or * DECmcc as a whole. Nor does access to this software imply any * current or future rights to use DECmcc. All rights to use * DECmcc and/or any of its componenents are detailed in the * various licenses of those components and are in no way * abrogated by access to this sample. * * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE * WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED AS A COMMITMENT * BY DIGITAL OR ITS THIRD PARTY SUPPLIERS * * DIGITAL AND ITS THIRD PARTY SUPPLIERS, ASSUME NO * RESPONSIBILITY FOR THE USE OR INABILITY TO USE ANY OF ITS * SOFTWARE . THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT * WARRANTY OF ANY KIND, AND DIGITAL EXPRESSLY DISCLAIMS ALL * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE. * * DEC, DECmcc, and the Digital logo are trademarks of * Digital Equipment Corporation. * ***********************************************************************/ /******************************************************************** * * Routine: mcc_evc_send * * FACILITY: MCC -- Management Control Center * * ABSTRACT: * * This is a sample program that allows users to use command line arguments to * build a data collector event structure. This structure is used to send an * event to a DECmcc Data Collector event sink via the MCC EVC API routine * mcc_send_event(). * * * ENVIRONMENT: * * This code should work on VMS or Ultrix. * * AUTHOR: MCC Development * * CREATION DATE: June 1991 * * MODIFICATION HISTORY: * * Version Date Reviser Reason * -------- ----------- ------------- ---------------------------- * 1.0 June 91 J. L. creation * 1.1 Jan 92 DWM revised to accept command * line args * 1.1 Jan 92 DWM Move to ULTRIX; clean up; * allow for MiXeD CaSe for * "severity"; fix to send * hostname from ULTRIX systems * T1.4.0 Sept-1994 F. AMRANI Cleaning * * T1.4.1 Nov-1994 F. AMRANI Ft_QAR_140 #13 * pb description: * If the length of the argv[]'s are not checked * Solution: * use strncpy instead of strcp * ******************************************************************************/ /******************************************************************************************************** * * HOW TO BUILD THIS SAMPLE PROGRAM: * * On ULTRIX: * % cc -Dunix -g -o mcc_evc_send mcc_evc_api.c mcc_evc_api_dna_unix.c * mcc_evc_send.c -ldnet * * On VMS: * $ cc /define=VMS mcc_evc_send.c, mcc_evc_api.c, mcc_evc_api_dna.c * $ link mcc_evc_send.obj, mcc_evc_api.obj, mcc_evc_api_dna.obj * ********************************************************************************************************/ #include #include #include #include #include #ifdef vms #include #include #include #include #include #include #include #include #else #include #include #include #include #include #endif #include #include #include "mcc_evc_api_def.h" /* external routines */ MCC_T_Unsigned32 mcc_send_event(); /* Because this routine is not linked with mmshell_unix, must define a dummy * routine */ MCC_T_CVR mcc_xmm_log() { return(MCC_S_NORMAL); } /* Routine: main Description: This code is responsible for parsing out the command line arguments and using them to fill in the fields for an event to send to a Data Collector event sink. This program is very unforgiving in a few ways: 1. You must specify ALL arguments or indicate the string is empty by passing a null string (i.e. "") 2. Strings that contain spaces in them must be contained by double quotes. (e.g. "A string with spaces") 3. Arguments must be in a specific order. They must be specified in the following order: - DESTINATION: The DECnet node name or address of the DECmcc system running the DataCollector event sink. - COLLECTOR: The name of the DECmcc collector that is intended to receive this event - TARGET: An (optional) target entity to which DECmcc Notfication Services can 're-vector' the event notification. If a Target Entity is not wanted (other than the Colllector icon, then this argument must be passed in as a null string (""). - TITLE: The title you wish to give the General Event. Note: since Notification Services' filters work based on strings within the event title, it is advisable to make the title string descriptive, but brief. - TEXT: The actual text of the event. If there are spaces in the event text, then it must be enclosed within double quotes. (I.e. "This is the event text"). - SEVERITY: The severity of the event. This can be specified as any of the following: Critical Major Minor Warning Indeterminate Clear If this argument is not specified (it must, however, be entered on the command line as a null string: "") or is un-parsable, the program will send the event with a severity of "INDETERMINATE" */ main(int argc, char* argv[]) { evc_t_cs cs_destination, /* counted string */ cs_collection_name, /* see mcc_evc_include.h */ cs_event_title, cs_event_time, /* CharAbsTime ?*/ cs_event_text, cs_event_target; MCC_T_Unsigned32 protocol_code, /* Transport protocol to use */ rs = 0, /* Return status indicator */ event_severity, /* Integer encoding of the event's severity */ status; /* Status from gethostname() */ time_t curtime; #ifdef vms char *p_env = "SYS$NODE"; /* Used to indicate the source of the event in case */ /* the sender leaves the field empty on the command line.*/ #endif char *destination, *protocol, *collector, *target, *title, *text, *severity; #ifdef unix #define MAXHOSTNAMELEN 64 /* From Stevens book */ int gethostname(); char name[MAXHOSTNAMELEN+1]; int namelen; #endif /* Display the command line format and arguments if user passed in a * "?" or didn't specify any args. */ if (argc < 2 ) { printf("\nFormat: command \n"); exit(rs); } if (!strcmp(argv[1],"?")) { printf("\nFormat: command \n"); exit(rs); } /* Don't bother with incomplete command lines... */ if (argc < 7) { printf( "\nSupply all required arguments or null strings.\n"); printf( "\nFormat: command \n"); exit(rs); } /* Copy the command line args into more 'meaningful' variable names. */ destination = argv[1]; /* Event destination */ collector = argv[2]; /* Collector name */ target = argv[3]; /* Event Target */ title = argv[4]; /* Event Title */ text = argv[5]; /* Event text */ severity = argv[6]; /* Event Severity */ if ( argv[7] != NULL ) /* if protocol type is supplied */ { protocol = argv[7]; while(*argv[7] !='\0') /* convert to uppercase */ { *argv[7] = (char)toupper((int)*argv[7]); ++argv[7]; } } /* Convert the text of the severity field to all uppercase severity */ while(*argv[6] !='\0') { *argv[6] = (char)toupper((int)*argv[6]); ++argv[6]; } /* Fill in Destination (node to send events to) */ if (!strcmp((char*)destination, "")) { printf("\nMust supply a destination node for the event.\n"); exit(rs); } else /**** BEGIN-MCC_FT_QAR_140#13-FA-112994 ****/ { strncpy((char*)cs_destination.cs_string,destination,EVC_T_COUNTED_STRING_LENGTH-1); cs_destination.cs_string[EVC_T_COUNTED_STRING_LENGTH-1] = '\0'; cs_destination.cs_count = strlen((char*)cs_destination.cs_string); } /* V1.3 UDP support, fill in "protocol". If not provided, default to DECnet */ if ( ( argv[7] == NULL ) || ( !strcmp(protocol,"UDPIP")) ) protocol_code = EVC_PROTOCOL_UDP; else { if (!strcmp(protocol,"DECNET")) protocol_code = EVC_PROTOCOL_DNA; else { printf("\n Supported transport protocols are: DECnet or UDPIP\n"); exit(rs); } } /* Fill in Collector */ if (!strcmp(collector,"")) { printf("\nMust supply a collector name for the event.\n"); exit(rs); } else { strncpy((char*)cs_collection_name.cs_string,collector,EVC_T_COUNTED_STRING_LENGTH-1); cs_collection_name.cs_string[EVC_T_COUNTED_STRING_LENGTH-1]='\0'; cs_collection_name.cs_count = strlen((char*)cs_collection_name.cs_string); } /* Fill in Target Entity */ memset( &( cs_event_target.cs_string[0] ), '\0', EVC_T_COUNTED_STRING_LENGTH ); strncpy(cs_event_target.cs_string,target,EVC_T_COUNTED_STRING_LENGTH-1); cs_event_target.cs_count = strlen( cs_event_target.cs_string ); /* Fill in the event Title */ memset( &( cs_event_title.cs_string[0] ), '\0', EVC_T_COUNTED_STRING_LENGTH ); if (!strcmp(title,"")) { strncpy((char*)cs_event_title.cs_string,"Event: ",EVC_T_COUNTED_STRING_LENGTH-1); cs_event_title.cs_count = strlen((char*)cs_event_title.cs_string); } else { strncpy((char*)cs_event_title.cs_string, title, EVC_T_COUNTED_STRING_LENGTH-1); cs_event_title.cs_count = strlen((char*)cs_event_title.cs_string); } /* Fill in the event Text */ memset( &( cs_event_text.cs_string[0] ), '\0', EVC_T_COUNTED_STRING_LENGTH ); if (!strcmp(text,"")) { /* Handle how to fill in a 'generic' */ /* event from the system, in case they */ /* specify a null string as the event */ /* text: */ /* */ #ifdef vms /* CASE 1: */ sprintf( cs_event_text.cs_string, "General event from %s", getenv( p_env ) ); /* If we're sending from a VMS system, */ #endif /* we'll include the DECnet nodename in */ /* the event message. */ /* */ /* CASE 2: */ #ifdef unix /* If we're sending from a UNIX[1] system */ status = gethostname(name,namelen); /* then we'll include the full hostname */ if (status == 0) { /* in the event message. */ sprintf((MCC_T_CHAR*)cs_event_text.cs_string,"General event from %s",name);/* */ } /* [1] UNIX is a registered footnote of */ else { /* UNIX Systems Laboratories. */ sprintf((MCC_T_CHAR*)cs_event_text.cs_string, "General event from unknown source."); }; #endif cs_event_text.cs_count = strlen((char*)cs_event_text.cs_string); } else { strncpy((char*)cs_event_text.cs_string,text,EVC_T_COUNTED_STRING_LENGTH-1); /* Otherwise, copy whatever they gave */ cs_event_text.cs_count = strlen((char*)cs_event_text.cs_string); /* into the buffer and be done with it. */ } /* Fill in the severity */ if (!strcmp(severity,"INDETERMINATE")) /* Check the event severity passed in. If null or un-parseable the */ event_severity = SEVRTY_INDETERMINATE; /* program will send the the default value of '0' indicating a severity */ /* of "Indeterminate". */ else if (!strcmp(severity,"CRITICAL")) event_severity = SEVRTY_CRITICAL; else if (!strcmp(severity,"MAJOR")) event_severity = SEVRTY_MAJOR; else if (!strcmp(severity,"MINOR")) event_severity = SEVRTY_MINOR; else if (!strcmp(severity,"WARNING")) event_severity = SEVRTY_WARNING; else if (!strcmp(severity,"CLEAR")) event_severity = SEVRTY_CLEAR; else event_severity = SEVRTY_INDETERMINATE; /* Fill in the Event Time stamp */ memset((char*) &( cs_event_time.cs_string[0] ), '\0', EVC_T_COUNTED_STRING_LENGTH ); time( &curtime ); if ( curtime == -1 ) strncpy ((char*)cs_event_time.cs_string, "Not Available",EVC_T_COUNTED_STRING_LENGTH-1); else strncpy ((char*)cs_event_time.cs_string, ctime( &curtime ), EVC_T_COUNTED_STRING_LENGTH-1); cs_event_time.cs_count = strlen((char*) cs_event_time.cs_string ); /**** END-MCC_FT_QAR_140#13-FA-112994 ****/ /* Specify the Protocol to use */ /* protocol = EVC_PROTOCOL_DNA; * Hard-wired for DECnet V1.2 */ #ifdef debug /* check what you think you're sending over the wire... */ printf("\n Event destination: %s", cs_destination.cs_string); printf("\n Collector name: %s", cs_collection_name.cs_string); printf("\n Event target: %s", cs_event_target.cs_string); printf("\n Event title: %s", cs_event_title.cs_string); printf("\n Event text: %s", cs_event_text.cs_string); printf("\n Event local timestamp: %s", cs_event_time.cs_string); printf("\n Event severity text: %s", severity); printf("\n Event severity code: %d", event_severity); printf("\n Transport protocol: %s", protocol); printf("\n Transport protocol code: %d", protocol_code); printf("\n"); #endif /* Now send the event report */ rs = mcc_send_event ( &cs_destination, &protocol_code, &cs_collection_name, &cs_event_title, &cs_event_time, &event_severity, &cs_event_text, &cs_event_target ); #ifdef debug printf("\nSend status = %d\n", rs ); #endif exit(rs); }