From dbda2208fb0cad4f7da86a351d451b8625237b80 Mon Sep 17 00:00:00 2001 From: Eric Schoville <eric.schoville@wisc.edu> Date: Thu, 23 Jan 2020 10:22:41 -0600 Subject: [PATCH] Move JSON log formatting to function --- run_agent.sh | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/run_agent.sh b/run_agent.sh index 8a91d79..0779b2e 100755 --- a/run_agent.sh +++ b/run_agent.sh @@ -64,6 +64,21 @@ handle_term() { fi } +set_json_log() { + + if [ ! -z ${JSON_LOG} ]; then + + # https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html + + # Replace the text line with a json formatted line. This is ugly. + find . -type f -name log4j.properties \ + -exec sed -i '/^log4j.appender.stdout.layout.ConversionPattern/c\log4j.appender.stdout.layout.ConversionPattern={"dateIso8601":"%d","timeZone":"%d{z}","priority":"%p","category":"%c","message":"%m"}%n' \ + {} \; + + fi + +} + # Login to the API with the provided username and password and get the URL and session id # so we can check the status of this agent. Read results into Bash array @@ -87,6 +102,14 @@ if [ -z "$status_code" ]; then exit 1 fi +error_code=$(jq -nr "${json}|.error.code") + +if [ -z "$error_code" ]; then + echo "Error connecting to Informatica API: ${error_code}" + echo $json + exit 1 +fi + result=($(jq -nr "${json}|.serverUrl, .icSessionId")) if [ -z "$result" ]; then @@ -146,8 +169,9 @@ else fi -# set shutdown hooks +# set shutdown hooks and set the json log file if necessary prep_term +set_json_log # run application ./infaagent startup @@ -190,16 +214,6 @@ curl -sS -H "Content-Type: application/json" \ term_child_pid=$(cat $PID_FILE) echoGreen "Secure Agent Starting pid:$term_child_pid" -if [[ -n ${JSON_LOG+x} && "$JSON_LOG" = true ]]; then - - # https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html - - # Replace the text line with a json formatted line. This is ugly. - find . -type f -name log4j.properties \ - -exec sed -i '/^log4j.appender.stdout.layout.ConversionPattern/c\log4j.appender.stdout.layout.ConversionPattern={"dateIso8601":"%d","timeZone":"%d{z}","priority":"%p","category":"%c","message":"%m"}%n' \ - {} \; - -fi # wait until terminated while true -- GitLab