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:
|
with open(log_path, 'r') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
# Pattern: reporting check result #<id> ...
|
# 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:
|
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):
|
if str(found_id) == str(tc):
|
||||||
# Write the output to the file
|
# Write the output to the file
|
||||||
output_path = output_path or f"/tmp/connector.output.{tc}"
|
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
|
import re
|
||||||
with open(log_path, 'r') as f:
|
with open(log_path, 'r') as f:
|
||||||
for line in 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:
|
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):
|
if str(found_id) == str(tc):
|
||||||
output_path = output_path or f"/tmp/connector.output.{tc}"
|
output_path = output_path or f"/tmp/connector.output.{tc}"
|
||||||
with open(output_path, 'w') as out:
|
with open(output_path, 'w') as out:
|
||||||
|
@ -107,18 +107,53 @@ Ctn Verify Command Without Connector Output
|
|||||||
... values=False
|
... values=False
|
||||||
... collapse_spaces=True
|
... collapse_spaces=True
|
||||||
|
|
||||||
Ctn Run Command With Connector And Check Result As Strings
|
Ctn Connector Log Contains Result
|
||||||
[Arguments] ${command} ${expected_result} ${tc}=0 ${timeout}=${TIMEOUT}
|
[Arguments] ${tc}
|
||||||
Log To Console c
|
${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.output
|
||||||
Remove File /tmp/connector.command.log
|
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 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
|
# 1. Extract the result from the log and write to /tmp/connector.output
|
||||||
Ctn Extract Result From Log ${tc}
|
Ctn Extract Result From Log ${tc}
|
||||||
# 2. Read the file
|
# 2. Read the file
|
||||||
${output} Get File /tmp/connector.output
|
${output} Get File /tmp/connector.output
|
||||||
${output} Strip String ${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
|
Should Be Equal As Strings
|
||||||
... ${expected_result}
|
... ${expected_result}
|
||||||
... ${output}
|
... ${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
|
Ctn Run Command With Connector And Check Result As Regexp
|
||||||
[Arguments] ${command} ${expected_result} ${tc}=0 ${timeout}=${TIMEOUT}
|
[Arguments] ${command} ${expected_result} ${tc}=0 ${timeout}=${TIMEOUT}
|
||||||
Log To Console c
|
Log To Console c
|
||||||
Remove File /tmp/connector.output
|
${output} Ctn Run Command With Connector And Return Result ${tc} ${command} ${timeout}
|
||||||
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}
|
|
||||||
# 3. Compare with expected
|
# 3. Compare with expected
|
||||||
Should Match Regexp
|
Should Match Regexp
|
||||||
... ${output}
|
... ${output}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user