Skip to content

Commit

Permalink
add check.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-christophe81 committed Sep 10, 2024
1 parent ff3ecd2 commit 032e001
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 13 deletions.
14 changes: 7 additions & 7 deletions .github/scripts/agent_robot_test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Write-Host ($agent_process | Format-Table | Out-String)
Start-Sleep -Seconds 1

#encrypted version
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name ca_certificate -Value ${$current_dir}/server_grpc.crt
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name ca_certificate -Value ${current_dir}/server_grpc.crt
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name endpoint -Value ${my_host_name}:4318
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name encryption -Value 1
$agent_log_path = $current_dir + "\reports\encrypted_centagent.log"
Expand All @@ -67,8 +67,8 @@ Start-Sleep -Seconds 1
#Start reverse agent
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name ca_certificate -Value ""
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name encryption -Value 0
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name endpoint -Value ${my_host_name}:4320
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name reversed_grpc_streaming -Value 1
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name endpoint -Value 0.0.0.0:4320
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name reverse_connection -Value 1
$agent_log_path = $current_dir + "\reports\reverse_centagent.log"
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name log_file -Value $agent_log_path

Expand All @@ -77,16 +77,16 @@ Start-Process -FilePath build_windows\agent\Release\centagent.exe -RedirectStand
Start-Sleep -Seconds 1

#reversed and encrypted
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name private_key -Value ${$current_dir}/server_grpc.key
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name public_cert -Value ${$current_dir}/server_grpc.crt
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name private_key -Value ${current_dir}/server_grpc.key
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name public_cert -Value ${current_dir}/server_grpc.crt
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name encryption -Value 1
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name endpoint -Value ${my_host_name}:4321
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name endpoint -Value 0.0.0.0:4321
$agent_log_path = $current_dir + "\reports\encrypted_reverse_centagent.log"
Set-ItemProperty -Path HKLM:\SOFTWARE\Centreon\CentreonMonitoringAgent -Name log_file -Value $agent_log_path

Start-Process -FilePath build_windows\agent\Release\centagent.exe -RedirectStandardOutput reports\encrypted_reversed_centagent_stdout.log -RedirectStandardError reports\encrypted_reversed_centagent_stderr.log

wsl cd $wsl_path `&`& .github/scripts/wsl-collect-test-robot.sh broker-engine/cma.robot $my_host_name $my_ip $pwsh_path
wsl cd $wsl_path `&`& .github/scripts/wsl-collect-test-robot.sh broker-engine/cma.robot $my_host_name $my_ip $pwsh_path ${current_dir}.replace('\','/')

if (Test-Path -Path 'reports\windows-cma-failed' -PathType Container) {
exit 1
Expand Down
6 changes: 6 additions & 0 deletions .github/scripts/wsl-collect-test-robot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export RUN_ENV=WSL
export HOST_NAME=$2
export USED_ADDRESS=$3
export PWSH_PATH=$4
export WINDOWS_PROJECT_PATH=$5


#ino order to connect to windows we neeed to use windowsw ip
echo "127.0.0.1 localhost" > /etc/hosts
echo "${USED_ADDRESS} ${HOST_NAME}" >> /etc/hosts

echo "##### /etc/hosts: ######"
cat /etc/hosts
Expand Down
12 changes: 9 additions & 3 deletions tests/broker-engine/cma.robot
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,23 @@ BEOTEL_CENTREON_AGENT_CHECK_HOST_CRYPTED

# Let's wait for the otel server start
${content} Create List encrypted server listening on 0.0.0.0:4318
${result} Ctn Find In Log With Timeout ${engineLog0} ${start} ${content} 60
${result} Ctn Find In Log With Timeout ${engineLog0} ${start} ${content} 10
Should Be True ${result} "encrypted server listening on 0.0.0.0:4318" should be available.
Sleep 1

${result} Ctn Check Host Check Status With Timeout host_1 30 ${start_int} 0 OK - 127.0.0.1
${result} Ctn Check Host Check Status With Timeout host_1 60 ${start_int} 0 OK - 127.0.0.1
Should Be True ${result} hosts table not updated

*** Keywords ***
Ctn Create Cert And Init
[Documentation] create key and certificates used by agent and engine on linux side
${host_name} Ctn Get Hostname
Ctn Create Key And Certificate ${host_name} /tmp/server_grpc.key /tmp/server_grpc.crt
${run_env} Ctn Run Env
IF "${run_env}" == "WSL"
Copy File ../server_grpc.key /tmp/server_grpc.key
Copy File ../server_grpc.crt /tmp/server_grpc.crt
ELSE
Ctn Create Key And Certificate ${host_name} /tmp/server_grpc.key /tmp/server_grpc.crt
END

Ctn Clean Before Suite
4 changes: 2 additions & 2 deletions tests/resources/Agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def ctn_echo_command(to_echo:str):
returned an echo command usable by testing agent OS
"""
if environ.get("RUN_ENV","") == "WSL":
return environ.get("PWSH_PATH") + " C:/Users/Public/echo.ps1 " + to_echo
return '"'+ environ.get('PWSH_PATH') + '"' + " C:/Users/Public/echo.ps1 " + to_echo
else:
return "/bin/echo " + to_echo

Expand All @@ -149,7 +149,7 @@ def ctn_check_pl_command(arg:str):
returned an check.pl command usable by testing agent OS
"""
if environ.get("RUN_ENV","") == "WSL":
return environ.get("PWSH_PATH") +" C:/Users/Public/check.ps1 " + arg
return '"'+ environ.get('PWSH_PATH') + '"' +" C:/Users/Public/check.ps1 " + arg + " " + environ.get("WINDOWS_PROJECT_PATH")
else:
return "/tmp/var/lib/centreon-engine/check.pl " + arg

2 changes: 1 addition & 1 deletion tests/resources/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def ctn_clear_commands_status():

def ctn_set_command_status(cmd, status):
if os.environ.get("RUN_ENV","") == "WSL":
state_path = "C:/Users/Public/states"
state_path = "states"
else:
state_path = "/tmp/states"

Expand Down
55 changes: 55 additions & 0 deletions tests/resources/engine-scripts/check.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# Copyright 2024 Centreon
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# For more information : contact@centreon.com
#

$id=$args[1]
$project_path = $args[2]

$status = -1
if (Test-Path -Path C:\Users\Public\states) {
$state_file = $project_path + "\tests\states"
$status = select-string -path $state_file -pattern "${id}=>(\d+)" | %{$_.Matches[0].Groups[1].Value }
}

$szd = Get-Date -UFormat "%s"
$dd = [double]$szd
$d = [int]($dd / 1000000)

$d = [int]($d + 3 * $id) -band 0x1ff;

$d = $d / ($id + 1);
$w = 300 / ($id + 1);
$c = 400 / ($id + 1);
if ($status -eq 0) {
$d = $w / 2;
} elseif ($status -eq 1) {
$d = ($w + $c) / 2;
} elseif ($status -eq 2) {
$d = 2 * $c;
} else {
if ($d -gt $c) {
$status = 2;
} elseif ($d -gt $w) {
$status = 1;
} else {
$status = 0;
}
}

"Test check $id | metric={0:n2};{1:n2};{2:n2}" -f $d, $w, $c

exit $status;

0 comments on commit 032e001

Please sign in to comment.