def send_email(self, msg, subject): """Send email""" mesage = ('On ' + time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime( time.time())) + ' ' + str(msg)) try: from plugins.email_adj import email email(subject, mesage) # send email without attachments self.add_status('Email was sent: ' + mesage) except Exception as err: self.add_status('Email was not sent! ' + str(err))
def run(self): time.sleep(randint(3, 10)) # Sleep some time to prevent printing before startup information print "Pressure plugin is active" send = False SUBJ = "Reporting from OSPy" # Subject in email self.add_status('Waiting...') while True: try: datapressure = get_pressure_options() # load data from file if datapressure['press'] != 'off': # if pressure plugin is enabled if (gv.sd['mas'] != 0) and not (gv.sd['mm']): # if is use master station and not manual control if gv.srvals[gv.sd['mas']] != 0: # if master station is ON test = get_check_pressure() if not test: # if sensor is active self._sleep(int(datapressure['time'])) # wait to activated pressure sensor test = get_check_pressure() if not test: # if sensor is current active stop_stations() self.add_status('Pressure sensor is not activated in time -> stops all stations and sends email.') if datapressure['sendeml'] != 'off': # if enabled send email send = True else: # if not used master station self.status = '' self.add_status('Not used master station.') if send: TEXT = ('On ' + time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime( time.time())) + ' System detected error: pressure sensor.') try: from plugins.email_adj import email email(SUBJ, TEXT) # send email without attachments self.add_status('Email was sent: ' + TEXT) send = False except Exception as err: self.add_status('Email was not sent! ' + str(err)) self._sleep(1) except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() err_string = ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback)) self.add_status('Pressure plugin encountered error: ' + err_string) self._sleep(60)
def run(self): time.sleep(randint(3, 10)) # Sleep some time to prevent printing before startup information print "Pressure plugin is active" send = False SUBJ = "Reporting from ospi" # Subject in email self.add_status('Waiting...') while True: try: datapressure = get_pressure_options() # load data from file if datapressure['press'] != 'off': # if pressure plugin is enabled if (gv.sd['mas'] != 0) and not (gv.sd['mm']): # if is use master station and not manual control if gv.srvals[gv.sd['mas']] != 0: # if master station is ON if GPIO.input(pin_pressure) == 0: # if sensor is open self._sleep(int(datapressure['time'])) # wait to activated pressure sensor if GPIO.input(pin_pressure) == 0: # if sensor is current open stop_stations() self.add_status('Pressure sensor is not activated in time -> stops all stations and sends email.') if datapressure['sendeml'] != 'off': # if enabled send email send = True else: # if not used master station self.status = '' self.add_status('Not used master station.') if send: TEXT = ('On ' + time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime( time.time())) + ' System detected error: pressure sensor.') try: from plugins.email_adj import email email(SUBJ, TEXT) # send email without attachments self.add_status('Email was sent: ' + TEXT) send = False except Exception as err: self.add_status('Email was not sent! ' + str(err)) self._sleep(1) except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() err_string = ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback)) self.add_status('Pressure plugin encountered error: ' + err_string) self._sleep(60)