From adf60521b0c5e8b8fba00cb449e89a6de70d952a Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Tue, 7 May 2024 18:01:49 +0800 Subject: [PATCH 01/24] create script to setup channel and remove objects --- ace-setup-mq/readme.md | 0 ace-setup-mq/remove-resources.sh | 82 ++++++++++++++++++ ace-setup-mq/setup-channel.sh | 143 +++++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 ace-setup-mq/readme.md create mode 100644 ace-setup-mq/remove-resources.sh create mode 100644 ace-setup-mq/setup-channel.sh diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md new file mode 100644 index 0000000..e69de29 diff --git a/ace-setup-mq/remove-resources.sh b/ace-setup-mq/remove-resources.sh new file mode 100644 index 0000000..22325d4 --- /dev/null +++ b/ace-setup-mq/remove-resources.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# Functions +printUsage() { + echo -e "\033[1;33mThis script will delete the specified objects:\033[0m" + echo "1. Check user running this script has authority to execute MQSC commands" + echo "2. Delete the specified listener" + echo "3. Delete the specified channel" + echo "4. Delete the specified topic" + echo "Usage: $0 -q QMGR_NAME -u AUTH_USER -b MQ_BIN_PATH -l LISTENER_NAME -c CHANNEL_NAME -t TOPIC_NAME" + echo "Example: $0 -q QM1 -b /opt/mqm/bin -l LS2 -c INSTANA.ACE.SVRCONN -t INSTANA.ACE.BROKER.TOPIC" +} + +# 1. Check the current user has authority to execute MQSC commands +checkUserAuthority() { + if groups | grep -q '\bmqm\b'; then + echo -e "\033[1;32mINFO:The user launches the script belongs to mqm group\033[0m" + else + echo -e "\033[1;31mERROR:The user launches the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" + exit 1 + fi +} + +# 2. delete objects +deleteListener() { + if [ -n "$LISTENER_NAME" ]; then + echo "stop and delete listener" + echo "stop LISTENER($LISTENER_NAME) IGNSTATE(YES)" | runmqsc "$QMGR_NAME" + echo "delete LISTENER($LISTENER_NAME) IGNSTATE(YES)" | runmqsc "$QMGR_NAME" + fi + +} +deleteChannel() { + if [ -n "$CHANNEL_NAME" ]; then + echo "delete channel object" + echo "delete channel($CHANNEL_NAME) IGNSTATE(NO)" | runmqsc "$QMGR_NAME" + fi +} +deleteTopic() { + if [ -n "$TOPIC_NAME" ]; then + echo "delete topic object" + echo "delete topic($TOPIC_NAME) AUTHREC(YES)" | runmqsc "$QMGR_NAME" + fi +} + + +# Init +# Check the parameters +while getopts "q:u:b:l:c:t:" arg; do + case ${arg} in + q) + QMGR_NAME=${OPTARG} + ;; + b) + MQ_BIN_PATH=${OPTARG} + ;; + l) + LISTENER_NAME=${OPTARG} + ;; + c) + CHANNEL_NAME=${OPTARG} + ;; + t) + TOPIC_NAME=${OPTARG} + ;; + ?) + printUsage + exit 1 + ;; + esac +done +shift $(($OPTIND - 1)) + +# Setup mq environment to accept mqsc command. +echo "INFO: setup mq environment to accept mqsc command" +. $MQ_BIN_PATH/setmqenv -s + + +printUsage +checkUserAuthority +deleteListener +deleteChannel +deleteTopic \ No newline at end of file diff --git a/ace-setup-mq/setup-channel.sh b/ace-setup-mq/setup-channel.sh new file mode 100644 index 0000000..50c5130 --- /dev/null +++ b/ace-setup-mq/setup-channel.sh @@ -0,0 +1,143 @@ +#!/bin/bash +#Functions +# 0: print usage +printUsage(){ + echo -e "\033[1;33mThis script will try to cover following things:\033[0m" + echo "1. Check user running this script has authority to execute MQSC commands" + echo "2. Check the available listener ports and define a new one if there is no available" + echo "3. Define a channel and set authrec for it with the specified user" + echo "4. Check the connectivity of the channel with specified user" + echo "5. Define a topic or use existing topic object for topic string '$SYS/Broker' and set authrec for it" + echo "6. List the useful info you can use to set in configuration.yaml for plugin.ace" + echo "Usage: $0 QMGR_NAME AUTH_USER MQ_BIN_PATH" + echo "Example $0 QM1 root /opt/mqm/bin" +} + +# 1. Check the current user has authority to execute MQSC commands +checkUserAuthority(){ + if groups | grep -q '\bmqm\b'; then + echo -e "\033[1;32mINFO:The user launches the script belongs to mqm group\033[0m" + else + echo -e "\033[1;31mERROR:The user launches the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" + exit 1 + fi +} +# 2. Print out all available listener ports +getListenerPort(){ + available_ports='' + listener_ports=$(echo "dis LISTENER(*) PORT" | runmqsc "$QMGR_NAME" | grep -oP 'PORT\(\K\d+') + if [ -n "$listener_ports" ]; then + echo "$listener_ports" | while read -r port; do + echo -e "\033[1;32mINFO: Test the listener port: $port. \033[0m" + if nc -zv localhost "$port"; then + available_ports+=" $port" + echo -e "\033[1;32mINFO: Port $port is open and accepting connections.\033[0m" + else + echo -e "\033[1;33mWARNING: Port $port is not open or not accepting connections.\033[0m" + fi + done + else + echo "Create a listener as there is no listener port found" + echo "DEFINE LISTENER($LISTENER_NAME) TRPTYPE(TCP) PORT($LISTENER_PORT)" | runmqsc "$QMGR_NAME" + echo "START LISTENER($LISTENER_NAME) IGNSTATE(NO)" | runmqsc "$QMGR_NAME" + if nc -zv localhost "$LISTENER_PORT"; then + available_ports+=" $LISTENER_PORT" + echo -e "\033[1;32mINFO: Port $LISTENER_PORT is open and accepting connections.\033[0m" + else + echo -e "\033[1;31mERROR: Port $LISTENER_PORT is not open or not accepting connections.\033[0m" + fi + fi +} + +# 3. Check whether the channel with $CHANNEL_NAME exists +prepChannelAndTopic(){ + CHECK_CHANNEL=$(echo "DISPLAY CHANNEL($CHANNEL_NAME)" | runmqsc "$QMGR_NAME") + if [[ "$CHECK_CHANNEL" != *"not found"* ]]; then + echo -e "\033[1;31mERROR:The channel exists, please try another CHANNEL_NAME or delete the existing channel and rerun the script. \033[0m" + echo -e "\033[1;31mT$CHECK_CHANNEL\033[0m" + exit 1 + fi + # Execute the MQSC commands + echo "$MQSC_CHECK_CHANNEL" | runmqsc "$QMGR_NAME" + + # 4. Verify the user authority of channel connection + OUTPUT=$(echo "dis chlauth($CHANNEL_NAME) MATCH(RUNCHECK) CLNTUSER('$AUTH_USER') ADDRESS('0.0.0.0')" | runmqsc "$QMGR_NAME") + EXPECTED_OUTPUT="AMQ9783I: Channel will run using MCAUSER('$AUTH_USER')." + + if [[ "$OUTPUT" == *"$EXPECTED_OUTPUT"* ]]; then + echo -e "\033[1;32mINFO:The channel authority is set successfully with output:\033[0m" + echo -e "\033[1;32m$EXPECTED_OUTPUT\033[0m" + EXISTING_TOPIC=$(echo "dis TOPIC(*) WHERE(TOPICSTR EQ '$TOPIC_STR')" | runmqsc "$QMGR_NAME") + # 5. Create a topic if it doesn't exist + if [[ $EXISTING_TOPIC == *"not found"* ]]; then + echo "Topic object with TOPICSTR '$TOPIC_STR' not found. Creating a new one..." + echo "DEFINE TOPIC($TOPIC_NAME) TOPICSTR('$TOPIC_STR')" | runmqsc "$QMGR_NAME" + else + echo -e "\033[1;32mINFO:Topic object with TOPICSTR '$TOPIC_STR' already exists.\033[0m" + TOPIC_NAME=$(echo "$EXISTING_TOPIC" | sed -n '/TOPIC(\*/d; s/^.*TOPIC(\([^)]*\)).*$/\1/p') + fi + # Set authrec for the topic + echo "SET AUTHREC profile($TOPIC_NAME) objtype(topic) PRINCIPAL('$AUTH_USER') AUTHADD(ALL)" + echo "Set authrec for the topic $TOPIC_NAME" + # Verify the authrec exists + EXISTING_AUTHREC=$(echo "DIS AUTHREC PROFILE($TOPIC_NAME) OBJTYPE(TOPIC)" | runmqsc "$QMGR_NAME") + # Print the result + if [[ $EXISTING_AUTHREC == *"not found"* ]]; then + echo -e "\033[1;31mERROR:AUTHREC for topic '$TOPIC_NAME' does not exist.Please check the commands execution result\033[0m" + echo "$EXISTING_AUTHREC" + else + echo -e "\033[1;32mINFO:AUTHREC for topic '$TOPIC_NAME' exists.\033[0m" + fi + else + echo -e "\033[1;31mERROR:The channel authority is failed to set. Check the blocking AUTHREC and fix it.\033[0m" + echo -e "$OUTPUT" + exit 1 + fi +} + +# 6. Print out useful info you need in setting configuration.yaml +printConnInfo(){ + echo -e "\033[1;32mHint: Please set the configuration.yaml for ACE sensor with following info:\033[0m" + echo -e "\033[1;32m queuemanagerName: $QMGR_NAME\033[0m" + echo -e "\033[1;32m mqport: $available_ports\033[0m" + echo -e "\033[1;32m channel: $CHANNEL_NAME\033[0m" + echo -e "\033[1;32m mqUsername: $AUTH_USER\033[0m" + echo -e "\033[1;32mThis tool only covers basic info, for other info, like user password and SSL related info, please check manually and set properly.\033[0m" + echo -e "\033[1;31mIf you want to delete the resources you created, please make sure you have downloaded the remove-resources.sh script and run like following: \033[0m" + echo "chmod +x remove-resources.sh" + echo "./remove-resources.sh -listener $LISTENER_NAME -channel $CHANNEL_NAME -topic $TOPIC_NAME" +} + + +# 0: Init +# Define the variables +QMGR_NAME=$1 +AUTH_USER=$2 +MQ_BIN_PATH=$3 +CHANNEL_NAME='INSTANA.ACE.SVRCONN' +TOPIC_NAME='INSTANA.ACE.BROKER.TOPIC' +TOPIC_STR='$SYS/Broker' +LISTENER_NAME='INSTANA.ACE.LS' +LISTENER_PORT='2121' +# Check the number of parameters +if [ "$#" -ne 3 ]; then + printUsage + exit 1 +fi +# Setup mq environment to accept mqsc command. +echo "INFO: setup mq environment to accept mqsc command" +. $MQ_BIN_PATH/setmqenv -s + +# Define the MQSC commands fro channel creating +read -r -d '' MQSC_CHECK_CHANNEL << EOF +DEFINE CHANNEL($CHANNEL_NAME) CHLTYPE(SVRCONN) TRPTYPE(TCP) MCAUSER('$AUTH_USER') +SET CHLAUTH($CHANNEL_NAME) TYPE(BLOCKUSER) USERLIST('nobody') DESCR('Block all users except authorized users') +SET AUTHREC profile($CHANNEL_NAME) objtype(channel) PRINCIPAL('$AUTH_USER') AUTHADD(ALL) +REFRESH SECURITY +EOF + +printUsage +checkUserAuthority +getListenerPort +prepChannelAndTopic +printConnInfo From d53b97a4ce9f87b0f40cae75a1f43db5852d1b22 Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Wed, 8 May 2024 15:40:29 +0800 Subject: [PATCH 02/24] refine the steps --- ace-setup-mq/readme.md | 25 +++++++++++ ace-setup-mq/remove-resources.sh | 76 +++++++++++++++++++------------- ace-setup-mq/setup-channel.sh | 73 ++++++++++++++++++------------ 3 files changed, 117 insertions(+), 57 deletions(-) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index e69de29..f34bd95 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -0,0 +1,25 @@ +# Instructions for setup-channel.sh +## Descriptions +The script `setup-channel.sh` is used to create resources and set authority properly in QMGR for ACE sensor. +## Usage +1. Download the script remove-resources.sh +2. Set it executable +3. Go to the directory and execute the script +```sh + ./setup-channel.sh +``` +# Instructions for remove-resources.sh +## Descriptions +The script `remove-resources.sh` is used to revert the authority granted with script `setup-channel.sh` and delete the objects created in QMGR for ACE sensor. +## Usage +1. Download the script remove-resources.sh +2. Set it executable +3. Go to the directory and execute the script +```sh + ./remove-resources.sh -q -d [-u AUTH_USER] [-l LISTENER_NAME] [-c CHANNEL_NAME] [-t TOPIC_NAME] +``` + + + + + diff --git a/ace-setup-mq/remove-resources.sh b/ace-setup-mq/remove-resources.sh index 22325d4..63a25ba 100644 --- a/ace-setup-mq/remove-resources.sh +++ b/ace-setup-mq/remove-resources.sh @@ -3,56 +3,73 @@ printUsage() { echo -e "\033[1;33mThis script will delete the specified objects:\033[0m" echo "1. Check user running this script has authority to execute MQSC commands" - echo "2. Delete the specified listener" - echo "3. Delete the specified channel" - echo "4. Delete the specified topic" - echo "Usage: $0 -q QMGR_NAME -u AUTH_USER -b MQ_BIN_PATH -l LISTENER_NAME -c CHANNEL_NAME -t TOPIC_NAME" - echo "Example: $0 -q QM1 -b /opt/mqm/bin -l LS2 -c INSTANA.ACE.SVRCONN -t INSTANA.ACE.BROKER.TOPIC" + echo "2. Remove the qmgr authority(connect+inq) for the specified user" + echo "3. Delete the specified listener/channel/topic" + echo -e "\033[1;33m Usage: $0 -q -d [-u AUTH_USER] [-l LISTENER_NAME] [-c CHANNEL_NAME] [-t TOPIC_NAME]\033[0m" + echo -e "\033[1;33m Example: $0 -q QM1 -d /opt/mqm/bin -u root -l LS2 -c INSTANA.ACE.SVRCONN -t INSTANA.ACE.BROKER.TOPIC\033[0m" } # 1. Check the current user has authority to execute MQSC commands -checkUserAuthority() { +preCheck() { + echo "Check current user has the authority to execute MQSC commands" if groups | grep -q '\bmqm\b'; then echo -e "\033[1;32mINFO:The user launches the script belongs to mqm group\033[0m" else - echo -e "\033[1;31mERROR:The user launches the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" + echo -e "\033[1;31mERROR:The user who launches the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" exit 1 fi + + echo "Check the MQ_BIN_PATH exists and file setmqenv exists" + if [ ! -d "$MQ_BIN_PATH" ] || [ ! -f "$MQ_BIN_PATH/setmqenv" ]; then + echo -e "\033[1;31mERROR: the path $MQ_BIN_PATH or the file $MQ_BIN_PATH/setmqenv does not exist or both don't exist.\033[0m" + exit 1 + else + echo -e "\033[1;32mINFO: the $MQ_BIN_PATH and related file setmqenv exist.\033[0m" + fi +} +# 2. remove authority to qmgr for specified user +removeQmgrAuth(){ + echo -e "\033[1;33mINFO: Remove connect/inq authority to qmgr $QMGR_NAME for user $AUTH_USER listener object033[0m" + setmqaut -m $QMGR_NAME -t qmgr -p $AUTH_USER -connect -inq } -# 2. delete objects -deleteListener() { +# 3. delete objects +deleteObjects() { if [ -n "$LISTENER_NAME" ]; then - echo "stop and delete listener" - echo "stop LISTENER($LISTENER_NAME) IGNSTATE(YES)" | runmqsc "$QMGR_NAME" - echo "delete LISTENER($LISTENER_NAME) IGNSTATE(YES)" | runmqsc "$QMGR_NAME" + echo -e "\033[1;33mINFO: delete listener object033[0m" + echo "stop LISTENER($LISTENER_NAME) IGNSTATE(NO)" | runmqsc "$QMGR_NAME" + echo "delete LISTENER($LISTENER_NAME) IGNSTATE(NO)" | runmqsc "$QMGR_NAME" + else + echo -e "\033[1;32mINFO: nothing to delete as the listener name $LISTENER_NAME is empty\033[0m" fi - -} -deleteChannel() { + if [ -n "$CHANNEL_NAME" ]; then - echo "delete channel object" - echo "delete channel($CHANNEL_NAME) IGNSTATE(NO)" | runmqsc "$QMGR_NAME" + echo -e "\033[1;33mINFO: delete channel object033[0m" + echo "delete channel($CHANNEL_NAME) IGNSTATE(YES)" | runmqsc "$QMGR_NAME" + else + echo -e "\033[1;32mINFO: nothing to delete as the channel name $CHANNEL_NAME is empty\033[0m" fi -} -deleteTopic() { if [ -n "$TOPIC_NAME" ]; then - echo "delete topic object" + echo -e "\033[1;33mINFO: delete topic object033[0m" echo "delete topic($TOPIC_NAME) AUTHREC(YES)" | runmqsc "$QMGR_NAME" + else + echo -e "\033[1;32mINFO: nothing to delete as the topic name $TOPIC_NAME is empty\033[0m" fi } - # Init # Check the parameters -while getopts "q:u:b:l:c:t:" arg; do - case ${arg} in +while getopts ":q:d:u:l:c:t:" opt; do + case ${opt} in q) QMGR_NAME=${OPTARG} ;; - b) + d) MQ_BIN_PATH=${OPTARG} ;; + u) + AUTH_USER=${OPTARG} + ;; l) LISTENER_NAME=${OPTARG} ;; @@ -71,12 +88,11 @@ done shift $(($OPTIND - 1)) # Setup mq environment to accept mqsc command. -echo "INFO: setup mq environment to accept mqsc command" +echo -e "\033[1;33mINFO: setup mq environment to accept mqsc command\033[0m" . $MQ_BIN_PATH/setmqenv -s - +# Call functions printUsage -checkUserAuthority -deleteListener -deleteChannel -deleteTopic \ No newline at end of file +preCheck +removeQmgrAuth +deleteObjects diff --git a/ace-setup-mq/setup-channel.sh b/ace-setup-mq/setup-channel.sh index 50c5130..a47fdd1 100644 --- a/ace-setup-mq/setup-channel.sh +++ b/ace-setup-mq/setup-channel.sh @@ -9,47 +9,65 @@ printUsage(){ echo "4. Check the connectivity of the channel with specified user" echo "5. Define a topic or use existing topic object for topic string '$SYS/Broker' and set authrec for it" echo "6. List the useful info you can use to set in configuration.yaml for plugin.ace" - echo "Usage: $0 QMGR_NAME AUTH_USER MQ_BIN_PATH" - echo "Example $0 QM1 root /opt/mqm/bin" + echo -e "\033[1;33mUsage: $0 \033[0m" + echo -e "\033[1;33mExample $0 QM1 /opt/mqm/bin root\033[0m" } # 1. Check the current user has authority to execute MQSC commands -checkUserAuthority(){ +preCheck(){ if groups | grep -q '\bmqm\b'; then - echo -e "\033[1;32mINFO:The user launches the script belongs to mqm group\033[0m" + echo -e "\033[1;32mINFO:The user who launches the script belongs to mqm group\033[0m" else echo -e "\033[1;31mERROR:The user launches the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" exit 1 fi + + echo "Check the MQ_BIN_PATH exists and file setmqenv exists" + if [ ! -d "$MQ_BIN_PATH" ] || [ ! -f "$MQ_BIN_PATH/setmqenv" ]; then + echo -e "\033[1;31mERROR: the path $MQ_BIN_PATH or the file $MQ_BIN_PATH/setmqenv does not exist or both don't exist.\033[0m" + exit 1 + else + echo -e "\033[1;32mINFO: the $MQ_BIN_PATH and related file setmqenv exist.\033[0m" + fi +} +# 2. Set correct authority for $AUTH_USER to access QMGR. +setQmgrAuth(){ + echo -e "\033[1;33mINFO: set authority for user $AUTH_USER to access QMGR.\033[0m" + setmqaut -m $QMGR_NAME -t qmgr -p $AUTH_USER +connect +inq + echo -e "\033[1;32m$(dmpmqaut -m $QMGR_NAME -t qmgr)\033[0m" + # } -# 2. Print out all available listener ports +# 3. Print out all available listener ports getListenerPort(){ - available_ports='' listener_ports=$(echo "dis LISTENER(*) PORT" | runmqsc "$QMGR_NAME" | grep -oP 'PORT\(\K\d+') if [ -n "$listener_ports" ]; then - echo "$listener_ports" | while read -r port; do - echo -e "\033[1;32mINFO: Test the listener port: $port. \033[0m" - if nc -zv localhost "$port"; then - available_ports+=" $port" + while read -r port; do + if checkPort $port; then + AVAILABLE_PORTS+=" $port" echo -e "\033[1;32mINFO: Port $port is open and accepting connections.\033[0m" else echo -e "\033[1;33mWARNING: Port $port is not open or not accepting connections.\033[0m" fi - done + done <<< "$listener_ports" else echo "Create a listener as there is no listener port found" echo "DEFINE LISTENER($LISTENER_NAME) TRPTYPE(TCP) PORT($LISTENER_PORT)" | runmqsc "$QMGR_NAME" echo "START LISTENER($LISTENER_NAME) IGNSTATE(NO)" | runmqsc "$QMGR_NAME" - if nc -zv localhost "$LISTENER_PORT"; then - available_ports+=" $LISTENER_PORT" - echo -e "\033[1;32mINFO: Port $LISTENER_PORT is open and accepting connections.\033[0m" - else - echo -e "\033[1;31mERROR: Port $LISTENER_PORT is not open or not accepting connections.\033[0m" + if checkPort $LISTENER_PORT; then + AVAILABLE_PORTS+=" $LISTENER_PORT" + echo -e "\033[1;32mINFO: Port $LISTENER_PORT is open and accepting connections.\033[0m" + else + echo -e "\033[1;31mERROR: Port $LISTENER_PORT is not open or not accepting connections.\033[0m" fi fi } -# 3. Check whether the channel with $CHANNEL_NAME exists +checkPort() { + local port="$1" + nc -zv localhost "$port" >/dev/null 2>&1 +} + +# 4. Create channel and topic, set authrec for them. prepChannelAndTopic(){ CHECK_CHANNEL=$(echo "DISPLAY CHANNEL($CHANNEL_NAME)" | runmqsc "$QMGR_NAME") if [[ "$CHECK_CHANNEL" != *"not found"* ]]; then @@ -60,7 +78,7 @@ prepChannelAndTopic(){ # Execute the MQSC commands echo "$MQSC_CHECK_CHANNEL" | runmqsc "$QMGR_NAME" - # 4. Verify the user authority of channel connection + # Verify the user authority of channel connection OUTPUT=$(echo "dis chlauth($CHANNEL_NAME) MATCH(RUNCHECK) CLNTUSER('$AUTH_USER') ADDRESS('0.0.0.0')" | runmqsc "$QMGR_NAME") EXPECTED_OUTPUT="AMQ9783I: Channel will run using MCAUSER('$AUTH_USER')." @@ -68,7 +86,7 @@ prepChannelAndTopic(){ echo -e "\033[1;32mINFO:The channel authority is set successfully with output:\033[0m" echo -e "\033[1;32m$EXPECTED_OUTPUT\033[0m" EXISTING_TOPIC=$(echo "dis TOPIC(*) WHERE(TOPICSTR EQ '$TOPIC_STR')" | runmqsc "$QMGR_NAME") - # 5. Create a topic if it doesn't exist + # Create a topic if it doesn't exist if [[ $EXISTING_TOPIC == *"not found"* ]]; then echo "Topic object with TOPICSTR '$TOPIC_STR' not found. Creating a new one..." echo "DEFINE TOPIC($TOPIC_NAME) TOPICSTR('$TOPIC_STR')" | runmqsc "$QMGR_NAME" @@ -95,30 +113,30 @@ prepChannelAndTopic(){ fi } -# 6. Print out useful info you need in setting configuration.yaml +# 4. Print out useful info you need in setting configuration.yaml printConnInfo(){ echo -e "\033[1;32mHint: Please set the configuration.yaml for ACE sensor with following info:\033[0m" echo -e "\033[1;32m queuemanagerName: $QMGR_NAME\033[0m" - echo -e "\033[1;32m mqport: $available_ports\033[0m" + echo -e "\033[1;32m mqport: $AVAILABLE_PORTS\033[0m" echo -e "\033[1;32m channel: $CHANNEL_NAME\033[0m" echo -e "\033[1;32m mqUsername: $AUTH_USER\033[0m" echo -e "\033[1;32mThis tool only covers basic info, for other info, like user password and SSL related info, please check manually and set properly.\033[0m" - echo -e "\033[1;31mIf you want to delete the resources you created, please make sure you have downloaded the remove-resources.sh script and run like following: \033[0m" - echo "chmod +x remove-resources.sh" - echo "./remove-resources.sh -listener $LISTENER_NAME -channel $CHANNEL_NAME -topic $TOPIC_NAME" + echo -e "\033[1;33mINFO: If you want to revert the authority and clean up the objects created, please make sure you have downloaded the remove-resources.sh script and run like following: \033[0m" + echo "./remove-resources.sh -q $QMGR_NAME -d $MQ_BIN_PATH -u $AUTH_USER -l $LISTENER_NAME -c $CHANNEL_NAME -t $TOPIC_NAME" } # 0: Init # Define the variables QMGR_NAME=$1 -AUTH_USER=$2 -MQ_BIN_PATH=$3 +MQ_BIN_PATH=$2 +AUTH_USER=$3 CHANNEL_NAME='INSTANA.ACE.SVRCONN' TOPIC_NAME='INSTANA.ACE.BROKER.TOPIC' TOPIC_STR='$SYS/Broker' LISTENER_NAME='INSTANA.ACE.LS' LISTENER_PORT='2121' +AVAILABLE_PORTS='' # Check the number of parameters if [ "$#" -ne 3 ]; then printUsage @@ -137,7 +155,8 @@ REFRESH SECURITY EOF printUsage -checkUserAuthority +preCheck +setQmgrAuth getListenerPort prepChannelAndTopic printConnInfo From 674b3630858ae451fd72951d02edb705efacf6d7 Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Wed, 8 May 2024 15:50:41 +0800 Subject: [PATCH 03/24] refine --- ace-setup-mq/setup-channel.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ace-setup-mq/setup-channel.sh b/ace-setup-mq/setup-channel.sh index a47fdd1..c6465f5 100644 --- a/ace-setup-mq/setup-channel.sh +++ b/ace-setup-mq/setup-channel.sh @@ -113,7 +113,7 @@ prepChannelAndTopic(){ fi } -# 4. Print out useful info you need in setting configuration.yaml +# 5. Print out useful info you need in setting configuration.yaml printConnInfo(){ echo -e "\033[1;32mHint: Please set the configuration.yaml for ACE sensor with following info:\033[0m" echo -e "\033[1;32m queuemanagerName: $QMGR_NAME\033[0m" From 4a8c1ec418a4ef1d4ca9c5fcf7dfbd76e32dae53 Mon Sep 17 00:00:00 2001 From: zhaohouf <35989725+zhaohouf@users.noreply.github.com> Date: Thu, 9 May 2024 10:10:41 +0800 Subject: [PATCH 04/24] Update readme.md --- ace-setup-mq/readme.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index f34bd95..03b4092 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -2,22 +2,24 @@ ## Descriptions The script `setup-channel.sh` is used to create resources and set authority properly in QMGR for ACE sensor. ## Usage -1. Download the script remove-resources.sh -2. Set it executable +1. Download the script `setup-channel.sh` +2. Set it executable `chmod +x setup-channel.sh` 3. Go to the directory and execute the script ```sh ./setup-channel.sh ``` +**Note:** the user to execute the script should be a member of mqm group. It is different than $AUTH_USER in the script. # Instructions for remove-resources.sh ## Descriptions The script `remove-resources.sh` is used to revert the authority granted with script `setup-channel.sh` and delete the objects created in QMGR for ACE sensor. ## Usage -1. Download the script remove-resources.sh -2. Set it executable +1. Download the script `remove-resources.sh` +2. Set it executable `chmod +x remove-resources.sh` 3. Go to the directory and execute the script ```sh ./remove-resources.sh -q -d [-u AUTH_USER] [-l LISTENER_NAME] [-c CHANNEL_NAME] [-t TOPIC_NAME] ``` +**Note:** the user to execute the script should be a member of mqm group. It is different than $AUTH_USER in the script. From a116258ed44fd7994c6b99711fe94d96a55537e8 Mon Sep 17 00:00:00 2001 From: zhaohouf <35989725+zhaohouf@users.noreply.github.com> Date: Thu, 9 May 2024 10:27:15 +0800 Subject: [PATCH 05/24] Update readme.md --- ace-setup-mq/readme.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index 03b4092..8e68e87 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -1,6 +1,8 @@ # Instructions for setup-channel.sh ## Descriptions The script `setup-channel.sh` is used to create resources and set authority properly in QMGR for ACE sensor. +* The script must be run with a user who belongs to mqm group and run on the machine which hosts the queue manager. +* The AUTH_USER used in the script is the user that you want to grant authority and it doesn't need to be a privileged user. ## Usage 1. Download the script `setup-channel.sh` 2. Set it executable `chmod +x setup-channel.sh` @@ -8,10 +10,11 @@ The script `setup-channel.sh` is used to create resources and set authority prop ```sh ./setup-channel.sh ``` -**Note:** the user to execute the script should be a member of mqm group. It is different than $AUTH_USER in the script. # Instructions for remove-resources.sh ## Descriptions The script `remove-resources.sh` is used to revert the authority granted with script `setup-channel.sh` and delete the objects created in QMGR for ACE sensor. +* The script must be run with a user who belongs to mqm group and run on the machine which hosts the queue manager. +* The AUTH_USER used in the script is the user that you used in `setup-channel.sh`. ## Usage 1. Download the script `remove-resources.sh` 2. Set it executable `chmod +x remove-resources.sh` @@ -19,8 +22,6 @@ The script `remove-resources.sh` is used to revert the authority granted with sc ```sh ./remove-resources.sh -q -d [-u AUTH_USER] [-l LISTENER_NAME] [-c CHANNEL_NAME] [-t TOPIC_NAME] ``` -**Note:** the user to execute the script should be a member of mqm group. It is different than $AUTH_USER in the script. - From c2786330b802d9243e5b75b29cb1bc2b5ad1b729 Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Thu, 9 May 2024 15:09:55 +0800 Subject: [PATCH 06/24] update for comments --- ace-setup-mq/setup-channel.sh | 47 ++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/ace-setup-mq/setup-channel.sh b/ace-setup-mq/setup-channel.sh index c6465f5..636a766 100644 --- a/ace-setup-mq/setup-channel.sh +++ b/ace-setup-mq/setup-channel.sh @@ -9,8 +9,8 @@ printUsage(){ echo "4. Check the connectivity of the channel with specified user" echo "5. Define a topic or use existing topic object for topic string '$SYS/Broker' and set authrec for it" echo "6. List the useful info you can use to set in configuration.yaml for plugin.ace" - echo -e "\033[1;33mUsage: $0 \033[0m" - echo -e "\033[1;33mExample $0 QM1 /opt/mqm/bin root\033[0m" + echo -e "\033[1;33mUsage: $0 -q -d -u \033[0m" + echo -e "\033[1;33mExample $0 -q QM1 -d /opt/mqm/bin -u root\033[0m" } # 1. Check the current user has authority to execute MQSC commands @@ -33,9 +33,14 @@ preCheck(){ # 2. Set correct authority for $AUTH_USER to access QMGR. setQmgrAuth(){ echo -e "\033[1;33mINFO: set authority for user $AUTH_USER to access QMGR.\033[0m" - setmqaut -m $QMGR_NAME -t qmgr -p $AUTH_USER +connect +inq - echo -e "\033[1;32m$(dmpmqaut -m $QMGR_NAME -t qmgr)\033[0m" - # + RESULT=$(echo "setmqaut -m $QMGR_NAME -t qmgr -p $AUTH_USER +connect +inq") + if [[ "$RESULT" != *"completed successfully"*]]; then + echo -e "\033[1;31mERROR: failed to set the authority for user $AUTH_USER to $QMGR_NAME\033[0m" + echo -e "\033[1;31m$RESULT\033[0m" + exit 1 + else + echo "dmpmqaut -m $QMGR_NAME -t qmgr" + fi } # 3. Print out all available listener ports getListenerPort(){ @@ -57,7 +62,8 @@ getListenerPort(){ AVAILABLE_PORTS+=" $LISTENER_PORT" echo -e "\033[1;32mINFO: Port $LISTENER_PORT is open and accepting connections.\033[0m" else - echo -e "\033[1;31mERROR: Port $LISTENER_PORT is not open or not accepting connections.\033[0m" + echo -e "\033[1;31mERROR: Port $LISTENER_PORT is not open or not accepting connections. Please check and fix.\033[0m" + exit 1 fi fi } @@ -103,6 +109,7 @@ prepChannelAndTopic(){ if [[ $EXISTING_AUTHREC == *"not found"* ]]; then echo -e "\033[1;31mERROR:AUTHREC for topic '$TOPIC_NAME' does not exist.Please check the commands execution result\033[0m" echo "$EXISTING_AUTHREC" + exit 1 else echo -e "\033[1;32mINFO:AUTHREC for topic '$TOPIC_NAME' exists.\033[0m" fi @@ -128,20 +135,32 @@ printConnInfo(){ # 0: Init # Define the variables -QMGR_NAME=$1 -MQ_BIN_PATH=$2 -AUTH_USER=$3 CHANNEL_NAME='INSTANA.ACE.SVRCONN' TOPIC_NAME='INSTANA.ACE.BROKER.TOPIC' TOPIC_STR='$SYS/Broker' LISTENER_NAME='INSTANA.ACE.LS' LISTENER_PORT='2121' AVAILABLE_PORTS='' -# Check the number of parameters -if [ "$#" -ne 3 ]; then - printUsage - exit 1 -fi +# Check the parameters +while getopts ":q:d:u:" opt; do + case ${opt} in + q) + QMGR_NAME=${OPTARG} + ;; + d) + MQ_BIN_PATH=${OPTARG} + ;; + u) + AUTH_USER=${OPTARG} + ;; + ?) + printUsage + exit 1 + ;; + esac +done +shift $(($OPTIND - 1)) + # Setup mq environment to accept mqsc command. echo "INFO: setup mq environment to accept mqsc command" . $MQ_BIN_PATH/setmqenv -s From 6bcd8adcfcaf5cd96388015e46570f32256cdfed Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Thu, 9 May 2024 15:12:31 +0800 Subject: [PATCH 07/24] update for comments --- ace-setup-mq/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index 8e68e87..1fb5b43 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -8,7 +8,7 @@ The script `setup-channel.sh` is used to create resources and set authority prop 2. Set it executable `chmod +x setup-channel.sh` 3. Go to the directory and execute the script ```sh - ./setup-channel.sh + ./setup-channel.sh -q -d -u ``` # Instructions for remove-resources.sh ## Descriptions From 79684e74013857dcac708aed4a5c3fecb4787e5f Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Thu, 9 May 2024 16:58:17 +0800 Subject: [PATCH 08/24] fix a syntax error --- ace-setup-mq/setup-channel.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ace-setup-mq/setup-channel.sh b/ace-setup-mq/setup-channel.sh index 636a766..37c69aa 100644 --- a/ace-setup-mq/setup-channel.sh +++ b/ace-setup-mq/setup-channel.sh @@ -9,6 +9,7 @@ printUsage(){ echo "4. Check the connectivity of the channel with specified user" echo "5. Define a topic or use existing topic object for topic string '$SYS/Broker' and set authrec for it" echo "6. List the useful info you can use to set in configuration.yaml for plugin.ace" + echo -e "\033[1;31mNote: this script will cover most cases, but sometimes if you fail to create the mq objects, please contact IBM Instana support or contact IBM MQ support team for help. \033[0m" echo -e "\033[1;33mUsage: $0 -q -d -u \033[0m" echo -e "\033[1;33mExample $0 -q QM1 -d /opt/mqm/bin -u root\033[0m" } @@ -34,7 +35,7 @@ preCheck(){ setQmgrAuth(){ echo -e "\033[1;33mINFO: set authority for user $AUTH_USER to access QMGR.\033[0m" RESULT=$(echo "setmqaut -m $QMGR_NAME -t qmgr -p $AUTH_USER +connect +inq") - if [[ "$RESULT" != *"completed successfully"*]]; then + if [[ "$RESULT" != *"completed successfully"* ]]; then echo -e "\033[1;31mERROR: failed to set the authority for user $AUTH_USER to $QMGR_NAME\033[0m" echo -e "\033[1;31m$RESULT\033[0m" exit 1 From 711215b2752a7226640e6a11fde003f7c08a4eaa Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Thu, 9 May 2024 17:35:38 +0800 Subject: [PATCH 09/24] check command result --- ace-setup-mq/setup-channel.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ace-setup-mq/setup-channel.sh b/ace-setup-mq/setup-channel.sh index 37c69aa..74fe026 100644 --- a/ace-setup-mq/setup-channel.sh +++ b/ace-setup-mq/setup-channel.sh @@ -19,7 +19,7 @@ preCheck(){ if groups | grep -q '\bmqm\b'; then echo -e "\033[1;32mINFO:The user who launches the script belongs to mqm group\033[0m" else - echo -e "\033[1;31mERROR:The user launches the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" + echo -e "\033[1;31mERROR:The user who launches the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" exit 1 fi @@ -34,15 +34,17 @@ preCheck(){ # 2. Set correct authority for $AUTH_USER to access QMGR. setQmgrAuth(){ echo -e "\033[1;33mINFO: set authority for user $AUTH_USER to access QMGR.\033[0m" - RESULT=$(echo "setmqaut -m $QMGR_NAME -t qmgr -p $AUTH_USER +connect +inq") + RESULT=$(echo "setmqaut -m "$QMGR_NAME" -t qmgr -p "$AUTH_USER" +connect +inq" 2>&1) if [[ "$RESULT" != *"completed successfully"* ]]; then echo -e "\033[1;31mERROR: failed to set the authority for user $AUTH_USER to $QMGR_NAME\033[0m" echo -e "\033[1;31m$RESULT\033[0m" exit 1 else - echo "dmpmqaut -m $QMGR_NAME -t qmgr" + echo -e "\033[1;33mINFO: The authority has been set succesfully for user $AUTH_USER\033[0m" + echo "$(dmpmqaut -m $QMGR_NAME -t qmgr 2>&1)" fi } + # 3. Print out all available listener ports getListenerPort(){ listener_ports=$(echo "dis LISTENER(*) PORT" | runmqsc "$QMGR_NAME" | grep -oP 'PORT\(\K\d+') From 4e79502933b01437e52d9c338583f2b976bcdea1 Mon Sep 17 00:00:00 2001 From: zhaohouf <35989725+zhaohouf@users.noreply.github.com> Date: Fri, 10 May 2024 10:05:02 +0800 Subject: [PATCH 10/24] Update ace-setup-mq/remove-resources.sh Co-authored-by: Lijian Wang <61578414+wlijiancp4mcm@users.noreply.github.com> --- ace-setup-mq/remove-resources.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ace-setup-mq/remove-resources.sh b/ace-setup-mq/remove-resources.sh index 63a25ba..7863ba9 100644 --- a/ace-setup-mq/remove-resources.sh +++ b/ace-setup-mq/remove-resources.sh @@ -11,7 +11,7 @@ printUsage() { # 1. Check the current user has authority to execute MQSC commands preCheck() { - echo "Check current user has the authority to execute MQSC commands" + echo "Check if current user has the authority to execute MQSC commands" if groups | grep -q '\bmqm\b'; then echo -e "\033[1;32mINFO:The user launches the script belongs to mqm group\033[0m" else From 7d88d35ae8bd5ce24c0023e588aa9e5659af4168 Mon Sep 17 00:00:00 2001 From: zhaohouf <35989725+zhaohouf@users.noreply.github.com> Date: Fri, 10 May 2024 10:05:14 +0800 Subject: [PATCH 11/24] Update ace-setup-mq/remove-resources.sh Co-authored-by: Lijian Wang <61578414+wlijiancp4mcm@users.noreply.github.com> --- ace-setup-mq/remove-resources.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ace-setup-mq/remove-resources.sh b/ace-setup-mq/remove-resources.sh index 7863ba9..e2b1979 100644 --- a/ace-setup-mq/remove-resources.sh +++ b/ace-setup-mq/remove-resources.sh @@ -13,7 +13,7 @@ printUsage() { preCheck() { echo "Check if current user has the authority to execute MQSC commands" if groups | grep -q '\bmqm\b'; then - echo -e "\033[1;32mINFO:The user launches the script belongs to mqm group\033[0m" + echo -e "\033[1;32mINFO:The user launched the script belongs to mqm group\033[0m" else echo -e "\033[1;31mERROR:The user who launches the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" exit 1 From cc95ab3d76f212f76e5da083332c3c82753887ea Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Fri, 10 May 2024 10:31:43 +0800 Subject: [PATCH 12/24] rename files --- ace-setup-mq/{setup-channel.sh => prep-mq.sh} | 28 +++++++++---------- ace-setup-mq/readme.md | 16 +++++------ .../{remove-resources.sh => revert-mq.sh} | 22 +++++++-------- 3 files changed, 33 insertions(+), 33 deletions(-) rename ace-setup-mq/{setup-channel.sh => prep-mq.sh} (83%) rename ace-setup-mq/{remove-resources.sh => revert-mq.sh} (76%) diff --git a/ace-setup-mq/setup-channel.sh b/ace-setup-mq/prep-mq.sh similarity index 83% rename from ace-setup-mq/setup-channel.sh rename to ace-setup-mq/prep-mq.sh index 74fe026..0b376fc 100644 --- a/ace-setup-mq/setup-channel.sh +++ b/ace-setup-mq/prep-mq.sh @@ -17,26 +17,26 @@ printUsage(){ # 1. Check the current user has authority to execute MQSC commands preCheck(){ if groups | grep -q '\bmqm\b'; then - echo -e "\033[1;32mINFO:The user who launches the script belongs to mqm group\033[0m" + echo -e "\033[1;32mINFO: The user launched the script belongs to mqm group\033[0m" else - echo -e "\033[1;31mERROR:The user who launches the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" + echo -e "\033[1;31mERROR: The user launched the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" exit 1 fi echo "Check the MQ_BIN_PATH exists and file setmqenv exists" if [ ! -d "$MQ_BIN_PATH" ] || [ ! -f "$MQ_BIN_PATH/setmqenv" ]; then - echo -e "\033[1;31mERROR: the path $MQ_BIN_PATH or the file $MQ_BIN_PATH/setmqenv does not exist or both don't exist.\033[0m" + echo -e "\033[1;31mERROR: The path $MQ_BIN_PATH or the file $MQ_BIN_PATH/setmqenv does not exist or both don't exist.\033[0m" exit 1 else - echo -e "\033[1;32mINFO: the $MQ_BIN_PATH and related file setmqenv exist.\033[0m" + echo -e "\033[1;32mINFO: The $MQ_BIN_PATH and related file setmqenv exist.\033[0m" fi } # 2. Set correct authority for $AUTH_USER to access QMGR. setQmgrAuth(){ - echo -e "\033[1;33mINFO: set authority for user $AUTH_USER to access QMGR.\033[0m" + echo -e "\033[1;33mINFO: Set authority for user $AUTH_USER to access QMGR.\033[0m" RESULT=$(echo "setmqaut -m "$QMGR_NAME" -t qmgr -p "$AUTH_USER" +connect +inq" 2>&1) if [[ "$RESULT" != *"completed successfully"* ]]; then - echo -e "\033[1;31mERROR: failed to set the authority for user $AUTH_USER to $QMGR_NAME\033[0m" + echo -e "\033[1;31mERROR: Failed to set the authority for user $AUTH_USER to $QMGR_NAME\033[0m" echo -e "\033[1;31m$RESULT\033[0m" exit 1 else @@ -80,7 +80,7 @@ checkPort() { prepChannelAndTopic(){ CHECK_CHANNEL=$(echo "DISPLAY CHANNEL($CHANNEL_NAME)" | runmqsc "$QMGR_NAME") if [[ "$CHECK_CHANNEL" != *"not found"* ]]; then - echo -e "\033[1;31mERROR:The channel exists, please try another CHANNEL_NAME or delete the existing channel and rerun the script. \033[0m" + echo -e "\033[1;31mERROR: The channel exists, please try another CHANNEL_NAME or delete the existing channel and rerun the script. \033[0m" echo -e "\033[1;31mT$CHECK_CHANNEL\033[0m" exit 1 fi @@ -92,7 +92,7 @@ prepChannelAndTopic(){ EXPECTED_OUTPUT="AMQ9783I: Channel will run using MCAUSER('$AUTH_USER')." if [[ "$OUTPUT" == *"$EXPECTED_OUTPUT"* ]]; then - echo -e "\033[1;32mINFO:The channel authority is set successfully with output:\033[0m" + echo -e "\033[1;32mINFO: The channel authority is set successfully with output:\033[0m" echo -e "\033[1;32m$EXPECTED_OUTPUT\033[0m" EXISTING_TOPIC=$(echo "dis TOPIC(*) WHERE(TOPICSTR EQ '$TOPIC_STR')" | runmqsc "$QMGR_NAME") # Create a topic if it doesn't exist @@ -100,7 +100,7 @@ prepChannelAndTopic(){ echo "Topic object with TOPICSTR '$TOPIC_STR' not found. Creating a new one..." echo "DEFINE TOPIC($TOPIC_NAME) TOPICSTR('$TOPIC_STR')" | runmqsc "$QMGR_NAME" else - echo -e "\033[1;32mINFO:Topic object with TOPICSTR '$TOPIC_STR' already exists.\033[0m" + echo -e "\033[1;32mINFO: Topic object with TOPICSTR '$TOPIC_STR' already exists.\033[0m" TOPIC_NAME=$(echo "$EXISTING_TOPIC" | sed -n '/TOPIC(\*/d; s/^.*TOPIC(\([^)]*\)).*$/\1/p') fi # Set authrec for the topic @@ -110,14 +110,14 @@ prepChannelAndTopic(){ EXISTING_AUTHREC=$(echo "DIS AUTHREC PROFILE($TOPIC_NAME) OBJTYPE(TOPIC)" | runmqsc "$QMGR_NAME") # Print the result if [[ $EXISTING_AUTHREC == *"not found"* ]]; then - echo -e "\033[1;31mERROR:AUTHREC for topic '$TOPIC_NAME' does not exist.Please check the commands execution result\033[0m" + echo -e "\033[1;31mERROR: AUTHREC for topic '$TOPIC_NAME' does not exist.Please check the commands execution result\033[0m" echo "$EXISTING_AUTHREC" exit 1 else - echo -e "\033[1;32mINFO:AUTHREC for topic '$TOPIC_NAME' exists.\033[0m" + echo -e "\033[1;32mINFO: AUTHREC for topic '$TOPIC_NAME' exists.\033[0m" fi else - echo -e "\033[1;31mERROR:The channel authority is failed to set. Check the blocking AUTHREC and fix it.\033[0m" + echo -e "\033[1;31mERROR: The channel authority is failed to set. Check the blocking AUTHREC and fix it.\033[0m" echo -e "$OUTPUT" exit 1 fi @@ -131,8 +131,8 @@ printConnInfo(){ echo -e "\033[1;32m channel: $CHANNEL_NAME\033[0m" echo -e "\033[1;32m mqUsername: $AUTH_USER\033[0m" echo -e "\033[1;32mThis tool only covers basic info, for other info, like user password and SSL related info, please check manually and set properly.\033[0m" - echo -e "\033[1;33mINFO: If you want to revert the authority and clean up the objects created, please make sure you have downloaded the remove-resources.sh script and run like following: \033[0m" - echo "./remove-resources.sh -q $QMGR_NAME -d $MQ_BIN_PATH -u $AUTH_USER -l $LISTENER_NAME -c $CHANNEL_NAME -t $TOPIC_NAME" + echo -e "\033[1;33mINFO: If you want to revert the authority and clean up the objects created, please make sure you have downloaded the revert-mq.sh script and run like following: \033[0m" + echo "./revert-mq.sh -q $QMGR_NAME -d $MQ_BIN_PATH -u $AUTH_USER -l $LISTENER_NAME -c $CHANNEL_NAME -t $TOPIC_NAME" } diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index 1fb5b43..83831e8 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -4,23 +4,23 @@ The script `setup-channel.sh` is used to create resources and set authority prop * The script must be run with a user who belongs to mqm group and run on the machine which hosts the queue manager. * The AUTH_USER used in the script is the user that you want to grant authority and it doesn't need to be a privileged user. ## Usage -1. Download the script `setup-channel.sh` -2. Set it executable `chmod +x setup-channel.sh` +1. Download the script `prep-mq.sh` +2. Set it executable `chmod +x prep-mq.sh` 3. Go to the directory and execute the script ```sh - ./setup-channel.sh -q -d -u + ./prep-mq.sh -q -d -u ``` # Instructions for remove-resources.sh ## Descriptions -The script `remove-resources.sh` is used to revert the authority granted with script `setup-channel.sh` and delete the objects created in QMGR for ACE sensor. +The script `revert-mq.sh` is used to revert the authority granted with script `prep-revert.sh` and delete the objects created in QMGR for ACE sensor. * The script must be run with a user who belongs to mqm group and run on the machine which hosts the queue manager. -* The AUTH_USER used in the script is the user that you used in `setup-channel.sh`. +* The AUTH_USER used in the script is the user that you used in `prep-mq.sh`. ## Usage -1. Download the script `remove-resources.sh` -2. Set it executable `chmod +x remove-resources.sh` +1. Download the script `revert-mq.sh` +2. Set it executable `chmod +x revert-mq.sh` 3. Go to the directory and execute the script ```sh - ./remove-resources.sh -q -d [-u AUTH_USER] [-l LISTENER_NAME] [-c CHANNEL_NAME] [-t TOPIC_NAME] + ./revert-mq.sh -q -d [-u AUTH_USER] [-l LISTENER_NAME] [-c CHANNEL_NAME] [-t TOPIC_NAME] ``` diff --git a/ace-setup-mq/remove-resources.sh b/ace-setup-mq/revert-mq.sh similarity index 76% rename from ace-setup-mq/remove-resources.sh rename to ace-setup-mq/revert-mq.sh index e2b1979..d02f3b5 100644 --- a/ace-setup-mq/remove-resources.sh +++ b/ace-setup-mq/revert-mq.sh @@ -13,18 +13,18 @@ printUsage() { preCheck() { echo "Check if current user has the authority to execute MQSC commands" if groups | grep -q '\bmqm\b'; then - echo -e "\033[1;32mINFO:The user launched the script belongs to mqm group\033[0m" + echo -e "\033[1;32mINFO: The user launched the script belongs to mqm group\033[0m" else - echo -e "\033[1;31mERROR:The user who launches the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" + echo -e "\033[1;31mERROR: The user launched the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" exit 1 fi echo "Check the MQ_BIN_PATH exists and file setmqenv exists" if [ ! -d "$MQ_BIN_PATH" ] || [ ! -f "$MQ_BIN_PATH/setmqenv" ]; then - echo -e "\033[1;31mERROR: the path $MQ_BIN_PATH or the file $MQ_BIN_PATH/setmqenv does not exist or both don't exist.\033[0m" + echo -e "\033[1;31mERROR: The path $MQ_BIN_PATH or the file $MQ_BIN_PATH/setmqenv does not exist or both don't exist.\033[0m" exit 1 else - echo -e "\033[1;32mINFO: the $MQ_BIN_PATH and related file setmqenv exist.\033[0m" + echo -e "\033[1;32mINFO: The $MQ_BIN_PATH and related file setmqenv exist.\033[0m" fi } # 2. remove authority to qmgr for specified user @@ -36,24 +36,24 @@ removeQmgrAuth(){ # 3. delete objects deleteObjects() { if [ -n "$LISTENER_NAME" ]; then - echo -e "\033[1;33mINFO: delete listener object033[0m" + echo -e "\033[1;33mINFO: Delete listener object033[0m" echo "stop LISTENER($LISTENER_NAME) IGNSTATE(NO)" | runmqsc "$QMGR_NAME" echo "delete LISTENER($LISTENER_NAME) IGNSTATE(NO)" | runmqsc "$QMGR_NAME" else - echo -e "\033[1;32mINFO: nothing to delete as the listener name $LISTENER_NAME is empty\033[0m" + echo -e "\033[1;32mINFO: Nothing to delete as the listener name $LISTENER_NAME is empty\033[0m" fi if [ -n "$CHANNEL_NAME" ]; then - echo -e "\033[1;33mINFO: delete channel object033[0m" + echo -e "\033[1;33mINFO: Delete channel object033[0m" echo "delete channel($CHANNEL_NAME) IGNSTATE(YES)" | runmqsc "$QMGR_NAME" else - echo -e "\033[1;32mINFO: nothing to delete as the channel name $CHANNEL_NAME is empty\033[0m" + echo -e "\033[1;32mINFO: Nothing to delete as the channel name $CHANNEL_NAME is empty\033[0m" fi if [ -n "$TOPIC_NAME" ]; then - echo -e "\033[1;33mINFO: delete topic object033[0m" + echo -e "\033[1;33mINFO: Delete topic object033[0m" echo "delete topic($TOPIC_NAME) AUTHREC(YES)" | runmqsc "$QMGR_NAME" else - echo -e "\033[1;32mINFO: nothing to delete as the topic name $TOPIC_NAME is empty\033[0m" + echo -e "\033[1;32mINFO: Nothing to delete as the topic name $TOPIC_NAME is empty\033[0m" fi } @@ -88,7 +88,7 @@ done shift $(($OPTIND - 1)) # Setup mq environment to accept mqsc command. -echo -e "\033[1;33mINFO: setup mq environment to accept mqsc command\033[0m" +echo -e "\033[1;33mINFO: Setup mq environment to accept mqsc command\033[0m" . $MQ_BIN_PATH/setmqenv -s # Call functions From bf293550207042b09f53770bc8fafd6a455b3083 Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Fri, 10 May 2024 17:20:06 +0800 Subject: [PATCH 13/24] update for aix --- ace-setup-mq/prep-mq.sh | 59 ++++++++++++++++------ ace-setup-mq/revert-mq.sh | 102 ++++++++++++++++++++++++++++++++------ 2 files changed, 129 insertions(+), 32 deletions(-) diff --git a/ace-setup-mq/prep-mq.sh b/ace-setup-mq/prep-mq.sh index 0b376fc..927e038 100644 --- a/ace-setup-mq/prep-mq.sh +++ b/ace-setup-mq/prep-mq.sh @@ -16,13 +16,15 @@ printUsage(){ # 1. Check the current user has authority to execute MQSC commands preCheck(){ - if groups | grep -q '\bmqm\b'; then + # Check user authority + if groups | tr ' ' '\n' | grep -q '^mqm$'; then echo -e "\033[1;32mINFO: The user launched the script belongs to mqm group\033[0m" else echo -e "\033[1;31mERROR: The user launched the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" exit 1 fi + # check mq bin path echo "Check the MQ_BIN_PATH exists and file setmqenv exists" if [ ! -d "$MQ_BIN_PATH" ] || [ ! -f "$MQ_BIN_PATH/setmqenv" ]; then echo -e "\033[1;31mERROR: The path $MQ_BIN_PATH or the file $MQ_BIN_PATH/setmqenv does not exist or both don't exist.\033[0m" @@ -30,24 +32,37 @@ preCheck(){ else echo -e "\033[1;32mINFO: The $MQ_BIN_PATH and related file setmqenv exist.\033[0m" fi + + # Setup mq environment to accept mqsc command. + echo -e "\033[1;33mINFO: Setup mq environment to accept mqsc command\033[0m" + . $MQ_BIN_PATH/setmqenv -s + if [ $? -eq 0 ]; then + echo -e "\033[1;32mINFO: The environment has been set successfully. \033[0m" + else + echo -e "\033[1;31mERROR: Failed to set the environment\033[0m" + exit 1 + fi } # 2. Set correct authority for $AUTH_USER to access QMGR. setQmgrAuth(){ echo -e "\033[1;33mINFO: Set authority for user $AUTH_USER to access QMGR.\033[0m" - RESULT=$(echo "setmqaut -m "$QMGR_NAME" -t qmgr -p "$AUTH_USER" +connect +inq" 2>&1) - if [[ "$RESULT" != *"completed successfully"* ]]; then - echo -e "\033[1;31mERROR: Failed to set the authority for user $AUTH_USER to $QMGR_NAME\033[0m" - echo -e "\033[1;31m$RESULT\033[0m" - exit 1 + echo "The user $AUTH_USER has following authority before setting:" + echo "$(dmpmqaut -m $QMGR_NAME -t qmgr -p $AUTH_USER)" + setmqaut -m "$QMGR_NAME" -t qmgr -p "$AUTH_USER" +connect +inq + if [ $? -eq 0 ]; then + echo -e "\033[1;32mINFO: The authority has been set succesfully for user $AUTH_USER\033[0m" + echo "The user $AUTH_USER has following authority after setting:" + echo "$(dmpmqaut -m $QMGR_NAME -t qmgr -p $AUTH_USER 2>&1)" else - echo -e "\033[1;33mINFO: The authority has been set succesfully for user $AUTH_USER\033[0m" - echo "$(dmpmqaut -m $QMGR_NAME -t qmgr 2>&1)" + echo -e "\033[1;31mERROR: Failed to set the authority for user $AUTH_USER to $QMGR_NAME\033[0m" + echo -e "\033[1;31m$RESULT\033[0m" + exit 1 fi } # 3. Print out all available listener ports getListenerPort(){ - listener_ports=$(echo "dis LISTENER(*) PORT" | runmqsc "$QMGR_NAME" | grep -oP 'PORT\(\K\d+') + listener_ports=$(echo "dis LISTENER(*) PORT" | runmqsc "$QMGR_NAME" | awk '/PORT/ {gsub("[^0-9]", "", $NF); print $NF}') if [ -n "$listener_ports" ]; then while read -r port; do if checkPort $port; then @@ -73,7 +88,12 @@ getListenerPort(){ checkPort() { local port="$1" - nc -zv localhost "$port" >/dev/null 2>&1 + os_type=$(uname -s) + if [[ "$os_type" == "Linux" ]]; then + nc -zv localhost "$port" >/dev/null 2>&1 + else + telnet localhost "$port" >/dev/null 2>&1 + fi } # 4. Create channel and topic, set authrec for them. @@ -81,7 +101,9 @@ prepChannelAndTopic(){ CHECK_CHANNEL=$(echo "DISPLAY CHANNEL($CHANNEL_NAME)" | runmqsc "$QMGR_NAME") if [[ "$CHECK_CHANNEL" != *"not found"* ]]; then echo -e "\033[1;31mERROR: The channel exists, please try another CHANNEL_NAME or delete the existing channel and rerun the script. \033[0m" - echo -e "\033[1;31mT$CHECK_CHANNEL\033[0m" + echo -e "\033[1;31mYou can use revert-mq.sh to delete this channel and revert all created objects:\033[0m" + echo -e "./revert-mq.sh -q $QMGR_NAME -d $MQ_BIN_PATH -u $AUTH_USER -l $LISTENER_NAME -c $CHANNEL_NAME" + echo "$CHECK_CHANNEL" exit 1 fi # Execute the MQSC commands @@ -127,7 +149,7 @@ prepChannelAndTopic(){ printConnInfo(){ echo -e "\033[1;32mHint: Please set the configuration.yaml for ACE sensor with following info:\033[0m" echo -e "\033[1;32m queuemanagerName: $QMGR_NAME\033[0m" - echo -e "\033[1;32m mqport: $AVAILABLE_PORTS\033[0m" + echo -e "\033[1;32m mqport: $AVAILABLE_PORTS (choose one)\033[0m" echo -e "\033[1;32m channel: $CHANNEL_NAME\033[0m" echo -e "\033[1;32m mqUsername: $AUTH_USER\033[0m" echo -e "\033[1;32mThis tool only covers basic info, for other info, like user password and SSL related info, please check manually and set properly.\033[0m" @@ -141,7 +163,7 @@ printConnInfo(){ CHANNEL_NAME='INSTANA.ACE.SVRCONN' TOPIC_NAME='INSTANA.ACE.BROKER.TOPIC' TOPIC_STR='$SYS/Broker' -LISTENER_NAME='INSTANA.ACE.LS' +LISTENER_NAME='INSTANA.ACE.LST' LISTENER_PORT='2121' AVAILABLE_PORTS='' # Check the parameters @@ -164,9 +186,14 @@ while getopts ":q:d:u:" opt; do done shift $(($OPTIND - 1)) -# Setup mq environment to accept mqsc command. -echo "INFO: setup mq environment to accept mqsc command" -. $MQ_BIN_PATH/setmqenv -s +if [[ -z "$QMGR_NAME" || -z "$MQ_BIN_PATH" || -z "$AUTH_USER" ]]; then + echo -e "\033[1;31mERROR: These arguments are required, but seems they are not set correctly." + echo "QMGR_NAME: $QMGR_NAME" + echo "MQ_BIN_PATH: $MQ_BIN_PATH" + echo "AUTH_USER:$AUTH_USER" + printUsage + exit 1 +fi # Define the MQSC commands fro channel creating read -r -d '' MQSC_CHECK_CHANNEL << EOF diff --git a/ace-setup-mq/revert-mq.sh b/ace-setup-mq/revert-mq.sh index d02f3b5..96cb4f8 100644 --- a/ace-setup-mq/revert-mq.sh +++ b/ace-setup-mq/revert-mq.sh @@ -11,14 +11,16 @@ printUsage() { # 1. Check the current user has authority to execute MQSC commands preCheck() { + # Check user authority echo "Check if current user has the authority to execute MQSC commands" - if groups | grep -q '\bmqm\b'; then + if groups | tr ' ' '\n' | grep -q '^mqm$'; then echo -e "\033[1;32mINFO: The user launched the script belongs to mqm group\033[0m" else echo -e "\033[1;31mERROR: The user launched the script doesn't belong to mqm group, please use an authorized user to execute MQSC commands\033[0m" exit 1 fi + # check mq bin path echo "Check the MQ_BIN_PATH exists and file setmqenv exists" if [ ! -d "$MQ_BIN_PATH" ] || [ ! -f "$MQ_BIN_PATH/setmqenv" ]; then echo -e "\033[1;31mERROR: The path $MQ_BIN_PATH or the file $MQ_BIN_PATH/setmqenv does not exist or both don't exist.\033[0m" @@ -26,34 +28,98 @@ preCheck() { else echo -e "\033[1;32mINFO: The $MQ_BIN_PATH and related file setmqenv exist.\033[0m" fi + + # Setup mq environment to accept mqsc command. + echo -e "\033[1;33mINFO: Setup mq environment to accept mqsc command\033[0m" + . $MQ_BIN_PATH/setmqenv -s + if [ $? -eq 0 ]; then + echo -e "\033[1;32mINFO: The environment has been set successfully. \033[0m" + else + echo -e "\033[1;31mERROR: Failed to set the environment\033[0m" + exit 1 + fi } # 2. remove authority to qmgr for specified user removeQmgrAuth(){ - echo -e "\033[1;33mINFO: Remove connect/inq authority to qmgr $QMGR_NAME for user $AUTH_USER listener object033[0m" - setmqaut -m $QMGR_NAME -t qmgr -p $AUTH_USER -connect -inq + echo -e "\033[1;33mINFO: Remove connect/inq authority to qmgr $QMGR_NAME for user $AUTH_USER listener object\033[0m" + AUTH_RECORDS=$(dmpmqaut -m $QMGR_NAME -t qmgr -p $AUTH_USER 2>&1) + echo "The user $AUTH_USER has following authority before removing: $AUTH_RECORDS" + if [[ "$AUTH_RECORDS" == *"No matching authority records."* ]]; then + echo -e "\033[1;32mINFO: No matching authority records for $AUTH_USER\033[0m" + else + setmqaut -m $QMGR_NAME -t qmgr -p $AUTH_USER -connect -inq + if [ $? -eq 0 ]; then + echo -e "\033[1;32mINFO: The authority has been removed succesfully for user $AUTH_USER\033[0m" + echo "The user $AUTH_USER has following authority after removing:" + else + echo -e "\033[1;31mERROR: Failed to remove the authority for user $AUTH_USER to $QMGR_NAME, please remove it manually\033[0m" + echo "$(dmpmqaut -m $QMGR_NAME -t qmgr -p $AUTH_USER 2>&1)" + fi + fi + } # 3. delete objects deleteObjects() { + # delete listener if [ -n "$LISTENER_NAME" ]; then - echo -e "\033[1;33mINFO: Delete listener object033[0m" - echo "stop LISTENER($LISTENER_NAME) IGNSTATE(NO)" | runmqsc "$QMGR_NAME" - echo "delete LISTENER($LISTENER_NAME) IGNSTATE(NO)" | runmqsc "$QMGR_NAME" + echo -e "\033[1;33mINFO: Delete listener object\033[0m" + listener=$(echo "dis LISTENER($LISTENER_NAME)" | runmqsc "$QMGR_NAME" 2>&1) + if [[ "$listener" == *"not found"* ]]; then + echo -e "\033[1;32mINFO: Nothing to delete as the $LISTENER_NAME is not found\033[0m" + else + echo "stop LISTENER($LISTENER_NAME) IGNSTATE(NO)" | runmqsc "$QMGR_NAME" + if [ $? -eq 0 ]; then + echo "delete LISTENER($LISTENER_NAME) IGNSTATE(NO)" | runmqsc "$QMGR_NAME" + if [ $? -eq 0 ]; then + echo -e "\033[1;32mINFO: Listenter $LISTENER_NAME has been deleted successfully.\033[0m" + else + echo -e "\033[1;31mERROR: Failed to delete listenter $LISTENER_NAME, please remove it manually\033[0m" + echo "dis LISTENER($LISTENER_NAME)" | runmqsc "$QMGR_NAME" + fi + else + echo -e "\033[1;31mERROR: Failed to stop listenter $LISTENER_NAME, please chekc and remove it manually\033[0m" + fi + fi else - echo -e "\033[1;32mINFO: Nothing to delete as the listener name $LISTENER_NAME is empty\033[0m" + echo -e "\033[1;32mINFO: Nothing to delete as the listener name is empty\033[0m" fi + # delete channel if [ -n "$CHANNEL_NAME" ]; then - echo -e "\033[1;33mINFO: Delete channel object033[0m" - echo "delete channel($CHANNEL_NAME) IGNSTATE(YES)" | runmqsc "$QMGR_NAME" + echo -e "\033[1;33mINFO: Delete channel object\033[0m" + channel=$(echo "dis CHANNEL($CHANNEL_NAME)" | runmqsc "$QMGR_NAME" 2>&1) + if [[ "$channel" == *"not found"* ]]; then + echo -e "\033[1;32mINFO: Nothing to delete as the $CHANNEL_NAME is not found\033[0m" + else + echo "delete CHANNEL($CHANNEL_NAME) IGNSTATE(YES)" | runmqsc "$QMGR_NAME" + if [ $? -eq 0 ]; then + echo -e "\033[1;32mINFO: Channel $CHANNEL_NAME has been deleted successfully.\033[0m" + else + echo -e "\033[1;31mERROR: Failed to delete channel $CHANNEL_NAME, please remove it manually\033[0m" + echo "dis CHANNEL($CHANNEL_NAME)" | runmqsc "$QMGR_NAME" + fi + fi else - echo -e "\033[1;32mINFO: Nothing to delete as the channel name $CHANNEL_NAME is empty\033[0m" + echo -e "\033[1;32mINFO: Nothing to delete as the channel name is empty\033[0m" fi + # delete topic if [ -n "$TOPIC_NAME" ]; then - echo -e "\033[1;33mINFO: Delete topic object033[0m" - echo "delete topic($TOPIC_NAME) AUTHREC(YES)" | runmqsc "$QMGR_NAME" + echo -e "\033[1;33mINFO: Delete topic object\033[0m" + topic=$(echo "dis TOPIC($TOPIC_NAME)" | runmqsc "$QMGR_NAME" 2>&1) + if [[ "$topic" == *"not found"* ]]; then + echo -e "\033[1;32mINFO: Nothing to delete as the $TOPIC_NAME is not found\033[0m" + else + echo "delete TOPIC($TOPIC_NAME) AUTHREC(YES)" | runmqsc "$QMGR_NAME" + if [ $? -eq 0 ]; then + echo -e "\033[1;32mINFO: Topic object $TOPIC_NAME has been deleted successfully.\033[0m" + else + echo -e "\033[1;31mERROR: Failed to delete topic object $TOPIC_NAME, please remove it manually\033[0m" + echo "dis TOPIC($CHANNEL_NAME)" | runmqsc "$QMGR_NAME" + fi + fi else - echo -e "\033[1;32mINFO: Nothing to delete as the topic name $TOPIC_NAME is empty\033[0m" + echo -e "\033[1;32mINFO: Nothing to delete as the topic name is empty\033[0m" fi } @@ -87,9 +153,13 @@ while getopts ":q:d:u:l:c:t:" opt; do done shift $(($OPTIND - 1)) -# Setup mq environment to accept mqsc command. -echo -e "\033[1;33mINFO: Setup mq environment to accept mqsc command\033[0m" -. $MQ_BIN_PATH/setmqenv -s +if [[ -z "$QMGR_NAME" || -z "$MQ_BIN_PATH" ]]; then + echo -e "\033[1;31mERROR: These arguments are required, but seems they are not set correctly\033[0m" + echo "QMGR_NAME: $QMGR_NAME" + echo "MQ_BIN_PATH: $MQ_BIN_PATH" + printUsage + exit 1 +fi # Call functions printUsage From b26c8db0418fed6d61614ae4723e835fd8ed22f1 Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Mon, 13 May 2024 10:16:13 +0800 Subject: [PATCH 14/24] add supported OS --- ace-setup-mq/readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index 83831e8..b254166 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -1,3 +1,5 @@ +# Supported OS +Linux (no test on zLinux) and AIX. # Instructions for setup-channel.sh ## Descriptions The script `setup-channel.sh` is used to create resources and set authority properly in QMGR for ACE sensor. From 454e72b9d9f41f2c28a5ad5475e60105e3e59b27 Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Mon, 13 May 2024 12:00:44 +0800 Subject: [PATCH 15/24] update the tested os --- ace-setup-mq/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index b254166..b583d84 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -1,5 +1,5 @@ # Supported OS -Linux (no test on zLinux) and AIX. +Tested on Ubuntu 20.04, RHEL9.4, AIX 7.2. # Instructions for setup-channel.sh ## Descriptions The script `setup-channel.sh` is used to create resources and set authority properly in QMGR for ACE sensor. From c94a8cbbf609ad121e55ffb7650f6b818220874b Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Mon, 13 May 2024 21:29:41 +0800 Subject: [PATCH 16/24] update description --- ace-setup-mq/prep-mq.sh | 22 +++++++++++++++++++++- ace-setup-mq/readme.md | 6 ++++-- ace-setup-mq/revert-mq.sh | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/ace-setup-mq/prep-mq.sh b/ace-setup-mq/prep-mq.sh index 927e038..d9af0b7 100644 --- a/ace-setup-mq/prep-mq.sh +++ b/ace-setup-mq/prep-mq.sh @@ -72,6 +72,9 @@ getListenerPort(){ echo -e "\033[1;33mWARNING: Port $port is not open or not accepting connections.\033[0m" fi done <<< "$listener_ports" + fi + if [ -n "$AVAILABLE_PORTS" ]; then + echo -e "\033[1;32mINFO: Found available ports: $AVAILABLE_PORTS\033[0m" else echo "Create a listener as there is no listener port found" echo "DEFINE LISTENER($LISTENER_NAME) TRPTYPE(TCP) PORT($LISTENER_PORT)" | runmqsc "$QMGR_NAME" @@ -89,9 +92,21 @@ getListenerPort(){ checkPort() { local port="$1" os_type=$(uname -s) + if [ -z "$port" ] || [ "$port" -eq 0 ]; then + echo -e "\033[1;31mERROR: Invalid port number: $port\033[0m" + return 1 + fi if [[ "$os_type" == "Linux" ]]; then + if ! command -v nc >/dev/null 2>&1; then + echo -e "\033[1;31mERROR: nc command not found: $port\033[0m" + return 1 + fi nc -zv localhost "$port" >/dev/null 2>&1 else + if ! command -v telnet >/dev/null 2>&1; then + echo -e "\033[1;31mERROR: telnet command not found: $port\033[0m" + return 1 + fi telnet localhost "$port" >/dev/null 2>&1 fi } @@ -126,7 +141,7 @@ prepChannelAndTopic(){ TOPIC_NAME=$(echo "$EXISTING_TOPIC" | sed -n '/TOPIC(\*/d; s/^.*TOPIC(\([^)]*\)).*$/\1/p') fi # Set authrec for the topic - echo "SET AUTHREC profile($TOPIC_NAME) objtype(topic) PRINCIPAL('$AUTH_USER') AUTHADD(ALL)" + echo "$MQSC_SET_AUTH_4_TOPIC" | runmqsc "$QMGR_NAME" echo "Set authrec for the topic $TOPIC_NAME" # Verify the authrec exists EXISTING_AUTHREC=$(echo "DIS AUTHREC PROFILE($TOPIC_NAME) OBJTYPE(TOPIC)" | runmqsc "$QMGR_NAME") @@ -203,6 +218,11 @@ SET AUTHREC profile($CHANNEL_NAME) objtype(channel) PRINCIPAL('$AUTH_USER') AUTH REFRESH SECURITY EOF +read -r -d '' MQSC_SET_AUTH_4_TOPIC << EOF +SET AUTHREC profile($TOPIC_NAME) objtype(topic) PRINCIPAL('$AUTH_USER') AUTHADD(ALL) +REFRESH SECURITY +EOF + printUsage preCheck setQmgrAuth diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index b583d84..e7cd6a8 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -1,6 +1,8 @@ +# Declaration +The scripts are used to help user to prepare the MQ objects for ace monitoring. Users can modify these scripts on demand for different environments. As a assistant tool, we will not provide offical support to these scripts. # Supported OS Tested on Ubuntu 20.04, RHEL9.4, AIX 7.2. -# Instructions for setup-channel.sh +# Instructions for prep-mq.sh ## Descriptions The script `setup-channel.sh` is used to create resources and set authority properly in QMGR for ACE sensor. * The script must be run with a user who belongs to mqm group and run on the machine which hosts the queue manager. @@ -12,7 +14,7 @@ The script `setup-channel.sh` is used to create resources and set authority prop ```sh ./prep-mq.sh -q -d -u ``` -# Instructions for remove-resources.sh +# Instructions for revert-mq.sh ## Descriptions The script `revert-mq.sh` is used to revert the authority granted with script `prep-revert.sh` and delete the objects created in QMGR for ACE sensor. * The script must be run with a user who belongs to mqm group and run on the machine which hosts the queue manager. diff --git a/ace-setup-mq/revert-mq.sh b/ace-setup-mq/revert-mq.sh index 96cb4f8..3cb29b2 100644 --- a/ace-setup-mq/revert-mq.sh +++ b/ace-setup-mq/revert-mq.sh @@ -6,7 +6,7 @@ printUsage() { echo "2. Remove the qmgr authority(connect+inq) for the specified user" echo "3. Delete the specified listener/channel/topic" echo -e "\033[1;33m Usage: $0 -q -d [-u AUTH_USER] [-l LISTENER_NAME] [-c CHANNEL_NAME] [-t TOPIC_NAME]\033[0m" - echo -e "\033[1;33m Example: $0 -q QM1 -d /opt/mqm/bin -u root -l LS2 -c INSTANA.ACE.SVRCONN -t INSTANA.ACE.BROKER.TOPIC\033[0m" + echo -e "\033[1;33m Example: $0 -q QM1 -d /opt/mqm/bin -u root -l INSTANA.ACE.LST -c INSTANA.ACE.SVRCONN -t INSTANA.ACE.BROKER.TOPIC\033[0m" } # 1. Check the current user has authority to execute MQSC commands From 5acd3c34825dca98ec11fc5d7d28efbba621e83a Mon Sep 17 00:00:00 2001 From: zhaohouf <35989725+zhaohouf@users.noreply.github.com> Date: Tue, 14 May 2024 14:37:36 +0800 Subject: [PATCH 17/24] Update ace-setup-mq/readme.md Co-authored-by: Savitha-Aneesh <168416196+Savitha-Aneesh@users.noreply.github.com> --- ace-setup-mq/readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index e7cd6a8..5e8329e 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -1,5 +1,6 @@ # Declaration -The scripts are used to help user to prepare the MQ objects for ace monitoring. Users can modify these scripts on demand for different environments. As a assistant tool, we will not provide offical support to these scripts. +The following scripts help you to prepare the IBM MQ objects for ACE monitoring. You can modify these scripts on demand for different environments. As an assistant tool, no official support to these scripts are provided. + # Supported OS Tested on Ubuntu 20.04, RHEL9.4, AIX 7.2. # Instructions for prep-mq.sh From c56cbf5ba03d299e5ccc4c7952a7dd755269fb59 Mon Sep 17 00:00:00 2001 From: zhaohouf <35989725+zhaohouf@users.noreply.github.com> Date: Tue, 14 May 2024 14:39:22 +0800 Subject: [PATCH 18/24] Apply suggestions from code review Co-authored-by: Savitha-Aneesh <168416196+Savitha-Aneesh@users.noreply.github.com> --- ace-setup-mq/readme.md | 49 +++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index 5e8329e..3a7f02a 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -1,29 +1,48 @@ # Declaration + The following scripts help you to prepare the IBM MQ objects for ACE monitoring. You can modify these scripts on demand for different environments. As an assistant tool, no official support to these scripts are provided. # Supported OS -Tested on Ubuntu 20.04, RHEL9.4, AIX 7.2. -# Instructions for prep-mq.sh -## Descriptions -The script `setup-channel.sh` is used to create resources and set authority properly in QMGR for ACE sensor. -* The script must be run with a user who belongs to mqm group and run on the machine which hosts the queue manager. -* The AUTH_USER used in the script is the user that you want to grant authority and it doesn't need to be a privileged user. + +- Ubuntu 20.04 +- RHEL9.4 +- AIX 7.2 +# Instructions for running the `prep-mq.sh` script +## Descriptions + +The script `setup-channel.sh` creates resources and sets authority correctly in QMGR for the ACE sensor. +* Run the script with a user who belongs to `mqm` group and on the machine that hosts the queue manager. +* `AUTH_USER` in the script is the user that you want to grant authority. The user needn't be a privileged user. + ## Usage -1. Download the script `prep-mq.sh` -2. Set it executable `chmod +x prep-mq.sh` -3. Go to the directory and execute the script + +To run the `prep-mq.sh` script, complete the following steps: +1. Download the `prep-mq.sh` script. +2. Make the script executable: + ``` + chmod +x prep-mq.sh + ``` + {: codeblock} +3. Go to the directory, and run the script. + ```sh ./prep-mq.sh -q -d -u ``` -# Instructions for revert-mq.sh +# Instructions for running the revert-mq.sh script + ## Descriptions -The script `revert-mq.sh` is used to revert the authority granted with script `prep-revert.sh` and delete the objects created in QMGR for ACE sensor. -* The script must be run with a user who belongs to mqm group and run on the machine which hosts the queue manager. -* The AUTH_USER used in the script is the user that you used in `prep-mq.sh`. + +The `revert-mq.sh` script reverts the authority granted with the `prep-revert.sh` script and deletes the objects created in QMGR for the ACE sensor. +* Run the script with a user who belongs to `mqm `group and on the machine which hosts the queue manager. +* `AUTH_USER` in the script is the user that you used in the `prep-mq.sh` script. + ## Usage -1. Download the script `revert-mq.sh` + +To run the `revert-mq.sh` script, complete the following steps: + +1. Download the `revert-mq.sh` script. 2. Set it executable `chmod +x revert-mq.sh` -3. Go to the directory and execute the script +3. Go to the directory, and execute the script. ```sh ./revert-mq.sh -q -d [-u AUTH_USER] [-l LISTENER_NAME] [-c CHANNEL_NAME] [-t TOPIC_NAME] ``` From c4188cfd1d66cd1903db8ecdd444756bab2aa79c Mon Sep 17 00:00:00 2001 From: zhaohouf <35989725+zhaohouf@users.noreply.github.com> Date: Tue, 14 May 2024 14:40:21 +0800 Subject: [PATCH 19/24] Apply suggestions from code review Co-authored-by: Savitha-Aneesh <168416196+Savitha-Aneesh@users.noreply.github.com> --- ace-setup-mq/readme.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index 3a7f02a..07695d4 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -41,7 +41,11 @@ The `revert-mq.sh` script reverts the authority granted with the `prep-revert.sh To run the `revert-mq.sh` script, complete the following steps: 1. Download the `revert-mq.sh` script. -2. Set it executable `chmod +x revert-mq.sh` +2. Make the script executable: + ``` + chmod +x revert-mq.sh + ``` + {: codeblock} 3. Go to the directory, and execute the script. ```sh ./revert-mq.sh -q -d [-u AUTH_USER] [-l LISTENER_NAME] [-c CHANNEL_NAME] [-t TOPIC_NAME] From 03f4d911676b1629474afee4faadc6e483797fa8 Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Tue, 14 May 2024 14:46:32 +0800 Subject: [PATCH 20/24] refine codeblock --- ace-setup-mq/readme.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index 07695d4..e6e2540 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -19,15 +19,16 @@ The script `setup-channel.sh` creates resources and sets authority correctly in To run the `prep-mq.sh` script, complete the following steps: 1. Download the `prep-mq.sh` script. 2. Make the script executable: - ``` - chmod +x prep-mq.sh - ``` - {: codeblock} +``` + chmod +x prep-mq.sh +``` +{: codeblock} 3. Go to the directory, and run the script. ```sh ./prep-mq.sh -q -d -u ``` + {: codeblock} # Instructions for running the revert-mq.sh script ## Descriptions @@ -42,14 +43,15 @@ To run the `revert-mq.sh` script, complete the following steps: 1. Download the `revert-mq.sh` script. 2. Make the script executable: - ``` +``` chmod +x revert-mq.sh - ``` - {: codeblock} +``` +{: codeblock} 3. Go to the directory, and execute the script. ```sh ./revert-mq.sh -q -d [-u AUTH_USER] [-l LISTENER_NAME] [-c CHANNEL_NAME] [-t TOPIC_NAME] ``` +{: codeblock} From 0d5006f7a3355ec8df0dc0dbbc6954350bf64bd2 Mon Sep 17 00:00:00 2001 From: HOU FANG ZHAO Date: Tue, 14 May 2024 14:52:44 +0800 Subject: [PATCH 21/24] align the code blocks --- ace-setup-mq/readme.md | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index e6e2540..5dc92ee 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -19,16 +19,15 @@ The script `setup-channel.sh` creates resources and sets authority correctly in To run the `prep-mq.sh` script, complete the following steps: 1. Download the `prep-mq.sh` script. 2. Make the script executable: -``` + ``` chmod +x prep-mq.sh -``` -{: codeblock} + ``` + {: codeblock} 3. Go to the directory, and run the script. - -```sh + ```sh ./prep-mq.sh -q -d -u -``` - {: codeblock} + ``` + {: codeblock} # Instructions for running the revert-mq.sh script ## Descriptions @@ -43,15 +42,15 @@ To run the `revert-mq.sh` script, complete the following steps: 1. Download the `revert-mq.sh` script. 2. Make the script executable: -``` + ``` chmod +x revert-mq.sh -``` -{: codeblock} + ``` + {: codeblock} 3. Go to the directory, and execute the script. -```sh + ```sh ./revert-mq.sh -q -d [-u AUTH_USER] [-l LISTENER_NAME] [-c CHANNEL_NAME] [-t TOPIC_NAME] -``` -{: codeblock} + ``` + {: codeblock} From ecab81b7ebc48b020b3955f0dd94b747b549047e Mon Sep 17 00:00:00 2001 From: zhaohouf <35989725+zhaohouf@users.noreply.github.com> Date: Tue, 14 May 2024 14:56:43 +0800 Subject: [PATCH 22/24] Update readme.md --- ace-setup-mq/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index 5dc92ee..99848b4 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -5,7 +5,7 @@ The following scripts help you to prepare the IBM MQ objects for ACE monitoring. # Supported OS - Ubuntu 20.04 -- RHEL9.4 +- RHEL 9.4 - AIX 7.2 # Instructions for running the `prep-mq.sh` script ## Descriptions From 4956082195c0b9ec18a506ba8a2f052dccc11673 Mon Sep 17 00:00:00 2001 From: zhaohouf <35989725+zhaohouf@users.noreply.github.com> Date: Tue, 14 May 2024 14:57:43 +0800 Subject: [PATCH 23/24] Update readme.md --- ace-setup-mq/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index 99848b4..f5918df 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -10,7 +10,7 @@ The following scripts help you to prepare the IBM MQ objects for ACE monitoring. # Instructions for running the `prep-mq.sh` script ## Descriptions -The script `setup-channel.sh` creates resources and sets authority correctly in QMGR for the ACE sensor. +The script `prep-mq.sh` creates resources and sets authority correctly in QMGR for the ACE sensor. * Run the script with a user who belongs to `mqm` group and on the machine that hosts the queue manager. * `AUTH_USER` in the script is the user that you want to grant authority. The user needn't be a privileged user. From 4b46a65ead3dafd38ae65939d8a04f6a33c211af Mon Sep 17 00:00:00 2001 From: zhaohouf <35989725+zhaohouf@users.noreply.github.com> Date: Tue, 14 May 2024 15:34:43 +0800 Subject: [PATCH 24/24] Apply suggestions from code review Co-authored-by: Savitha-Aneesh <168416196+Savitha-Aneesh@users.noreply.github.com> --- ace-setup-mq/readme.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/ace-setup-mq/readme.md b/ace-setup-mq/readme.md index f5918df..d7b4ebd 100644 --- a/ace-setup-mq/readme.md +++ b/ace-setup-mq/readme.md @@ -7,8 +7,10 @@ The following scripts help you to prepare the IBM MQ objects for ACE monitoring. - Ubuntu 20.04 - RHEL 9.4 - AIX 7.2 -# Instructions for running the `prep-mq.sh` script -## Descriptions + +# `prep-mq.sh` script + +## Description The script `prep-mq.sh` creates resources and sets authority correctly in QMGR for the ACE sensor. * Run the script with a user who belongs to `mqm` group and on the machine that hosts the queue manager. @@ -17,20 +19,22 @@ The script `prep-mq.sh` creates resources and sets authority correctly in QMGR f ## Usage To run the `prep-mq.sh` script, complete the following steps: + 1. Download the `prep-mq.sh` script. 2. Make the script executable: ``` chmod +x prep-mq.sh ``` {: codeblock} -3. Go to the directory, and run the script. +3. Go to the directory, and run the script: ```sh ./prep-mq.sh -q -d -u ``` {: codeblock} -# Instructions for running the revert-mq.sh script + +# `revert-mq.sh` script -## Descriptions +## Description The `revert-mq.sh` script reverts the authority granted with the `prep-revert.sh` script and deletes the objects created in QMGR for the ACE sensor. * Run the script with a user who belongs to `mqm `group and on the machine which hosts the queue manager. @@ -46,12 +50,9 @@ To run the `revert-mq.sh` script, complete the following steps: chmod +x revert-mq.sh ``` {: codeblock} -3. Go to the directory, and execute the script. +3. Go to the directory, and run the script: ```sh ./revert-mq.sh -q -d [-u AUTH_USER] [-l LISTENER_NAME] [-c CHANNEL_NAME] [-t TOPIC_NAME] ``` {: codeblock} - - -