mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-26 23:24:27 +02:00
enh(plugin): add ansible host IP to Ansible Tower discovery (#5221)
REFS: CTOR-311
This commit is contained in:
parent
06b1fe2731
commit
591981bf37
@ -71,6 +71,14 @@ sub run {
|
|||||||
$host{inventory_name} = $host->{summary_fields}->{inventory}->{name};
|
$host{inventory_name} = $host->{summary_fields}->{inventory}->{name};
|
||||||
$host{groups} = $host->{summary_fields}->{groups}->{results};
|
$host{groups} = $host->{summary_fields}->{groups}->{results};
|
||||||
$host{enabled} = $host->{enabled};
|
$host{enabled} = $host->{enabled};
|
||||||
|
# Get the ansible host IP address if available
|
||||||
|
eval {
|
||||||
|
my $json = decode_json($host->{variables});
|
||||||
|
$host{ansible_host} = $json->{ansible_host} || '';
|
||||||
|
};
|
||||||
|
if ($@) {
|
||||||
|
$host{ansible_host} = '';
|
||||||
|
}
|
||||||
push @disco_data, \%host;
|
push @disco_data, \%host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
43
tests/apps/automation/ansible/tower/discovery.robot
Normal file
43
tests/apps/automation/ansible/tower/discovery.robot
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
*** Settings ***
|
||||||
|
Documentation Check the discovery mode with api custom mode
|
||||||
|
|
||||||
|
Resource ${CURDIR}${/}..${/}..${/}..${/}..${/}resources/import.resource
|
||||||
|
|
||||||
|
Suite Setup Start Mockoon ${MOCKOON_JSON}
|
||||||
|
Suite Teardown Stop Mockoon
|
||||||
|
Test Timeout 120s
|
||||||
|
|
||||||
|
|
||||||
|
*** Variables ***
|
||||||
|
${MOCKOON_JSON} ${CURDIR}${/}ansible_tower.json
|
||||||
|
|
||||||
|
${CMD} ${CENTREON_PLUGINS}
|
||||||
|
... --plugin=apps::automation::ansible::tower::plugin
|
||||||
|
... --custommode=api
|
||||||
|
... --hostname=${HOSTNAME}
|
||||||
|
... --username=username
|
||||||
|
... --password=password
|
||||||
|
... --port=${APIPORT}
|
||||||
|
... --mode=discovery
|
||||||
|
|
||||||
|
*** Test Cases ***
|
||||||
|
Discovery ${tc}
|
||||||
|
[Tags] apps automation ansible api
|
||||||
|
|
||||||
|
${command} Catenate
|
||||||
|
... ${CMD}
|
||||||
|
... ${extraoptions}
|
||||||
|
|
||||||
|
${output} Run ${command}
|
||||||
|
|
||||||
|
${output} Strip String ${output}
|
||||||
|
Should Be Equal As Strings
|
||||||
|
... ${output}
|
||||||
|
... ${expected_result}
|
||||||
|
... Wrong output result for command:\n${CMD}\n\nObtained:\n${output}\n\nExpected:\n${expected_result}\n
|
||||||
|
... values=False
|
||||||
|
... collapse_spaces=True
|
||||||
|
|
||||||
|
Examples: tc extraoptions expected_result --
|
||||||
|
... 1 | jq '.results | length' 10
|
||||||
|
... 2 | jq -r '.results | map(select(.ansible_host != "" and (.ansible_host | test("^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$") | not))) | .[].ansible_host' ${EMPTY}
|
Loading…
x
Reference in New Issue
Block a user