Skip to content

Commit 42f7400

Browse files
add robot test
1 parent 7dbbd77 commit 42f7400

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

tests/broker-engine/cma.robot

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,77 @@ BEOTEL_CENTREON_AGENT_CHECK_NATIVE_CPU
412412
Should Be True ${result} resources table not updated
413413

414414

415+
BEOTEL_CENTREON_AGENT_CHECK_NATIVE_STORAGE
416+
[Documentation] agent check service with native check storage and we expect to get it in check result
417+
[Tags] broker engine opentelemetry MON-147936
418+
419+
${run_env} Ctn Run Env
420+
Pass Execution If "${run_env}" != "WSL" "This test is only for WSL"
421+
422+
Ctn Config Engine ${1} ${2} ${2}
423+
Ctn Add Otl ServerModule
424+
... 0
425+
... {"otel_server":{"host": "0.0.0.0","port": 4317},"max_length_grpc_log":0,"centreon_agent":{"check_interval":10, "export_period":15}}
426+
Ctn Config Add Otl Connector
427+
... 0
428+
... OTEL connector
429+
... opentelemetry --processor=centreon_agent --extractor=attributes --host_path=resource_metrics.resource.attributes.host.name --service_path=resource_metrics.resource.attributes.service.name
430+
Ctn Engine Config Replace Value In Services ${0} service_1 check_command otel_check
431+
Ctn Set Services Passive 0 service_1
432+
433+
Ctn Engine Config Add Command ${0} otel_check {"check": "storage", "args": { "free": true, "unit": "%"}} OTEL connector
434+
435+
Ctn Engine Config Set Value 0 log_level_checks trace
436+
437+
Ctn Clear Db metrics
438+
439+
Ctn Config Broker central
440+
Ctn Config Broker module
441+
Ctn Config Broker rrd
442+
Ctn Config Centreon Agent
443+
444+
Ctn Config BBDO3 1
445+
Ctn Clear Retention
446+
447+
${start} Ctn Get Round Current Date
448+
Ctn Start Broker
449+
Ctn Start Engine
450+
Ctn Start Agent
451+
452+
# Let's wait for the otel server start
453+
${content} Create List unencrypted server listening on 0.0.0.0:4317
454+
${result} Ctn Find In Log With Timeout ${engineLog0} ${start} ${content} 10
455+
Should Be True ${result} "unencrypted server listening on 0.0.0.0:4317" should be available.
456+
457+
${result} Ctn Check Service Resource Status With Timeout host_1 service_1 0 120 HARD
458+
Should Be True ${result} resources table not updated
459+
460+
${expected_perfdata} Ctn Get Drive Statistics
461+
${result} Ctn Check Service Perfdata host_1 service_1 60 0.1 ${expected_perfdata}
462+
Should be True ${result} data_bin not updated
463+
464+
465+
#a small threshold to make service_1 warning
466+
Ctn Engine Config Replace Value In Services ${0} service_1 check_command otel_check2
467+
468+
Ctn Engine Config Add Command ${0} otel_check2 {"check": "storage", "args": {"warning" : "99.99"}} OTEL connector
469+
470+
Ctn Reload Engine
471+
${result} Ctn Check Service Resource Status With Timeout host_1 service_1 1 60 ANY
472+
Should Be True ${result} resources table not updated
473+
474+
#a small threshold to make service_1 critical
475+
Ctn Engine Config Replace Value In Services ${0} service_1 check_command otel_check3
476+
477+
Ctn Engine Config Add Command ${0} otel_check3 {"check": "storage", "args": {"critical" : "99.99"}} OTEL connector
478+
479+
Ctn Reload Engine
480+
${result} Ctn Check Service Resource Status With Timeout host_1 service_1 2 60 ANY
481+
Should Be True ${result} resources table not updated
482+
483+
484+
485+
415486
*** Keywords ***
416487
Ctn Create Cert And Init
417488
[Documentation] create key and certificates used by agent and engine on linux side

tests/resources/Agent.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,17 @@ def ctn_check_pl_command(arg:str):
166166
else:
167167
return "/tmp/var/lib/centreon-engine/check.pl " + arg
168168

169+
def ctn_get_drive_statistics():
170+
"""
171+
ctn_get_drive_statistics
172+
return a dictionary of drive statistics indexed by expected perfdata names
173+
"""
174+
if environ.get("RUN_ENV","") == "WSL":
175+
drive_dict = {}
176+
json_test_args = environ.get("JSON_TEST_PARAMS")
177+
test_args = json.loads(json_test_args)
178+
for drive in test_args["drives"]:
179+
if drive['Free'] is not None:
180+
drive_dict[f"{drive['Name']}:\\"] = (100 * drive['Free']) / (drive['Used'] + drive['Free'])
181+
else:
182+
return None

tests/resources/Common.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,3 +1949,54 @@ def ctn_compare_string_with_file(string_to_compare:str, file_path:str):
19491949
return False
19501950
return True
19511951

1952+
1953+
1954+
def ctn_check_service_perfdata(host: str, serv: str, timeout: int, precision: float, expected: dict):
1955+
"""
1956+
Check if performance data are near as expected.
1957+
host (str): The hostname of the service to check.
1958+
serv (str): The service name to check.
1959+
timeout (int): The timeout value for the check.
1960+
precision (float): The precision required for the performance data comparison.
1961+
expected (dict): A dictionary containing the expected performance data values.
1962+
"""
1963+
limit = time.time() + timeout
1964+
while time.time() < limit:
1965+
connection = pymysql.connect(host=DB_HOST,
1966+
user=DB_USER,
1967+
password=DB_PASS,
1968+
database=DB_NAME_STORAGE,
1969+
charset='utf8mb4',
1970+
cursorclass=pymysql.cursors.DictCursor)
1971+
with connection:
1972+
with connection.cursor() as cursor:
1973+
cursor.execute(f""""
1974+
SELECT
1975+
sub_query.metric_name, db.value
1976+
FROM
1977+
data_bin db
1978+
JOIN
1979+
(SELECT
1980+
m.metric_name, MAX(db.ctime) AS last_data, db.id_metric
1981+
FROM
1982+
data_bin db
1983+
JOIN metrics m ON db.id_metric = m.metric_id
1984+
JOIN index_data id ON id.id = m.index_id
1985+
WHERE id.host_name='{host}' AND id.service_description='{serv}'
1986+
GROUP BY m.metric_id) sub_query ON db.ctime = sub_query.last_data
1987+
AND db.id_metric = sub_query.id_metric""")
1988+
result = cursor.fetchall()
1989+
if len(result) == len(expected):
1990+
for res in result:
1991+
logger.console(f"metric: {res['metric_name']}, value: {res['value']}")
1992+
metric = res['metric_name']
1993+
value = float(res['value'])
1994+
if metric not in expected:
1995+
logger.console(f"unexpected metric: {metric}")
1996+
return False
1997+
if abs(value - expected[metric]) > precision:
1998+
logger.console(f"unexpected value for {metric}: {value}")
1999+
return False
2000+
return True
2001+
time.sleep(1)
2002+
return False

0 commit comments

Comments
 (0)