One of the great things about Log Insight is that you do not need a CLI to use it. If you do decide to use the CLI you may find yourself wishing to execute commands on every node in a Log Insight cluster. While this can be done with a simple for loop, I wrote a quick wrapper script to make it even easier.
WARNING: This script is not supported by VMware or me. Use at your own risk!
From any node within a Log Insight cluster you can determine all other nodes in the cluster. This means with a simple wrapper script you can point to a single node like a master, worker, or VIP and based on configuration data, issue a command to all nodes within the cluster. Note that this script uses SSH so you will want to have SSH keys configured on the nodes. To use the script I created, simply run li_rexec:
$ li_rexec USAGE: li_rexec[-v]
As you can see, the script requires two inputs being the Log Insight instance (e.g. master, worker, VIP, standalone) and the command(s) you wish to run. By default the output is not very verbose:
$ li_rexec li.sflanders.net date Tue Dec 30 20:34:37 UTC 2014 Tue Dec 30 20:34:37 UTC 2014 Tue Dec 30 20:34:37 UTC 2014
To make the output more verbose, use the -v flag at the end of the command:
$ li_rexec li.sflanders.net date -v =================================== Host: li01.sflanders.net Command(s): date =================================== Tue Dec 30 20:34:37 UTC 2014 =================================== Host: li02.sflanders.net Command(s): date =================================== Tue Dec 30 20:34:37 UTC 2014 =================================== Host: li03.sflanders.net Command(s): date =================================== Tue Dec 30 20:34:37 UTC 2014
That’s it! So without further adieu, here is the script:
#!/usr/bin/env sh # # li_rexec # Steve Flanders (stevesflandersnet) # # Description - Wrapper to run commands on every node in a Log Insight instance # # ***PLEASE DO NOT REMOVE THIS HEADER AND PLEASE CREDIT THE AUTHOR*** # ### VALIDATIONS if [ -z "$2" -o ! -z "$4" ]; then echo "USAGE: $0[-v]"; exit; fi ### VARIABLES LOGINSIGHT="$1" SSHCOMMAND="$2" SSHUSER="root" ### DO NOT CHANGE ANYTHING BELOW HERE!!! # Assume a cluster and get the list of nodes NODELIST=$(ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $SSHUSER@$LOGINSIGHT "grep \"daemon host\" \$(ls /storage/core/loginsight/config/loginsight-config.xml* | sort -k1.55n | tail -n 1) | awk '{ split(\$0,a,\"\\\"\"); print a[2];}'") NODES=() if [ ! -z "$NODELIST" ]; then for N in $NODELIST; do NODES+=($N); done; fi # If unable to get a list of nodes then assume standalone if [ -z "$NODES" ]; then NODES=($loginsight); fi for NODE in ${NODES[@]}; do if [ "$3" == "-v" ]; then echo " =================================== Host: $NODE Command(s): $SSHCOMMAND ==================================="; fi ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $SSHUSER@$NODE $SSHCOMMAND done if [ "$3" == "-v" ]; then echo; fi
© 2015, Steve Flanders. All rights reserved.