Writing Monitors for the Event Monitoring Service (December 1999)

Chapter 5 145
Writing a Target Application
Target Application Overview
Sample Code
rm_strerror() Format an error message to a buffer.
rm_uncompress() Converts a TCP/IP or UDP/IP notification message into
an EMS object.
Table 5-1 EMS API Functions Used by Target Applications
/*****************************************************************************/
/* TCP_TARGET.C */
/* Using the specified TCP port, waits for a message to arrive on that port.*/
/* */
/* To compile, type: */
/* cc -Ae -I/opt/resmon/devkit/source/resmon +DA1.1 +DS1.1 */
/* -DHPUX_VERSION=1020 -L/opt/resmon/lib */
/* -lresmon -o tcp_target tcp_target.c */
/* */
/* On HP-UX 11.0, use -DHPUX_VERSION=1100 */
/* */
/* Usage: */
/* 1) Invoke tcp_target application: $tcp_target <port> */
/* 2) Configure monitoring request to the TCP target port specified */
/* above. This can be done using the EMS GUI in SAM. */
/*****************************************************************************/
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <netdb.h>
#include <resmon.h>
#define HEADER_LEN 9
#define MAX_MESSAGES 2
void format_notify_object (rm_object_addr notify_obj);
void format_restart_object (rm_object_addr restart_obj);
/*****************************************************************************/
/* Name: main */
/* Description: Sets up TCP listen port based on input port number. */
/* Sits in loop waiting to: receive events, read data off */
/* of the socket, uncompress and call format routines. */
/* Arguments: port_number TCP port for receiving EMS events */
/*****************************************************************************/