2
This program reads events from ITO server or agent event stream and
3
writes them to standard output. Its main task is to be a link between
4
ITO and external message processing application (e.g. correlation engine).
6
This program takes 2 commandline parameters:
8
MSI interface - name used internally by ITO to denote the interface that
9
is used for passing messages to this program. You can
10
pick up arbitrary name, provided that it meets naming
11
convention used by ITO (see ITO Application Integration
12
Guide for more information). Generally, using up to 12
13
a-z characters as a name should be safe.
14
reopen timeout - if there has been no new data for a given number of
15
seconds, reopen the interface. Using 0 as a value
19
Compiling on ITO server (tested on HPUX running ITO5.3):
20
gcc -o itostream itostream.c -L/opt/OV/lib -lopcsv -lnsp
22
Compiling on ITO agent:
23
gcc -o itostream itostream.c -DAGENT -L/opt/OV/lib -lopc -lnsp
25
Since ITO agent installation is sometimes broken, you might not have libopc
26
in /opt/OV/lib (which normally is just a symbolic link to libopc_r or some
27
other library in the same directory). In that case you could just try:
28
gcc -o itostream itostream.c -DAGENT -L/opt/OV/lib -lopc_r -lnsp
30
Compiled program needs root-privileges for running.
31
If ITO shared libraries are not found when starting the program, recompile
32
with additional options -Xlinker -rpath /opt/OV/lib
35
#include <stdio.h> /* stdio stuff */
36
#include <stdlib.h> /* free(), atoi() */
37
#include <unistd.h> /* sleep() */
40
#include "/opt/OV/include/opcapi.h" /* ITO agent-side stuff */
42
#include "/opt/OV/include/opcsvapi.h" /* ITO server-side stuff */
45
#define ERRORMSGSIZE 1024
46
#define SLEEPEMPTY 1 /* sleep on empty input before new read attempt */
47
#define SLEEPOPEN 3 /* sleep between closing and reopening the input */
49
void error_msg(int code, char *text)
54
opcdata_get_error_msg(code, &ptr, &size);
55
strncpy(text, ptr, size);
62
int open_if(char *ifname)
65
char errortext[ERRORMSGSIZE];
70
ret = opcif_open(OPCAGTIF_EXTMSGPROC_READWRITE, ifname, OPCIF_SV_RUNNING |
71
OPCIF_READ_NOWAIT | OPCIF_IGNORE_MSI_ALREADY_EXISTS, 0, &interface);
73
ret = opcif_open(OPCSVIF_EXTMSGPROC_READWRITE, ifname, OPCIF_SV_RUNNING |
74
OPCIF_READ_NOWAIT | OPCIF_IGNORE_MSI_ALREADY_EXISTS, 0, &interface);
77
if (ret != OPC_ERR_OK) {
79
error_msg(ret, errortext);
82
"Error opening MSI interface \"%s\": %s\n", ifname, errortext);
87
ret = opcif_register(interface, 0, 0);
89
if (ret != OPC_ERR_OK) {
91
error_msg(ret, errortext);
94
"Error registering condition with MSI interface \"%s\": %s\n",
97
opcif_close(interface);
107
void find_sev(int severity, char *text)
112
case OPC_SEV_UNCHANGED:
113
strcpy(text, "unchanged");
116
case OPC_SEV_UNKNOWN:
117
strcpy(text, "unknown");
121
strcpy(text, "normal");
124
case OPC_SEV_WARNING:
125
strcpy(text, "warning");
128
case OPC_SEV_CRITICAL:
129
strcpy(text, "critical");
133
strcpy(text, "minor");
137
strcpy(text, "major");
146
int main(int argc, char **argv)
149
int reopen, sleepcounter;
151
char errortext[ERRORMSGSIZE];
156
char *id, *app, *obj, *node;
157
char *msg_group, *msg_text;
163
"Usage: %s <MSI interface name> <reopen timeout>\n", argv[0]);
167
/* set stdout buffering to line mode
168
(needed if stdout was redirected to a file or to a pipe) */
169
setvbuf(stdout, 0, _IOLBF, 0);
171
interface = open_if(argv[1]);
172
reopen = atoi(argv[2]);
174
opcdata_create(OPCDTYPE_EMPTY, &msg);
180
ret = opcif_read(interface, msg);
188
id = opcdata_get_str(msg, OPCDATA_MSGID);
189
time = opcdata_get_long(msg, OPCDATA_CREATION_TIME);
190
severity = opcdata_get_long(msg, OPCDATA_SEVERITY);
191
node = opcdata_get_str(msg, OPCDATA_NODENAME);
192
app = opcdata_get_str(msg, OPCDATA_APPLICATION);
193
obj = opcdata_get_str(msg, OPCDATA_OBJECT);
194
msg_group = opcdata_get_str(msg, OPCDATA_GROUP);
195
msg_text = opcdata_get_str(msg, OPCDATA_MSGTEXT);
197
find_sev(severity, sevtext);
199
printf("id=%s time=%ld sev=%s node=%s app=%s obj=%s msg_grp=%s msg_text=%s\n",
200
id, time, sevtext, node, app, obj, msg_group, msg_text);
204
case OPC_ERR_NO_DATA:
207
sleepcounter += SLEEPEMPTY;
209
if (reopen && sleepcounter >= reopen) {
211
fprintf(stderr, "Reopening MSI interface \"%s\"\n", argv[1]);
213
opcif_close(interface);
215
interface = open_if(argv[1]);
222
error_msg(ret, errortext);
224
fprintf(stderr, "Error reading from MSI interface \"%s\": %s\n",
228
opcif_close(interface);