mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-09-25 18:58:39 +02:00
fix retrieving of results + factorize run & return
This commit is contained in:
parent
17ccfdb8d9
commit
9520d8b3e4
@ -142,9 +142,9 @@ def ctn_extract_result_from_log(tc, log_path="/tmp/connector.log", output_path=N
|
||||
with open(log_path, 'r') as f:
|
||||
for line in f:
|
||||
# Pattern: reporting check result #<id> ...
|
||||
m = re.search(r'reporting check result #(\d+).*output:(.*)', line)
|
||||
m = re.search(r'reporting check result #(\d+) check:(\d+) .*output:(.*)', line)
|
||||
if m:
|
||||
found_id, output = m.group(1), m.group(2).strip()
|
||||
test_number, found_id, output = m.group(1), m.group(2), m.group(3).strip()
|
||||
if str(found_id) == str(tc):
|
||||
# Write the output to the file
|
||||
output_path = output_path or f"/tmp/connector.output.{tc}"
|
||||
@ -167,9 +167,9 @@ def ctn_extract_result_from_log(tc, log_path="/tmp/connector.log", output_path=N
|
||||
import re
|
||||
with open(log_path, 'r') as f:
|
||||
for line in f:
|
||||
m = re.search(r'reporting check result #(\d+).*output:(.*)', line)
|
||||
m = re.search(r'reporting check result #(\d+) check:(\d+) .*output:(.*)', line)
|
||||
if m:
|
||||
found_id, output = m.group(1), m.group(2).strip()
|
||||
test_number, found_id, output = m.group(1), m.group(2), m.group(3).strip()
|
||||
if str(found_id) == str(tc):
|
||||
output_path = output_path or f"/tmp/connector.output.{tc}"
|
||||
with open(output_path, 'w') as out:
|
||||
|
@ -107,18 +107,53 @@ Ctn Verify Command Without Connector Output
|
||||
... values=False
|
||||
... collapse_spaces=True
|
||||
|
||||
Ctn Run Command With Connector And Check Result As Strings
|
||||
[Arguments] ${command} ${expected_result} ${tc}=0 ${timeout}=${TIMEOUT}
|
||||
Log To Console c
|
||||
Ctn Connector Log Contains Result
|
||||
[Arguments] ${tc}
|
||||
${result}= Grep File /tmp/connector.log reporting check result
|
||||
#\d+ check:${tc}${SPACE}
|
||||
|
||||
IF "${result}" == ''
|
||||
${toto}= Grep File /tmp/connector.log .
|
||||
Fail Result not available yet
|
||||
ELSE
|
||||
RETURN ${TRUE}
|
||||
END
|
||||
|
||||
Ctn Wait Until Connector Result Available
|
||||
[Arguments] ${tc} ${timeout}=${TIMEOUT}
|
||||
Wait Until Keyword Succeeds
|
||||
... ${timeout}
|
||||
... .2
|
||||
... File Should Not Be Empty /tmp/connector.log
|
||||
File Should Not Be Empty /tmp/connector.log
|
||||
Wait Until Keyword Succeeds
|
||||
... ${timeout}
|
||||
... .2
|
||||
... Ctn Connector Log Contains Result ${tc}
|
||||
|
||||
Ctn Run Command With Connector And Return Result
|
||||
[Arguments] ${tc} ${command} ${timeout}=${TIMEOUT}
|
||||
Remove File /tmp/connector.output
|
||||
Remove File /tmp/connector.command.log
|
||||
Create File /tmp/connector.log
|
||||
File Should Be Empty /tmp/connector.log
|
||||
|
||||
Ctn Send To Connector ${tc} ${command} ${timeout}
|
||||
Ctn Wait Until Connector Result Available ${tc} ${timeout}
|
||||
|
||||
# 1. Extract the result from the log and write to /tmp/connector.output
|
||||
Ctn Extract Result From Log ${tc}
|
||||
# 2. Read the file
|
||||
${output} Get File /tmp/connector.output
|
||||
${output} Strip String ${output}
|
||||
# 3. Compare with expected
|
||||
RETURN ${output}
|
||||
|
||||
Ctn Run Command With Connector And Check Result As Strings
|
||||
[Arguments] ${command} ${expected_result} ${tc}=0 ${timeout}=${TIMEOUT}
|
||||
Log To Console c
|
||||
|
||||
${output} Ctn Run Command With Connector And Return Result ${tc} ${command} ${timeout}
|
||||
|
||||
Should Be Equal As Strings
|
||||
... ${expected_result}
|
||||
... ${output}
|
||||
@ -130,14 +165,8 @@ Ctn Run Command With Connector And Check Result As Strings
|
||||
Ctn Run Command With Connector And Check Result As Regexp
|
||||
[Arguments] ${command} ${expected_result} ${tc}=0 ${timeout}=${TIMEOUT}
|
||||
Log To Console c
|
||||
Remove File /tmp/connector.output
|
||||
Remove File /tmp/connector.command.log
|
||||
Ctn Send To Connector ${tc} ${command} ${timeout}
|
||||
# 1. Extract the result from the log and write to /tmp/connector.output
|
||||
Ctn Extract Result From Log ${tc}
|
||||
# 2. Read the file
|
||||
${output} Get File /tmp/connector.output
|
||||
${output} Strip String ${output}
|
||||
${output} Ctn Run Command With Connector And Return Result ${tc} ${command} ${timeout}
|
||||
|
||||
# 3. Compare with expected
|
||||
Should Match Regexp
|
||||
... ${output}
|
||||
|
Loading…
x
Reference in New Issue
Block a user