def hk_ok(verbosity=1, fulltest=False): ''' check that housekeeping is okay ''' retval = {} ok = True message = '' retval['power'] = check_power(verbosity=verbosity) retval['network'] = check_network(verbosity=verbosity, fulltest=fulltest) retval['mounts'] = check_mounts(verbosity=verbosity) retval['diskspace'] = check_diskspace(verbosity=verbosity) retval['calsource'] = check_calsource(verbosity=verbosity) retval['servers'] = check_servers(verbosity=verbosity) retval['temps'] = check_temps(verbosity=verbosity) retval['compressor'] = check_compressors(verbosity=verbosity) message_list = [] for key in retval.keys(): if 'ok' not in retval[key].keys(): if verbosity > 0: print('missing ok key for %s' % key) continue if not retval[key]['ok']: ok = False if 'error_message' not in retval[key].keys(): message += '\n%s: no message' % key else: message += '\n%s:\n %s' % (key, retval[key]['error_message']) message_list.append('============= %s ================' % key) message_list.append(retval[key]['message']) if not ok: ttl = '\n*******************************' ttl += '\n* QUBIC Housekeeping problems *' message_list.append(ttl) message_list.append(message) if verbosity > 0: print(ttl) if verbosity > 0: print(message) errmsg = ttl + '\n' + message send_telegram(errmsg) retval['error_message'] = message retval['ok'] = ok full_message = '\n'.join(message_list) retval['full_message'] = full_message return retval
$Id: hk_ok.py $auth: Steve Torchinsky <*****@*****.**> $created: Mon 12 Oct 2020 09:37:44 CEST $license: GPLv3 or later, see https://www.gnu.org/licenses/gpl-3.0.txt This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. check if QUBIC housekeeping is running ''' import sys from qubichk.hk_verify import hk_ok from qubichk.send_telegram import send_telegram if __name__ == '__main__': verbosity = 1 fulltest = False for arg in sys.argv: if arg == '--silent': verbosity = 0 continue if arg == '--full': fulltest = True ret = hk_ok(verbosity=verbosity, fulltest=fulltest) if verbosity > 0: send_telegram(ret['full_message'])
$auth: Steve Torchinsky <*****@*****.**> $created: Sun 05 Dec 2021 19:28:38 CET $license: GPLv3 or later, see https://www.gnu.org/licenses/gpl-3.0.txt This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. test the Telegram alarm ''' from qubichk.send_telegram import send_telegram, get_alarm_recipients, get_TelegramAddresses known_users = get_TelegramAddresses() alarm_recipients = get_alarm_recipients() msg = "\n\nYou can now subscribe or unsubscribe yourself from the list of recipients for alarms" msg += " by using the commands 'subscribe' and 'unsubscribe'. You are currently subscribed." msg += "\n\nI will check the compressor status every minute, and the UPS status every minute." msg += " If there's a problem, I'll send you a telegram every minute until the problem is resolved," msg += " or until you unsubscribe from the list." msg += "\n\nBest regards from your friend," msg += "\nQUBIC" for chatid in alarm_recipients: if chatid in known_users.keys(): fullmsg = 'Hi %s!' % known_users[chatid] else: fullmsg = 'Hi!' fullmsg += '\n' + msg send_telegram(fullmsg, chatid=chatid) send_telegram(fullmsg, 'Steve')
redistribute it. There is NO WARRANTY, to the extent permitted by law. send a warning that we're on UPS ''' # following example at: http://docs.python.org/library/email-examples.html #import smtplib #from email.mime.text import MIMEText #import sys,os,time,subprocess from qubichk.ups import get_ups_info from qubichk.send_telegram import send_telegram # cmd = 'hostname' # proc = subprocess.Popen(cmd,stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) # out,err = proc.communicate() # hostname = out.decode().strip() # msg = MIMEText(txtmsg) # msg['Subject']='UPS alert from QUBIC' # msg['To']='Steve Torchinsky <*****@*****.**>' # msg['From']='%s <*****@*****.**>' % hostname # s = smtplib.SMTP('apcrelay.in2p3.fr') # s.sendmail(msg['From'], msg['To'], msg.as_string()) # s.quit() info = get_ups_info() # send by Telegram send_telegram(info['full message'])
#!/usr/bin/env python3 ''' $Id: ups_log.py $auth: Steve Torchinsky <*****@*****.**> $created: Mon 29 Nov 2021 17:36:29 CET $license: GPLv3 or later, see https://www.gnu.org/licenses/gpl-3.0.txt This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. output logging information from the UPS, save to the housekeeping directory ''' from qubichk.ups import get_ups_info from qubichk.send_telegram import send_telegram, get_alarm_recipients hk_dir = '/home/qubic/data/temperature/broadcast' h = open(hk_dir+'/ups_log.txt','a') info = get_ups_info() logline = info['log message']+'\n' h.write(logline) h.close() alarm_recipients = get_alarm_recipients() if info['alarm']: for chatid in alarm_recipients: send_telegram(info['full message'],chatid=chatid)
msg = [] status_msg = [] comm_error = False ok = True for compressor_num in [1,2]: logfile = '%s/compressor%i_log.txt' % (hk_dir,compressor_num) c.append(compressor(compressor_num)) info.append(c[-1].status()) h = open(logfile,'a') h.write(info[-1]['log_message']+'\n') h.close() status_msg.append(info[-1]['status_message']) msg.append(info[-1]['msg']) comm_error = comm_error or info[-1]['communication error'] ok = ok and info[-1]['status'] if not ok: error_msg = '\n'.join(msg) alarm_recipients = get_alarm_recipients() if not comm_error: for chatid in alarm_recipients: send_telegram(error_msg,chatid=chatid) else: fullmsg = 'The following message is only sent to Steve' fullmsg += '\n- - - - - -\n' + error_msg fullmsg += '\n- - - - - -\n' + '\n'.join(status_msg) send_telegram(fullmsg,'Steve')