Created 03-28-2018 08:37 PM
Ambari alerts only check process and port health, yes? There are no smoke tests being ran by Ambari unless a manual service check is ran?
I was able to write a bash script to detect a timeout from a simple COUNT query, but later found out that Ambari only accepts Python scripts as alerts.
What are my options if I would like to periodically run a Hive query and do a validity check against a Hive table?
This script works on it's own in bash, but I need help calling it / re-doing it using Python if I want to use Ambari alerts
#!/usr/bin/env bash set -u TIMEOUT=1m BEELINE=/usr/hdp/current/hive-client/bin/beeline RUNAS=hive TEZ_QUEUE=infrastructure OUTPUT_FILE=/tmp/hivecanary.out CONNECT_URI=jdbc:hive2://localhost:10000?tez.queue.name=infrastructure if [[ ! -x $BEELINE ]]; then echo CRITICAL exit 2 fi if [[ -f $OUTPUT_FILE ]]; then rm -f "$OUTPUT_FILE" fi echo "$BEELINE --showHeader=false --outputformat=tsv2 -n hive -u 'jdbc:hive2://localhost:10000?tez.queue.name=infrastructure' -e 'SELECT COUNT(*) FROM default.customers'" | bash & a=0 sleep 10 while true;do a=$(($a+1)) PID=$(ps aux | grep beeline | grep -v grep | grep 'SELECT COUNT' | awk '{ print $2 }') if [ -z "$PID" ]; then echo OK exit 0 else if [ "$a" -gt 60 ]; then echo CRITICAL exit 1 fi fi sleep 1 done
Created 03-28-2018 08:46 PM
There is a great example here
It allows you to execute most shell commands as native python functions.
Example:
import sh sh.cd('/path/to/Development') print(sh.pwd()) # => /path/to/Development
Created 03-28-2018 09:09 PM
It depends on which service and component. Some only do simple checks like port and PID status.
Hive Server actually runs beeline commands
Hive Metastore runs a show databases command
Created 03-30-2018 03:06 AM
@Geoffrey Shelton Okot - That requires installing sh module into the Ambari python installation, which I do not want to maintain. If I could do that, then I would use a Python Hive driver.