Мой скрипт не прошел сравнение check.decode() == 'TRUE'
, результат /healthcheck/bin/captureFailed.sh
равен ИСТИНА , должен входить в if
и не попадать в else
, какие-либо предложения?
Скрипт python:
import requests
import json
from time import gmtime, strftime
import subprocess
from subprocess import Popen, PIPE, STDOUT
try:
p = Popen(['/bin/bash', '/healthcheck/bin/captureFailed.sh'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
check = p.communicate()[0]
print("[INFO] CHECK TEPS STATUS: {}".format(check.decode()))
if str(check.decode()) == 'TRUE':
print("[INFO] SENDING ALERT")
webhook_url = 'https://hooks.slack.com/services/channel-here'
response = requests.post(
webhook_url,
json={'text': '[ALERT] Baseline control has not been updated, there is a flaw in TEPS, check the logs. [{}]'
.format(strftime("%Y-%m-%d", gmtime()))},
headers={'Content-Type': 'application/json'}
)
if response.status_code != 200:
raise ValueError(
'Request to slack returned an error %s, the response is:%s'
% (response.status_code, response.text)
)
else:
print("[OK] SENT WITH SUCCESS")
else:
print("[OK] NO ERRORS, RUNNING SCRIPTS ...")
except Exception as e:
print('[FAILED] Caused by: {}'.format(e))
Оболочка скрипта:
cat /healthcheck/logs/exec.log | grep HTTP | while read line
do
echo "$line" | grep "ERROR" >/dev/null
if [ $? = 0 ]; then
echo "TRUE";
fi
done
Вывод:
[INFO] CHECK TEPS STATUS: TRUE
[OK] NO ERRORS, RUNNING SCRIPTS ...