diff --git a/tests/broker-engine/cma.robot b/tests/broker-engine/cma.robot index 49d9110366..1c0b4adaed 100644 --- a/tests/broker-engine/cma.robot +++ b/tests/broker-engine/cma.robot @@ -412,6 +412,77 @@ BEOTEL_CENTREON_AGENT_CHECK_NATIVE_CPU Should Be True ${result} resources table not updated +BEOTEL_CENTREON_AGENT_CHECK_NATIVE_STORAGE + [Documentation] agent check service with native check storage and we expect to get it in check result + [Tags] broker engine opentelemetry MON-147936 + + ${run_env} Ctn Run Env + Pass Execution If "${run_env}" != "WSL" "This test is only for WSL" + + Ctn Config Engine ${1} ${2} ${2} + Ctn Add Otl ServerModule + ... 0 + ... {"otel_server":{"host": "0.0.0.0","port": 4317},"max_length_grpc_log":0,"centreon_agent":{"check_interval":10, "export_period":15}} + Ctn Config Add Otl Connector + ... 0 + ... OTEL connector + ... opentelemetry --processor=centreon_agent --extractor=attributes --host_path=resource_metrics.resource.attributes.host.name --service_path=resource_metrics.resource.attributes.service.name + Ctn Engine Config Replace Value In Services ${0} service_1 check_command otel_check + Ctn Set Services Passive 0 service_1 + + Ctn Engine Config Add Command ${0} otel_check {"check": "storage", "args": { "free": true, "unit": "%"}} OTEL connector + + Ctn Engine Config Set Value 0 log_level_checks trace + + Ctn Clear Db metrics + + Ctn Config Broker central + Ctn Config Broker module + Ctn Config Broker rrd + Ctn Config Centreon Agent + + Ctn Config BBDO3 1 + Ctn Clear Retention + + ${start} Ctn Get Round Current Date + Ctn Start Broker + Ctn Start Engine + Ctn Start Agent + + # Let's wait for the otel server start + ${content} Create List unencrypted server listening on 0.0.0.0:4317 + ${result} Ctn Find In Log With Timeout ${engineLog0} ${start} ${content} 10 + Should Be True ${result} "unencrypted server listening on 0.0.0.0:4317" should be available. + + ${result} Ctn Check Service Resource Status With Timeout host_1 service_1 0 120 HARD + Should Be True ${result} resources table not updated + + ${expected_perfdata} Ctn Get Drive Statistics + ${result} Ctn Check Service Perfdata host_1 service_1 60 0.1 ${expected_perfdata} + Should be True ${result} data_bin not updated + + + #a small threshold to make service_1 warning + Ctn Engine Config Replace Value In Services ${0} service_1 check_command otel_check2 + + Ctn Engine Config Add Command ${0} otel_check2 {"check": "storage", "args": {"warning" : "99.99"}} OTEL connector + + Ctn Reload Engine + ${result} Ctn Check Service Resource Status With Timeout host_1 service_1 1 60 ANY + Should Be True ${result} resources table not updated + + #a small threshold to make service_1 critical + Ctn Engine Config Replace Value In Services ${0} service_1 check_command otel_check3 + + Ctn Engine Config Add Command ${0} otel_check3 {"check": "storage", "args": {"critical" : "99.99"}} OTEL connector + + Ctn Reload Engine + ${result} Ctn Check Service Resource Status With Timeout host_1 service_1 2 60 ANY + Should Be True ${result} resources table not updated + + + + *** Keywords *** Ctn Create Cert And Init [Documentation] create key and certificates used by agent and engine on linux side diff --git a/tests/resources/Agent.py b/tests/resources/Agent.py index 219e9a8078..63435e33ea 100644 --- a/tests/resources/Agent.py +++ b/tests/resources/Agent.py @@ -166,3 +166,17 @@ def ctn_check_pl_command(arg:str): else: return "/tmp/var/lib/centreon-engine/check.pl " + arg +def ctn_get_drive_statistics(): + """ + ctn_get_drive_statistics + return a dictionary of drive statistics indexed by expected perfdata names + """ + if environ.get("RUN_ENV","") == "WSL": + drive_dict = {} + json_test_args = environ.get("JSON_TEST_PARAMS") + test_args = json.loads(json_test_args) + for drive in test_args["drives"]: + if drive['Free'] is not None: + drive_dict[f"{drive['Name']}:\\"] = (100 * drive['Free']) / (drive['Used'] + drive['Free']) + else: + return None \ No newline at end of file diff --git a/tests/resources/Common.py b/tests/resources/Common.py index 0e7ed0ab88..b530d33f90 100644 --- a/tests/resources/Common.py +++ b/tests/resources/Common.py @@ -1949,3 +1949,54 @@ def ctn_compare_string_with_file(string_to_compare:str, file_path:str): return False return True + + +def ctn_check_service_perfdata(host: str, serv: str, timeout: int, precision: float, expected: dict): + """ + Check if performance data are near as expected. + host (str): The hostname of the service to check. + serv (str): The service name to check. + timeout (int): The timeout value for the check. + precision (float): The precision required for the performance data comparison. + expected (dict): A dictionary containing the expected performance data values. + """ + limit = time.time() + timeout + while time.time() < limit: + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor) + with connection: + with connection.cursor() as cursor: + cursor.execute(f"""" + SELECT + sub_query.metric_name, db.value + FROM + data_bin db + JOIN + (SELECT + m.metric_name, MAX(db.ctime) AS last_data, db.id_metric + FROM + data_bin db + JOIN metrics m ON db.id_metric = m.metric_id + JOIN index_data id ON id.id = m.index_id + WHERE id.host_name='{host}' AND id.service_description='{serv}' + GROUP BY m.metric_id) sub_query ON db.ctime = sub_query.last_data + AND db.id_metric = sub_query.id_metric""") + result = cursor.fetchall() + if len(result) == len(expected): + for res in result: + logger.console(f"metric: {res['metric_name']}, value: {res['value']}") + metric = res['metric_name'] + value = float(res['value']) + if metric not in expected: + logger.console(f"unexpected metric: {metric}") + return False + if abs(value - expected[metric]) > precision: + logger.console(f"unexpected value for {metric}: {value}") + return False + return True + time.sleep(1) + return False \ No newline at end of file