init ems server code
This commit is contained in:
84
src/performanceMgr/c_program/cstaCollector/Makefile
Normal file
84
src/performanceMgr/c_program/cstaCollector/Makefile
Normal file
@@ -0,0 +1,84 @@
|
||||
#/bin/sh
|
||||
|
||||
# Makefile for cstaCollector Module.
|
||||
|
||||
CC = gcc
|
||||
CFLAGS=-g -Wall -I/usr/local/mysql/include
|
||||
CFLAGS.ES=-g -Wall -I/usr/include/mariadb
|
||||
|
||||
COMPILE.c=$(CC) $(CFLAGS)
|
||||
COMPILE.c.ES=$(CC) $(CFLAGS.ES)
|
||||
|
||||
LINK.c=$(CC) $(CFLAGS)
|
||||
LINK.c.ES=$(CC) $(CFLAGS.ES)
|
||||
|
||||
LINKFLAG=-L../../../omcLib/c_program/ftp -lftp \
|
||||
-L../../../../wxc2plat/snmp -lsnmp \
|
||||
-L../../../../wxc2plat/debug -ldebug \
|
||||
-L../../../../wxc2plat/iptrans -liptrans \
|
||||
-L../../../../wxc2plat/public -lpublic \
|
||||
-L/usr/local/mysql/lib -lmariadbclient -lz
|
||||
|
||||
LINKFLAG.ES=-L../../../omcLib/c_program/omcLib -lomcLib \
|
||||
-L../../../../plat/snmp/lib -lsnmp \
|
||||
-L../../../../plat/debug/lib -ldebug \
|
||||
-L../../../../plat/sccp/lib -lsccp \
|
||||
-L../../../../plat/iptrans/lib -liptrans \
|
||||
-L../../../../plat/public/lib -lpublic \
|
||||
-L/usr/lib/mysql -lmariadbclient -lz
|
||||
|
||||
PROGS=cstaCollector
|
||||
CSTA_OBJ = csta.o
|
||||
CSTA_OBJ.ES = csta.o.ES cstamain.o.ES
|
||||
|
||||
default: linuxES
|
||||
|
||||
all:
|
||||
@echo " **** Compiling $(PROGS) ****"
|
||||
@echo "make clean -- Delete the target files(*.o, *.a)"
|
||||
@echo "make linux72 -- Generate target files for Redhat Linux 7.2"
|
||||
@echo "make linuxES -- Generate target files for Redhat ES 4.0"
|
||||
|
||||
linux72: $(CSTA_OBJ) cstamain.o
|
||||
@echo Linking $(PROGS)
|
||||
@$(LINK.c) -o $(PROGS) cstamain.o $(CSTA_OBJ) $(LINKFLAG) -lm
|
||||
ar r libcsta.a $(CSTA_OBJ)
|
||||
rm -rf *.o
|
||||
rm -rf *bak
|
||||
rm -rf *~
|
||||
cp -f $(PROGS) ../../../bin
|
||||
cp -f $(PROGS) /usr/local/omc/bin/
|
||||
|
||||
linuxES: $(CSTA_OBJ.ES) cstamain.o.ES
|
||||
@echo Linking $(PROGS)
|
||||
@$(LINK.c.ES) -o $(PROGS) cstamain.o $(CSTA_OBJ) $(LINKFLAG.ES) -lm
|
||||
ar r libcsta.a $(CSTA_OBJ)
|
||||
# rm -rf *.o
|
||||
# rm -rf *bak
|
||||
# rm -rf *~
|
||||
# cp -f $(PROGS) ../../../../bin
|
||||
# cp -f $(PROGS) /usr/local/omc/bin/
|
||||
|
||||
installbin: linuxES
|
||||
cp -f $(PROGS) ../../../../bin/
|
||||
|
||||
installomc: linuxES
|
||||
cp -f $(PROGS) /usr/local/omc/bin/
|
||||
|
||||
installall: installbin installomc
|
||||
|
||||
cstamain.o: cstamain.c
|
||||
$(COMPILE.c) -c cstamain.c
|
||||
|
||||
csta.o: csta.c csta.h
|
||||
$(COMPILE.c) -c csta.c
|
||||
|
||||
cstamain.o.ES: cstamain.c
|
||||
$(COMPILE.c.ES) -c cstamain.c
|
||||
|
||||
csta.o.ES: csta.c csta.h
|
||||
$(COMPILE.c.ES) -c csta.c
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a $(PROGS)
|
||||
|
||||
1804
src/performanceMgr/c_program/cstaCollector/csta.c
Normal file
1804
src/performanceMgr/c_program/cstaCollector/csta.c
Normal file
File diff suppressed because it is too large
Load Diff
146
src/performanceMgr/c_program/cstaCollector/csta.h
Normal file
146
src/performanceMgr/c_program/cstaCollector/csta.h
Normal file
@@ -0,0 +1,146 @@
|
||||
#include <ctype.h>
|
||||
#include "../../../../plat/snmp/src/include/snmp.h"
|
||||
#include "../../../omcLib/c_program/omcLib/omcLib.h"
|
||||
#include "mysql.h"
|
||||
|
||||
#include "errmsg.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef __CSTA_HEAD_FILE
|
||||
#define __CSTA_HEAD_FILE
|
||||
|
||||
#ifndef _T_BYTE
|
||||
#define _T_BYTE
|
||||
typedef unsigned char BYTE;
|
||||
#endif
|
||||
|
||||
#ifndef _T_BOOL
|
||||
#define _T_BOOL
|
||||
typedef unsigned char BOOL;
|
||||
#endif
|
||||
|
||||
#ifndef _T_DWORD
|
||||
#define _T_DWORD
|
||||
typedef unsigned int DWORD;
|
||||
#endif
|
||||
|
||||
#ifndef _T_WORD
|
||||
#define _T_WORD
|
||||
typedef unsigned short WORD;
|
||||
#endif
|
||||
//=======================================================
|
||||
int csta_init();
|
||||
void csta_timer();
|
||||
|
||||
#ifndef CSTA_DEBUG
|
||||
#define CSTA_DEBUG 0
|
||||
#endif
|
||||
|
||||
#define CSTA_DB "CSTA_DB"
|
||||
#define CSTA_LOG_PATH "../log"
|
||||
#define LOG_FILE "../log/cstalog"
|
||||
#define OUTPUT_FILE_TIME_HOUR 4
|
||||
#define OUTPUT_FILE_TIME_MINUTE 30
|
||||
#define RECORD_KEEP_DAY 30
|
||||
#define CSTA_PORT 4954
|
||||
|
||||
#define MAX_SYSTEM_NUM 32
|
||||
#define MAX_OBJECT_NUM 16
|
||||
#define MAX_FIELD_NUM 512
|
||||
#define MAX_CSTA_SRC_NUM 64
|
||||
#define MAX_MSG_NUM 32
|
||||
|
||||
#define UPDATE_SYSTEM_INTERVAL 50*60
|
||||
#define CHASE_INTERVAL 50*4
|
||||
|
||||
#define TIMETO_NONE 0
|
||||
#define TIMETO_GET_CSTA 1
|
||||
#define TIMETO_OUTPUT_FILE 2
|
||||
#define TIMETO_CHANGE_LOG 3
|
||||
|
||||
#define STATE_NORMAL 0
|
||||
#define STATE_CHASE 1
|
||||
|
||||
#define STATE_MSG_NONE 0
|
||||
#define STATE_MSG_GET_REQUEST 1
|
||||
#define STATE_MSG_WAIT_RESPONSE 2
|
||||
|
||||
typedef struct csta_sys
|
||||
{
|
||||
DWORD request_id;
|
||||
int sysid;
|
||||
int subsysid;
|
||||
snmp_addr addr;
|
||||
int system_state;
|
||||
int msg_state;
|
||||
|
||||
int instance;
|
||||
int objindex;
|
||||
int id1;
|
||||
int id2;
|
||||
|
||||
//for retry
|
||||
int pre_instance;
|
||||
int pre_objindex;
|
||||
int pre_id1;
|
||||
int pre_id2;
|
||||
|
||||
int timeout;
|
||||
int fail;
|
||||
int retry;
|
||||
BYTE cstamsg[MAX_OBJECT_NUM][4096];
|
||||
unsigned long msglen;
|
||||
}csta_sys;
|
||||
|
||||
typedef struct csta_obj
|
||||
{
|
||||
int csta_type;
|
||||
int field_width;
|
||||
|
||||
int oidlen;
|
||||
DWORD oid[OID_MAXLEN];
|
||||
|
||||
int id1_start;
|
||||
int id1_end;
|
||||
int id1_offset;
|
||||
char id1_field[32];
|
||||
|
||||
int id2_start;
|
||||
int id2_end;
|
||||
int id2_offset;
|
||||
char id2_field[32];
|
||||
|
||||
char sql_detail[8192];
|
||||
char detail_field_list[MAX_FIELD_NUM][32];
|
||||
int detail_field_count;
|
||||
|
||||
char relate_table[64];
|
||||
|
||||
char sql_sum[8192];
|
||||
char sum_field_list[MAX_FIELD_NUM][32];
|
||||
int sum_field_count;
|
||||
|
||||
char detail_table[64];
|
||||
char sum_table[64];
|
||||
}csta_obj;
|
||||
|
||||
typedef struct csta_src
|
||||
{
|
||||
int sysTypeNo;
|
||||
int hassubsys;
|
||||
int sum_flag;
|
||||
int check_time_flag;
|
||||
int single_message_flag;
|
||||
csta_sys systems[MAX_SYSTEM_NUM];
|
||||
int systemCount;
|
||||
|
||||
csta_obj objects[MAX_OBJECT_NUM];
|
||||
int objectCount;
|
||||
|
||||
char csv_path[64];
|
||||
}csta_src;
|
||||
|
||||
|
||||
#endif
|
||||
184
src/performanceMgr/c_program/cstaCollector/cstamain.c
Normal file
184
src/performanceMgr/c_program/cstaCollector/cstamain.c
Normal file
@@ -0,0 +1,184 @@
|
||||
/*************************************************
|
||||
File name: cstamain.c
|
||||
Author: JianHui Zheng
|
||||
Version: 9:00:00
|
||||
Date: 2007-7-2
|
||||
Description:cstaCollectorģ<72><C4A3><EFBFBD><EFBFBD>main<69>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʹģ<CAB9><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>
|
||||
void iptrans_init();
|
||||
void snmp_init(int port);
|
||||
<09><><EFBFBD><EFBFBD>csta.c<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
void csta_init();
|
||||
|
||||
History:
|
||||
No.
|
||||
Author
|
||||
Date
|
||||
Version
|
||||
Description
|
||||
*************************************************/
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "csta.h"
|
||||
|
||||
static struct itimerval itimer, old_itimer;
|
||||
|
||||
void onCstaCollectorTimer();
|
||||
void setCstaCollectorTimer();
|
||||
void setup_daemon(void);
|
||||
int timerCounter = 0;
|
||||
|
||||
/*************************************************
|
||||
Function: // main
|
||||
Description: // main<69><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹģ<CAB9><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Calls: // iptrans_init; snmp_init; csta_init; setCstaCollectorTimer;
|
||||
Called By: // csta.c:csta_init;
|
||||
Table Accessed: //
|
||||
Table Updated: //
|
||||
Input: // int argc, char *argv[]
|
||||
Output: //
|
||||
Return: //
|
||||
Others: //
|
||||
*************************************************/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char runMode;
|
||||
|
||||
runMode = getopt(argc, argv, "d");
|
||||
|
||||
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD>в<EFBFBD><D0B2><EFBFBD>
|
||||
switch (runMode)
|
||||
{
|
||||
case 'd':
|
||||
setup_daemon();
|
||||
break;
|
||||
case '?':
|
||||
break;
|
||||
}
|
||||
|
||||
//IPƽ̨ģ<CCA8><C4A3><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
fprintf(stderr, "\n Calling iptrans_init() \n");
|
||||
iptrans_init();
|
||||
|
||||
//snmpģ<70><C4A3><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
fprintf(stderr, "\n Calling snmp_init() \n");
|
||||
snmp_init(4957);
|
||||
|
||||
//cstaCollectorģ<72><C4A3><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
fprintf(stderr, "\n Calling csta_init() \n");
|
||||
csta_init();
|
||||
|
||||
//<2F>趨<EFBFBD><E8B6A8>ʱ<EFBFBD><CAB1>
|
||||
setCstaCollectorTimer();
|
||||
while (1) {
|
||||
usleep(50);
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*************************************************
|
||||
Function: // onCstaCollectorTimer
|
||||
Description: // <20>趨<EFBFBD><E8B6A8>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Calls: // csta_timer;
|
||||
Called By: // setCstaCollectorTimer;
|
||||
Table Accessed: //
|
||||
Table Updated: //
|
||||
Input: // int argc; char *argv[];
|
||||
Output: //
|
||||
Return: //
|
||||
Others: //
|
||||
*************************************************/
|
||||
void onCstaCollectorTimer()
|
||||
{
|
||||
csta_timer();
|
||||
}
|
||||
|
||||
/*************************************************
|
||||
Function: // setCstaCollectorTimer
|
||||
Description: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Calls: // setitimer;
|
||||
Called By: // main;
|
||||
Table Accessed: //
|
||||
Table Updated: //
|
||||
Input: //
|
||||
Output: //
|
||||
Return: //
|
||||
Others: //
|
||||
*************************************************/
|
||||
void setCstaCollectorTimer()
|
||||
{
|
||||
struct sigaction act;
|
||||
act.sa_handler = onCstaCollectorTimer;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
if (sigaction(SIGALRM, &act, NULL) < 0) {
|
||||
perror("Produce Sigaction");
|
||||
exitLog("cstaCollector:setCstaCollectorTimer, sigaction function error");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
itimer.it_interval.tv_sec = 0;
|
||||
itimer.it_interval.tv_usec = 10 * 1000;
|
||||
itimer.it_value.tv_sec = 0;
|
||||
itimer.it_value.tv_usec = 10 * 1000;
|
||||
|
||||
if (setitimer(ITIMER_REAL, &itimer, &old_itimer) != 0) {
|
||||
printf("Setting Timer error! \n");
|
||||
exitLog("cstaCollector:setCstaCollectorTimer, setitimer function error");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************
|
||||
Function: // setup_daemon
|
||||
Description: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>̨<EFBFBD><CCA8><EFBFBD><EFBFBD>
|
||||
Calls: // fork;
|
||||
Called By: // main;
|
||||
Table Accessed: //
|
||||
Table Updated: //
|
||||
Input: //
|
||||
Output: //
|
||||
Return: //
|
||||
Others: //
|
||||
*************************************************/
|
||||
void setup_daemon(void)
|
||||
{
|
||||
|
||||
//<2F><><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>
|
||||
switch (fork())
|
||||
{
|
||||
case -1:
|
||||
{
|
||||
perror("setup_daemon(), 1st fork()");
|
||||
exit(2);
|
||||
}
|
||||
default:
|
||||
exit(0);
|
||||
case 0:
|
||||
if (setsid() == -1)
|
||||
{
|
||||
perror("setup_daemon(), setsid()");
|
||||
exit(3);
|
||||
}
|
||||
switch (fork())
|
||||
{
|
||||
case -1:
|
||||
{
|
||||
perror("setup_daemon(), 2nd fork()");
|
||||
exit(3);
|
||||
}
|
||||
|
||||
default:
|
||||
exit(0);
|
||||
case 0:
|
||||
umask(0);
|
||||
/* and return with daemon set up */
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
84
src/performanceMgr/c_program/logCollector/Makefile
Normal file
84
src/performanceMgr/c_program/logCollector/Makefile
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/bin/sh
|
||||
|
||||
CC = gcc
|
||||
CFLAGS=-D_REENTRANT -g -Wall
|
||||
|
||||
dbINCLUDE_FLAGS = -I/usr/local/mysql/include
|
||||
dbINCLUDE_FLAGS.ES = -I/usr/include/mariadb
|
||||
|
||||
LINKFLAG=-L../../../../wxc2plat/snmp -lsnmp \
|
||||
-L../../../omcLib/c_program/omcLib -lomcLib \
|
||||
-L../../../../wxc2plat/debug -ldebug \
|
||||
-L../../../../wxc2plat/iptrans -liptrans \
|
||||
-L../../../../wxc2plat/public -lpublic \
|
||||
-L/usr/local/mysql/lib -lmariadbclient -lz
|
||||
|
||||
LINKFLAG.ES=-L../../../../plat/snmp/lib -lsnmp \
|
||||
-L../../../omcLib/c_program/omcLib -lomcLib \
|
||||
-L../../../../plat/debug/lib -ldebug \
|
||||
-L../../../../plat/sccp/lib -lsccp \
|
||||
-L../../../../plat/iptrans/lib -liptrans \
|
||||
-L../../../../plat/public/lib -lpublic \
|
||||
-L/usr/lib/mysql -lmariadbclient -lz
|
||||
|
||||
COMPILE_SUFFIX = $(dbINCLUDE_FLAGS)
|
||||
COMPILE_SUFFIX.ES = $(dbINCLUDE_FLAGS.ES)
|
||||
|
||||
LINK_SUFFIX = $(dbINCLUDE_FLAGS) $(LINKFLAG)
|
||||
LINK_SUFFIX.ES = $(dbINCLUDE_FLAGS.ES) $(LINKFLAG.ES)
|
||||
|
||||
PROGS = logCollector
|
||||
|
||||
LOGCOLLECTOR_OBJ = logCollectorMain.o logCollector.o
|
||||
LOGCOLLECTOR_OBJ.ES = logCollectorMain.o.ES logCollector.o.ES
|
||||
|
||||
LIB_OBJ = logCollector.o
|
||||
LIB_OBJ.ES = logCollector.o.ES
|
||||
|
||||
default: linuxES
|
||||
|
||||
all:
|
||||
@echo " **** Compiling $(PROGS) ****"
|
||||
@echo "make clean -- Delete the target files"
|
||||
@echo "make linux72 -- Generate target files for Redhat Linux 72"
|
||||
@echo "make linuxES -- Generate target files for Redhat Linux ES"
|
||||
|
||||
linux72: $(LOGCOLLECTOR_OBJ)
|
||||
@echo Linking $(PROGS)
|
||||
@$(CC) $(CFLAGS) -o $(PROGS) $(LOGCOLLECTOR_OBJ) $(LINK_SUFFIX) -lm
|
||||
ar r liblogCollector.a $(LIB_OBJ)
|
||||
rm -f *.o core *~
|
||||
cp -f $(PROGS) ../../../bin/
|
||||
cp -f $(PROGS) /usr/local/omc/bin/
|
||||
|
||||
linuxES: $(LOGCOLLECTOR_OBJ.ES)
|
||||
@echo Linking $(PROGS)
|
||||
@$(CC) $(CFLAGS) -o $(PROGS) $(LOGCOLLECTOR_OBJ) $(LINK_SUFFIX.ES) -lm
|
||||
ar r liblogCollector.a $(LIB_OBJ)
|
||||
rm -f *.o core *~
|
||||
cp -f $(PROGS) ../../../../bin/
|
||||
cp -f $(PROGS) /usr/local/omc/bin/
|
||||
|
||||
installbin: linuxES
|
||||
cp -f $(PROGS) ../../../../bin/
|
||||
|
||||
installomc: linuxES
|
||||
cp -f $(PROGS) /usr/local/omc/bin/
|
||||
|
||||
installall: installbin installomc
|
||||
|
||||
logCollectorMain.o: logCollectorMain.c
|
||||
$(CC) $(CFLAGS) -c logCollectorMain.c $(dbINCLUDE_FLAGS)
|
||||
|
||||
logCollector.o: logCollector.c
|
||||
$(CC) $(CFLAGS) -c logCollector.c $(dbINCLUDE_FLAGS)
|
||||
|
||||
logCollectorMain.o.ES: logCollectorMain.c
|
||||
$(CC) $(CFLAGS) -c logCollectorMain.c $(dbINCLUDE_FLAGS.ES)
|
||||
|
||||
logCollector.o.ES: logCollector.c
|
||||
$(CC) $(CFLAGS) -c logCollector.c $(dbINCLUDE_FLAGS.ES)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a $(PROGS)
|
||||
|
||||
1102
src/performanceMgr/c_program/logCollector/logCollector.c
Normal file
1102
src/performanceMgr/c_program/logCollector/logCollector.c
Normal file
File diff suppressed because it is too large
Load Diff
118
src/performanceMgr/c_program/logCollector/logCollector.h
Normal file
118
src/performanceMgr/c_program/logCollector/logCollector.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/* Title: logCollector.h
|
||||
* Description:
|
||||
* Author:
|
||||
* Date:
|
||||
*/
|
||||
|
||||
#ifndef logCollector__H
|
||||
#define logCollector__H
|
||||
|
||||
#include "../../../../plat/public/src/include/asn1.h"
|
||||
#include "../../../../plat/snmp/src/include/snmp.h"
|
||||
#include "../../../omcLib/c_program/omcLib/omcLib.h"
|
||||
|
||||
#ifndef MYSQL_H
|
||||
#include "mysql.h"
|
||||
#endif
|
||||
|
||||
#ifndef logCollector_DEBUG
|
||||
#define logColl_DEBUG 0
|
||||
#endif
|
||||
|
||||
#define MaxLogSrcNum 16 //max number of command can be execute as same time
|
||||
#define MaxAttrDefnNum 256
|
||||
#define MaxOidLen 20 //max number of object ID
|
||||
#define MaxSubOidLen 10 //max number of sub object ID
|
||||
#define MaxVarNum 50 //max number of var in one pdu
|
||||
#define DefPort 4960 //define receive port
|
||||
#define HOSTNAME "localhost"
|
||||
#define PUB_DB "OMC_PUB" //OMC's public database
|
||||
#define SysConfTable "OMC_PUB.sysConf" //system config table
|
||||
#define logConfTable "OMC_PUB.sysLogSrcConf" //system config table
|
||||
#define IpTable "OMC_PUB.sysInfo" //system's IP table
|
||||
|
||||
//msgState flag define
|
||||
#define nIdle 0
|
||||
#define nWaitResponse 1
|
||||
|
||||
//logState flag define
|
||||
#define nGetInfo 0
|
||||
#define nGetLog 1
|
||||
#define nWaitLog 2
|
||||
|
||||
//snmp pdu type define [define in snmp.h]
|
||||
#define nGet 0
|
||||
#define nGetNext 1
|
||||
#define nResp 2
|
||||
#define nSet 3
|
||||
|
||||
#define nBgnOid 1
|
||||
#define nEndOid 2
|
||||
#define nDataOid 3
|
||||
|
||||
//snmp var type code
|
||||
#define nInteger 0x02
|
||||
#define nOctetString 0x04
|
||||
#define nNull 0x05
|
||||
#define nObjectId 0x06
|
||||
#define nNoSuchObject 0x80
|
||||
#define nNoSuchInstance 0x81
|
||||
#define nEndOfMibView 0x82
|
||||
|
||||
typedef struct unitAttrDefn {
|
||||
int sysTypeNo;
|
||||
int dataTypeNo;
|
||||
char fieldObjIdStr[16];
|
||||
char fieldName[64];
|
||||
int valueType;
|
||||
int valueLen;
|
||||
} unitAttrDefn;
|
||||
|
||||
typedef struct unitLogSrc {
|
||||
int isEnable;
|
||||
int sysTypeNo;
|
||||
int sysNo;
|
||||
int subSysNo;
|
||||
|
||||
int requestId;
|
||||
char dstIP[16];
|
||||
WORD dstPort;
|
||||
DWORD preObjId[20]; //the oid before x
|
||||
int preObjIdLen;
|
||||
int maxMsgLen;
|
||||
char snmpCommunity[16];
|
||||
|
||||
int dataTypeNo;
|
||||
int maxSizeOfRec;
|
||||
int maxRecNumOfBuf;
|
||||
int maxRecNumOfDay;
|
||||
char dataStoreTable[64]; //database.table
|
||||
int attrDefnArrOffset;
|
||||
int attrDefnNum;
|
||||
|
||||
unsigned long bgnNo;
|
||||
unsigned long endNo;
|
||||
unsigned long logNo;
|
||||
|
||||
BYTE logState; //-1:nFailed,0:nWaitProc,1:nNoFinish,2:nFinished
|
||||
BYTE msgState; //command process state:0=idle,1=waitResponse
|
||||
BYTE waitTimeCount; //the times number of timeout
|
||||
BYTE timeoutCount; //the timeCount
|
||||
|
||||
int sleepTime; //the time count of sleep to wait log
|
||||
int sleepCount; //tht count
|
||||
|
||||
int totalVarNum;
|
||||
int finishVarNum;
|
||||
|
||||
char desc[200];
|
||||
|
||||
//var_list info
|
||||
BYTE varNum;
|
||||
} unitLogSrc;
|
||||
|
||||
//Interface Functions Declare,define in logCollector.c
|
||||
int logCollectorInit();
|
||||
int logCollectorTimer();
|
||||
|
||||
#endif
|
||||
122
src/performanceMgr/c_program/logCollector/logCollectorMain.c
Normal file
122
src/performanceMgr/c_program/logCollector/logCollectorMain.c
Normal file
@@ -0,0 +1,122 @@
|
||||
/* Title: logCollectorMain.c
|
||||
* Description: test
|
||||
* Author:
|
||||
* Date:
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "logCollector.h"
|
||||
|
||||
static struct itimerval itimer, old_itimer;
|
||||
|
||||
void onTimer();
|
||||
void setTimer();
|
||||
void setup_daemon(void);
|
||||
int timerCounter = 0;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char runMode;
|
||||
debug_init();
|
||||
fprintf(stderr, "\n Calling iptrans_init()");
|
||||
iptrans_init();
|
||||
|
||||
fprintf(stderr, "\n Calling logCollectorInit()");
|
||||
logCollectorInit();
|
||||
|
||||
if (argc > 0) {
|
||||
runMode = getopt(argc, argv, "d");
|
||||
switch (runMode) {
|
||||
case 'd':
|
||||
setup_daemon();
|
||||
break;
|
||||
case '?':
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
//debug_init();//must do it at first
|
||||
}
|
||||
setTimer();
|
||||
while (1) {
|
||||
usleep(50);
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
void onTimer()
|
||||
{
|
||||
//debug_rt();
|
||||
//snmp_timer();
|
||||
if (timerCounter % 3 == 0) {
|
||||
logCollectorTimer();
|
||||
}
|
||||
if (timerCounter >= 50000) {
|
||||
//logCollectorInit();
|
||||
timerCounter = 0;
|
||||
}
|
||||
timerCounter++;
|
||||
}
|
||||
|
||||
void setTimer()
|
||||
{
|
||||
struct sigaction act;
|
||||
act.sa_handler = onTimer;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
if (sigaction(SIGALRM, &act, NULL) < 0) {
|
||||
perror("Produce Sigaction");
|
||||
exitLog("logCollector:setTimer, sigaction function error");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
itimer.it_interval.tv_sec = 0;
|
||||
itimer.it_interval.tv_usec = 20 * 1000;
|
||||
itimer.it_value.tv_sec = 0;
|
||||
itimer.it_value.tv_usec = 20 * 1000;
|
||||
|
||||
if (setitimer(ITIMER_REAL, &itimer, &old_itimer) != 0) {
|
||||
printf("Setting Timer error! \n");
|
||||
exitLog("logCollector:setTimer, setitimer function error");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void setup_daemon(void)
|
||||
{
|
||||
/*
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
close(i);
|
||||
}
|
||||
*/
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
perror("setup_daemon(), 1st fork()");
|
||||
exit(2);
|
||||
default:
|
||||
exit(0);
|
||||
case 0:
|
||||
if (setsid() == -1) {
|
||||
perror("setup_daemon(), setsid()");
|
||||
exit(3);
|
||||
}
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
perror("setup_daemon(), 2nd fork()");
|
||||
exit(3);
|
||||
default:
|
||||
exit(0);
|
||||
case 0:
|
||||
umask(0);
|
||||
/* and return with daemon set up */
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user