111 lines
2.3 KiB
C
111 lines
2.3 KiB
C
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include <dirent.h>
|
|
#include <signal.h>
|
|
#include <sys/time.h>
|
|
#include <sys/wait.h>
|
|
#include <pthread.h>
|
|
#include <zmq.h>
|
|
#include <sys/inotify.h>
|
|
|
|
#define EVENT_NUM 12
|
|
#define BUF_SIZE 1024
|
|
//gcc monitsys.c -lzmq -lpthread -L/usr/local/lib -I/usr/local/include -Wl,-rpath=/usr/local/lib/ -o monitsys
|
|
#define fb_debug(fmt, arg...) \
|
|
do{ \
|
|
printf("%s %d : ", __FILE__, __LINE__); \
|
|
printf(fmt, ##arg); \
|
|
printf("\n"); \
|
|
}while(0)
|
|
|
|
#define fb_assert(var, info) \
|
|
do{ \
|
|
if(!(var)) { \
|
|
fb_debug(info); \
|
|
} \
|
|
}while(0)
|
|
|
|
typedef unsigned int uint;
|
|
|
|
char *event_str[EVENT_NUM] =
|
|
{
|
|
"IN_ACCESS",
|
|
"IN_MODIFY",
|
|
"IN_ATTRIB",
|
|
"IN_CLOSE_WRITE",
|
|
"IN_CLOSE_NOWRITE",
|
|
"IN_OPEN",
|
|
"IN_MOVED_FROM",
|
|
"IN_MOVED_TO",
|
|
"IN_CREATE",
|
|
"IN_DELETE",
|
|
"IN_DELETE_SELF",
|
|
"IN_MOVE_SELF"
|
|
};
|
|
|
|
int lastnum = 0,lastlognum = 0,newloginnum = 0,lastloginnum = 0;
|
|
|
|
typedef struct CPU_PACKED
|
|
{
|
|
char name[20]; //
|
|
unsigned int user;
|
|
unsigned int nice;
|
|
unsigned int system;
|
|
unsigned int idle;
|
|
}CPU_OCCUPY;
|
|
|
|
typedef struct
|
|
{
|
|
uint uiType; // 1
|
|
char szip[32];
|
|
struct timeval stRcvTime;
|
|
uint uiCpuRate;
|
|
uint uiMemRate;
|
|
uint uiTcpEstablishNum;
|
|
uint uiRunningProcessNum;
|
|
uint uiCronNum;
|
|
char szPasswdMd5[64];
|
|
char szGroupMd5[64];
|
|
}Msgreport;
|
|
|
|
typedef struct
|
|
{
|
|
uint uiType;//2
|
|
char szIp[32];
|
|
struct timeval stRcvTime;
|
|
char uiProcessname[32];
|
|
uint uiProcessState;// 0 mains enable,1 disable
|
|
}stProcessState;
|
|
|
|
typedef struct
|
|
{
|
|
uint uiType; //3
|
|
char szIp[32];
|
|
struct timeval stRcvTime;
|
|
char szFileName[32]; //filename modified
|
|
//char eventType[16]; //eventType of filename
|
|
char szFileMd5[64]; //md5num of file name
|
|
}stFileState;
|
|
|
|
typedef struct
|
|
{
|
|
uint uiType; //4
|
|
char szIp[32];
|
|
struct timeval stRcvTime;
|
|
char szPath[32]; //监控路径
|
|
char szFileName[32]; //增加或删除的文件名称
|
|
uint uiFileNum; //当前文件夹下文件数量
|
|
}stFileNum;
|
|
|
|
|
|
typedef struct
|
|
{
|
|
uint uiType;//5
|
|
char szIp[32];
|
|
struct timeval stRcvTime;
|
|
char szLogFile[32];
|
|
char szMsg[5][128];
|
|
}stLogMsg; |