| Olli,
the code segment below is NOT supported by the PCM team, although it does
work. I wrote it as an exercise to check out the API for Phil.
Cheers SImon......
/* Routine to send events from the PSWX action interface in to the ENS
subsystem. This routine will use the example read file descriptor 0
routine described in dca.h and will send the data in to ENS through
the CMUserSendEvent() call in to ENS.
Most of this code is really used to translate between the values
of the data presented by PSWX and the event attributes supported by
ENS.
*/
/*
Declarations
*/
#include <stdio.h>
#include <time.h>
#include "dca.h"
#include <console.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/errno.h>
FILE *Errors;
CMContext ENS_Context;
char* class = "PSWX";
char info[512];
char* text;
int priority;
char* subsystem;
char* source = "PSWX";
int My_index;
time_t event_time;
int status;
char* name = "PSWX";
char *ErrString;
/* I am declaring a couple of structuure types here for convenience as
I have to be able to translate the priority names to ENS priority
integers and the PSWX code to an ENS subsystem.
*/
typedef struct _PswPriorities
{
char *PswPriority;
int ENSPriority;
} PswPriorities;
typedef struct _PswCodes
{
char *code;
char *subsystem;
} PswCodes;
/* Here we will declare the array of the possible values of the PSW
event code and the corresponding ENS subsystem which will be passed
in the subsystem field of the packet.
*/
PswCodes EventCode[] =
{
{"PSW_C_EXT","Unknown"},
{"PSW_C_CPU","CPU"},
{"PSW_C_MEM","Memory"},
{"PSW_C_DSK","Disk"},
{"PSW_C_ETH","Ethernet"},
{"PSW_C_HSC","Disk"},
{"PSW_C_CIC","Bus"},
{"PSW_C_PRS","Printer"},
{"PSW_C_LOP","Software"},
{"PSW_C_DNF","Disk"},
{"PSW_C_DSS","Disk"},
{"PSW_C_DQP","Printer"},
{"PSW_C_BQP","Batch"},
{"PSW_C_QCP","Batch"},
{"PSW_C_BAT","Batch"},
{"PSW_C_DMM","Memory"},
{"PSW_C_SWL","Disk"},
{"PSW_C_PRO","Software"},
{"PSW_C_SHS","Disk"},
{"PSW_C_ILL","Software"},
{"PSW_C_SMP","CPU"},
{"PSW_C_UNR","Software"},
{"PSW_C_ORS","Software"},
{"PSW_C_UNK","Software"},
{"PSW_C_TIM","Software"},
{"PSW_C_WDM","Software"},
{"PSW_C_OTH","Unknown"},
{"PSW_C_VAL","Software"},
{"PSW_C_PSW","Software"},
{NULL, NULL}
};
/* Here we will declare the array of the possible values of the PSW
severity and the corresponding ENS priority which will be passed
in the priority field of the packet.
*/
PswPriorities Priorities[] =
{
{"Fatal",CMPriorityCritical},
{"Error",CMPriorityMajor},
{"Warning",CMPriorityWarning},
{"Success",CMPriorityClear},
{"Information",CMPriorityIndeterminate},
{NULL, 0}
};
/*
Main routine. This don't need to initialise the ENS callable
interface as we are only sending events so we will just set up
PSWX interface and then format the packets we require.
*/
main ()
{
actor_packet_type PSW_Packet;
/* Loop to Read Packet from File Descriptor 0 */
while (read(0,&PSW_Packet,sizeof(actor_packet_type))>0)
{
if (strlen(PSW_Packet.message) == 0 )
{
continue;
}
/* Got a packet now we need to format it to send to ENS */
/*
We need to format from the PSWX packet or supply defaults
for each of the following:
PSWX ENS
Node System
"PSWX Event" Name
"PSWX" class
Req_str Information (this will be set up to reflect
whether this is new event,updated
event or deleted event from PSWX).
message Text
- Time
severity priority
event_str subsystem ( this is converted in a lookup table)
"PSWX" Source
*/
/*
First lets make up the Information Field from the Req String and
the message from PSWX.
*/
if ((strncasecmp(PSW_Packet.req_str,
"PSW_C_NEW",strlen("PSW_C_NEW"))) == 0 )
{
sprintf( info,"Message from PSW: %s", PSW_Packet.message);
}
if ((strncasecmp(PSW_Packet.req_str,
"PSW_C_UPD",strlen("PSW_C_UPD"))) == 0 )
{
sprintf( info,"Update from PSW: %s", PSW_Packet.message);
}
if ((strncasecmp(PSW_Packet.req_str,
"PSW_C_REM",strlen("PSW_C_REM"))) == 0 )
{
sprintf( info,"Cleared PSW message %s", PSW_Packet.message);
}
/*
Next comes the priority and we shall use the conversion tables
created above. If it is a remove event the priority will be
set to clear in all cases.
*/
if ((strncasecmp(PSW_Packet.req_str,
"PSW_C_REM",strlen("PSW_C_REM"))) == 0 )
{
priority = CMPriorityClear;
}
else
{
My_index = 0;
while (Priorities[My_index].PswPriority != NULL)
{
if (strcasecmp(PSW_Packet.severity_lvl,
Priorities[My_index].PswPriority) == 0)
{
priority = Priorities[My_index].ENSPriority;
break;
}
My_index++;
}
}
/*
Do the same as above to convert the subsystem to the right sort of
thing.
*/
My_index = 0;
while (EventCode[My_index].code != NULL)
{
if (strcmp(PSW_Packet.event_str,
EventCode[My_index].code) == 0)
{
subsystem = EventCode[My_index].subsystem;
break;
}
My_index++;
}
/* I think I have all I need. the time bit will be done in the call. */
event_time = time(0);
status = CMUserSendEvent(&ENS_Context,
PSW_Packet.node,
name,
class,
info,
PSW_Packet.message,
event_time,
priority,
subsystem,
source);
}
}
|