Skip to content
Permalink
Browse files

[CMK-1730] - initial commit of new Windows Agent

Change-Id: I375d03193d5559042f0d7445de74df14e7433710
  • Loading branch information...
s-kipnis committed Feb 28, 2019
1 parent 4e9a34f commit d23343b97f8ce104e8f51b34bd0040cb13ee8a70
Showing 301 changed files with 32,891 additions and 0 deletions.
@@ -49,4 +49,5 @@ tests/web/data/*
.venv
*.gcov
htmlcov/
artefacts/
node_modules/
No changes.
Binary file not shown.
@@ -0,0 +1 @@
No test and benchmark folder. Too big
@@ -53,6 +53,26 @@ set out_dir_name=%nm%
powershell Write-Host "%out_dir_name%:" -ForegroundColor blue
call %unpack_cmd% %unpacker_exe% %src_dir_name% %src_file_name% %out_root% %out_dir_name% *

rem with internal folder in the tar.gz
set nm=yaml-cpp
set vv=-master
set src_dir_name=%omd_path%\%nm%
if not exist %src_dir_name% set src_dir_name=%agent_path%\%nm%
set src_file_name=%nm%%vv%
set out_dir_name=%nm%
powershell Write-Host "%out_dir_name%:" -ForegroundColor blue
call %unpack_cmd% %unpacker_exe% %src_dir_name% %src_file_name% %out_root% %out_dir_name% *

rem with internal folder in the tar.gz
set nm=json
set vv=-master-3.4.0
set src_dir_name=%omd_path%\%nm%
if not exist %src_dir_name% set src_dir_name=%agent_path%\%nm%
set src_file_name=%nm%%vv%
set out_dir_name=%nm%
powershell Write-Host "%out_dir_name%:" -ForegroundColor blue
call %unpack_cmd% %unpacker_exe% %src_dir_name% %src_file_name% %out_root% %out_dir_name% *


rem without internal folder in the tar.gz
set nm=simpleini
Binary file not shown.
@@ -0,0 +1,12 @@
*.res
*.obj
*.exe
*.msi
Debug/
Release/
x86/
x64/
*.ipch
extlibs/
.vs/
*vcxproj.user
@@ -0,0 +1,6 @@
{
"files.exclude": {
"**/build": true,
"**/extlibs": true
}
}
@@ -0,0 +1 @@
Assorted executable scripts for testing/installing
@@ -0,0 +1,5 @@
@echo off
@call test_service.cmd check_mk_service64.exe CheckMkService
if NOT "%errorlevel%" == "0" powershell Write-Host "Test Failed" -ForegroundColor red && set e=1 && goto exit
powershell Write-Host "Test Successful" -ForegroundColor green
:exit
@@ -0,0 +1,26 @@
@echo off
rem Simple testing script for any service
rem You may need Administrative Account
rem Usage:
rem test_service.cmd <binary> CheckMkService
rem Example:
rem test_service.cmd check_mk_service64.exe CheckMkService
set svc=%1%
set svc_name=%2%
set e=0
%svc% -install
if NOT "%errorlevel%" == "0" powershell Write-Host "Service Failed to Install" -ForegroundColor red && set e=1 && goto exit
powershell Write-Host "Service Installed" -ForegroundColor green
net start CheckMkService
if NOT "%errorlevel%" == "0" powershell Write-Host "Service Failed to Start" -ForegroundColor red && set e=1 && goto remove
powershell Write-Host "Service Started" -ForegroundColor green
pause
net stop CheckMkService
if NOT "%errorlevel%" == "0" powershell Write-Host "Service Failed to Stop" -ForegroundColor red && set e=1 && goto remove
powershell Write-Host "Service Stopped" -ForegroundColor green
:remove
%svc% -remove
if NOT "%errorlevel%" == "0" powershell Write-Host "Service Failed to Remove" -ForegroundColor red && set e=1 && goto exit
powershell Write-Host "Service Removed" -ForegroundColor green
:exit
exit /b %e%
@@ -0,0 +1,81 @@
@echo off
rem File to Build MSI usingMS BUild system
rem Problem based on the fact that we have one x86 Playfrom for MSI
rem but two, x86 and x64, for exe and MSI must have both targets
rem build before owm build start.
rem this is for command line only
rem In GUI we should do Batch Rebuild of everything
rem variables to set OPTOIONALLY, when you are using the same git checkout multiple times
rem REMOTE_MACHINE - final artefacts
rem LOCAL_IMAGES_EXE - exe
rem LOCAL_IMAGE_PDB - pdb
rem WNX_BUILD - in the future this is name of subfloder to build out

