서버에 webknight로그가 쌓이면 자동으로 메일일 뿌려주는 에이전트 개발
-> 모니터링 중이 아니더라도 메일을 통해 이벤트확인이 가능
주요함수
FindFirstChangeNotification
FindNextChangeNotification
WaitForMultipleObjects
// agent.cpp : Defines the entry point for the console application.
//
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <tchar.h>
#include <Wininet.h>
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE dwChangeHandles[1];
DWORD dwWaitStatus;
HINTERNET hInternet;
HINTERNET hURL;
HINTERNET hRequest;
BOOL bRet;
dwChangeHandles[0] = FindFirstChangeNotification(L"C:\\Program Files\\AQTRONIX Webknight\\LogFiles",TRUE,FILE_NOTIFY_CHANGE_SIZE);
if(dwChangeHandles[0] == INVALID_HANDLE_VALUE)
{
printf("\nerror: unexpected null from findfirstchangenotification.\n");
ExitProcess(GetLastError());
}
if(dwChangeHandles[0] == NULL)
{
printf("\n ERROR: Unexpected NULL from FindFirstChangeNotification.\n");
ExitProcess(GetLastError());
}
while(TRUE)
{
printf("\nWaiting for notification...\n");
dwWaitStatus = WaitForMultipleObjects(1,dwChangeHandles,FALSE,INFINITE);
switch (dwWaitStatus)
{
case WAIT_OBJECT_0:
printf("\nchange log size\n");
hInternet = InternetOpen(L"WebKnightConsoleAgent",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
hURL = InternetConnect(hInternet,L"192.168.230.130",80,L"",L"",INTERNET_SERVICE_HTTP,0,0);
hRequest = HttpOpenRequest(hURL,L"GET",L"/LogAnalysis.php?no=1&mail=1",NULL,NULL,NULL,0,0);
bRet = HttpSendRequest(hRequest,NULL,0,NULL,0);
if ( FindNextChangeNotification(dwChangeHandles[0]) == FALSE )
{
printf("\n ERROR: FindNextChangeNotification function failed.\n");
ExitProcess(GetLastError());
}
break;
case WAIT_TIMEOUT:
printf("\nNo changes in the timeout period.\n");
break;
default:
printf("\n ERROR: Unhandled dwWaitStatus.\n");
ExitProcess(GetLastError());
break;
}
}
return 0;
}