Skip to content

Commit

Permalink
added auto discovery of databases
Browse files Browse the repository at this point in the history
reads listener status and tries to convert instance names to databases
using some conventions.
  • Loading branch information
ikzelf committed Feb 14, 2018
1 parent da6079a commit 3b7aac6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
41 changes: 41 additions & 0 deletions bin/zbx_discover_dbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
ME=${0##*/}
ME_FILE=`type $ME|sed "s/[()]//g"|awk '{print $NF}'`
ME_DIR=`dirname $ME_FILE`
list_listener()
{
SITE=$1
CLUSTER=`echo $2|sed 's/"//g'`
shift 2
NODES=$*
{
for node in $NODES
do
echo node $node >&2
echo "scp -p ${ME_FILE}_remote ${node}:/tmp/"
scp -p ${ME_FILE}_remote ${node}:/tmp/
< /dev/null ssh -tt $node /tmp/${ME}_remote
done
} |grep Instance|awk '{print $2}'|cut -f2 -d\"|
if [ -n "${CLUSTER}" ]
then
sed "s/[0-9]$//"
else
cat
fi |
sed "s/[+-]//"|sort|uniq|
if [ -n "${CLUSTER}" ]
then
sed "s/^/${SITE}_${CLUSTER}_/"
else
sed "s/^/${SITE}_/"
fi
}

cat $HOME/etc/$ME.cfg|while read group cluster nodes
do
echo nodes $nodes >&2
list_listener "$group" "$cluster" "$nodes"
done | awk 'BEGIN { printf ("{ \"data\":[\n"); comma=" " }
{ printf ("%s\"{#DB_NAME}\":\"%s\"\n", comma, $0); comma="," }
END {printf ("]}\n") }'
6 changes: 6 additions & 0 deletions bin/zbx_discover_dbs_remote
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tns=`ps -ef|grep tnslsnr|grep -v grep|awk '{print $8}'|sort|uniq|tail -1`
echo tns=$tns
dir=$(dirname $tns)
echo "dir=$dir"
export ORACLE_HOME=$(dirname $dir)
$ORACLE_HOME/bin/lsnrctl status
3 changes: 3 additions & 0 deletions etc/zbx_discover_dbs.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
customerA dm01 dm01db01.intra.customerA.nl dm01db02.intra.customerA.nl
customerA dm02 dm02db01.intra.customerA.nl dm02db02.intra.customerA.nl
customerA "" srv-ora-001.intra.customerA.nl

0 comments on commit 3b7aac6

Please sign in to comment.