set cur_dir=%cd%
set arte=%cur_dir%\..\..\artefacts
mkdir %arte% 2> nul
mkdir %arte%\plugins 2> nul
mkdir %arte%\watest 2> nul
mkdir %arte%\watest\plugins 2> nul
mkdir %arte%\providers 2> nul
mkdir %arte%\exe 2> nul
mkdir %arte%\pdb 2> nul
set REMOTE_MACHINE=%arte%
set LOCAL_IMAGES_PDB=%arte%\pdb
set LOCAL_IMAGES_EXE=%arte%\exe

if "%1" == "SIMULATE_OK" powershell Write-Host "Successful Build" -Foreground Green && echo aaa > %arte%\check_mk_service.msi && exit 0
if "%1" == "SIMULATE_FAIL" powershell Write-Host "Failed Install build" -Foreground Red && del %arte%\check_mk_service.msi && exit 8

powershell Write-Host "Building MSI..." -Foreground Green
set msbuild="C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe"
if not exist %msbuild% powershell Write-Host "MSBUILD not found, trying Visual Professional" -Foreground Yellow && set msbuild="C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe"
if not exist %msbuild% powershell Write-Host "Install MSBUILD, please" -Foreground Red && exit 99

set exec=check_mk_service
%msbuild% wamain.sln /t:%exec% /p:Configuration=Release,Platform=x86
if not %errorlevel% == 0 powershell Write-Host "Failed %exec%-32" -Foreground Red && exit 1
%msbuild% wamain.sln /t:%exec% /p:Configuration=Release,Platform=x64
if not %errorlevel% == 0 powershell Write-Host "Failed %exec%-64" -Foreground Red && exit 2

set exec=plugin_player
%msbuild% wamain.sln /t:%exec% /p:Configuration=Release,Platform=x86
if not %errorlevel% == 0 powershell Write-Host "Failed %exec%-32" -Foreground Red && exit 2
%msbuild% wamain.sln /t:%exec% /p:Configuration=Release,Platform=x64
if not %errorlevel% == 0 powershell Write-Host "Failed %exec%-64" -Foreground Red && exit 3

set exec=providers\perf_counter
%msbuild% wamain.sln /t:%exec% /p:Configuration=Release,Platform=x86
if not %errorlevel% == 0 powershell Write-Host "Failed %exec%-32" -Foreground Red && exit 4
%msbuild% wamain.sln /t:%exec% /p:Configuration=Release,Platform=x64
if not %errorlevel% == 0 powershell Write-Host "Failed %exec%-64" -Foreground Red && exit 5

set exec=watest
%msbuild% wamain.sln /t:%exec% /p:Configuration=Release,Platform=x86
if not %errorlevel% == 0 powershell Write-Host "Failed %exec%-32" -Foreground Red && exit 6
%msbuild% wamain.sln /t:%exec% /p:Configuration=Release,Platform=x64
if not %errorlevel% == 0 powershell Write-Host "Failed %exec%-64" -Foreground Red && exit 7

%msbuild% wamain.sln /t:install /p:Configuration=Release,Platform=x64
if not %errorlevel% == 0 powershell Write-Host "Failed Install build" -Foreground Red && exit 8
goto end
@rem ignored:
powershell Write-Host "starting unit tests" -Foreground Cyan

pushd %REMOTE_MACHINE%
watest
if not %errorlevel% == 0 goto error
popd
powershell Write-Host "Unit test SUCCESS" -Foreground Green


:error
popd
powershell Write-Host "Unit test failed" -Foreground Red
powershell Write-Host "Killing msi in artefacts" -Foreground Red
del %REMOTE_MACHINE%\check_mk_service.msi
exit 100
:end



@@ -0,0 +1,30 @@
@echo off
rem Short Build File

set cur_dir=%cd%
set arte=%cur_dir%\..\..\artefacts
mkdir %arte% 2> nul
mkdir %arte%\plugins 2> nul
mkdir %arte%\watest 2> nul
mkdir %arte%\watest\plugins 2> nul
mkdir %arte%\providers 2> nul
mkdir %arte%\exe 2> nul
mkdir %arte%\pdb 2> nul
set REMOTE_MACHINE=%arte%
set LOCAL_IMAGES_PDB=%arte%\pdb
set LOCAL_IMAGES_EXE=%arte%\exe

if "%1" == "SIMULATE_OK" powershell Write-Host "Successful Build" -Foreground Green && echo aaa > %arte%\check_mk_service.msi && exit 0
if "%1" == "SIMULATE_FAIL" powershell Write-Host "Failed Install build" -Foreground Red && del %arte%\check_mk_service.msi && exit 8

