From 7ee913eb1f8505d6463dee302f96268c2ebabef3 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Fri, 7 Jan 2022 15:46:47 -0500 Subject: [PATCH] if /opt/so/conf/wazuh/initial_agent_registration.log doesnt exist, and agent is already registered, touch file and exit 0 to prevent salt error --- salt/wazuh/files/agent/wazuh-register-agent | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/salt/wazuh/files/agent/wazuh-register-agent b/salt/wazuh/files/agent/wazuh-register-agent index 98ab9fb13..3c5db61e9 100755 --- a/salt/wazuh/files/agent/wazuh-register-agent +++ b/salt/wazuh/files/agent/wazuh-register-agent @@ -60,8 +60,14 @@ register_agent() { GOT_KEY=$? if [[ -z "$AGENT_ID" || -z "$AGENT_KEY" || $GOT_ID -ne 0 || $GOT_KEY -ne 0 ]]; then - echo "Failed Result: $API_RESULT" - return 1 + if echo $API_RESULT | jq -er .message | grep -q "There is an agent with the same name"; then + echo "Agent $AGENT_NAME already registered!" + touch /opt/so/conf/wazuh/initial_agent_registration.log + exit 0 + else + echo "Failed Result: $API_RESULT" + return 1 + fi else echo "Agent '$AGENT_NAME' with ID '$AGENT_ID' added." echo "Key for agent '$AGENT_ID' received."