powershell Write-Host "Building MSI..." -Foreground Green
set msbuild="C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe"
if not exist %msbuild% powershell Write-Host "MSBUILD not found, trying Visual Professional" -Foreground Yellow && set msbuild="C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe"
if not exist %msbuild% powershell Write-Host "Install MSBUILD, please" -Foreground Red && exit 99

set exec=watest
%msbuild% wamain.sln /t:%exec% /p:Configuration=Release,Platform=x86
if not %errorlevel% == 0 powershell Write-Host "Failed %exec%-32" -Foreground Red && exit 6



@@ -0,0 +1,4 @@
@echo off
@echo Starting deployment
if "%1" == "SIMULATE_OK" powershell Write-Host "Deploy: SUCCESS" -Foreground Green && exit 0
if "%1" == "SIMULATE_FAIL" powershell Write-Host "Deploy: FAIL" -Foreground Red && del %REMOTE_MACHINE%\check_mk_service.msi && exit 99
@@ -0,0 +1,35 @@
@echo off
call prepare_to_tests.cmd
set root=%cd%\..\..\artefacts
set REMOTE_MACHINE=%root%

if "%1" == "SIMULATE_OK" powershell Write-Host "Unit test SUCCESS" -Foreground Green && exit 0
if "%1" == "SIMULATE_FAIL" powershell Write-Host "Unit test FAIL" -Foreground Red && del %REMOTE_MACHINE%\check_mk_service.msi && exit 100
if NOT "%1" == "" set param=--gtest_filter=%1
set sec_param=%2
if "%param%" == "" powershell Write-Host "Full and Looooooong test was requested." -Foreground Cyan && set sec_param=both

powershell Write-Host "32-bit test" -Foreground Cyan
cd %REMOTE_MACHINE%
%REMOTE_MACHINE%\watest32.exe %param%
if not %errorlevel% == 0 goto error
cd %REMOTE_MACHINE%
if NOT "%sec_param%" == "both" powershell Write-Host "This is end of testing. QUICK test was requested." -Foreground Cyan && goto success

@rem 64-bit is tested quickly
powershell Write-Host "64-bit test" -Foreground Cyan
if "%1" == "" set param=--gtest_filter=-PluginTest.Sync*:PluginTest.Async*
%REMOTE_MACHINE%\watest64.exe %param%
if not %errorlevel% == 0 goto error
popd
powershell Write-Host "This is end of testing. FULL test was requested." -Foreground Cyan
:success
powershell Write-Host "Unit test SUCCESS" -Foreground Green
goto end
:error
popd
powershell Write-Host "Unit test failed" -Foreground Red
powershell Write-Host "Killing msi in artefacts" -Foreground Red
del %REMOTE_MACHINE%\check_mk_service.msi
exit 100
:end
@@ -0,0 +1 @@
call call_unit_tests.cmd -PluginTest.Async*:PluginTest.Sync*:PlayerTest.RealLife* skip
@@ -0,0 +1,71 @@

Transport in Windows Agent

External Transport:

- Located in the namespace cma::world
- files
external_port.h
external_port.cpp
test-external-port.cpp
- Uses ASIO standalone implementation
- Implemented in the class ExternalPort according to asio original documentation and working example(async echo server)
- Supporting Important Classes
AsioSession - modified reference implementation from the ASIO documentation
ExternalPort::server - a bit modified reference implementation from the ASIO documentation
- API
ctor/dtor
startIo(replyFunc)
non-blocking!
replyFunc is lambda or functor to
get IP of client
perform any actions
returns data block
shutdown
- Port 6556, in the future will be configured from the config file
- unit tested
basic testing only
- thread safe
- asynchronous
- Important Notes
Current Algorythm
listen
accept connection
save IP
call replyFunc
disconnect
goto listen...
Future
mode without disconnect
shutdown correcly deletes all data and stops all thread
owner of the external port object should keep it safe till shutodwn called
- Performance theoretically unlimited(to be measured)
- VIP
object itself
private thread
created startIo
ended shutdown
- example of usage
{
using namespace std::chrono;
cma::world::ReplyFunc reply =
[](const std::string Ip) -> std::vector<uint8_t> {
char reply_text[] = "I am test\n";
auto len = strlen(reply_text) + 1;
std::vector<uint8_t> v;
v.resize(len);
for (unsigned int i = 0; i < len; i++) v[i] = reply_text[i];
return v;
};

cma::world::ExternalPort test_port(64351); //
auto ret = test_port.startIo(reply); //
// wait a bit just for fun
// or connect to port 64531 and print result
std::this_thread::sleep_until(steady_clock::now() + 1000ms);
test_port.shutdownIo(); //
}




Oops, something went wrong.

0 comments on commit d23343b

Please sign in to comment.
You can’t perform that action at this time.