Exemplo n.º 1
0
def send_email(msg):
    """Send email"""
    message = datetime_string() + ': ' + msg
    try:
        from plugins.email_notifications import email
        email(message)
        log.info(NAME, _('Email was sent') + ': ' + message)
    except Exception:
        log.info(NAME, _('Email was not sent') + '! ' + traceback.format_exc())
Exemplo n.º 2
0
def send_email(msg):
    """Send email"""
    message = datetime_string() + ': ' + msg
    try:
        from plugins.email_notifications import email

        Subject = plugin_options['eml_subject']

        email(message, subject=Subject) # send email

        if not options.run_logEM:
           log.info(NAME, _('Email logging is disabled in options...'))
        else:        
           logEM.save_email_log(Subject, message, _('Sent'))

        log.info(NAME, _('Email was sent') + ': ' + message)

    except Exception:
        if not options.run_logEM:
           log.info(NAME, _('Email logging is disabled in options...'))
        else:
           logEM.save_email_log(Subject, message, _('Sent'))

        log.info(NAME, _('Email was not sent') + '! ' + traceback.format_exc())
Exemplo n.º 3
0
def send_email(msg, msglog):
    message = datetime_string() + ': ' + msg
    Subject = plugin_options['emlsubject']
    try:
        email = None
        if plugin_options['eplug']==0: # email_notifications
            from plugins.email_notifications import email
        if plugin_options['eplug']==1: # email_notifications SSL
            from plugins.email_notifications_ssl import email
        if email is not None:        
            email(message, subject=Subject)
            if not options.run_logEM:
                log.info(NAME, _(u'Email logging is disabled in options...'))
            else:
                logEM.save_email_log(Subject, msglog, _('Sent'))
            log.info(NAME, _(u'Email was sent') + ': ' + msglog)

    except Exception:
        if not options.run_logEM:
           log.info(NAME, _(u'Email logging is disabled in options...'))
        else:
           logEM.save_email_log(Subject, msglog, _('Email was not sent'))

        log.info(NAME, _(u'Email was not sent') + '! ' + traceback.format_exc())
Exemplo n.º 4
0
    def run(self):
        try:
            import smbus  # for PCF 8583

            self.bus = smbus.SMBus(1 if get_rpi_revision() >= 2 else 0)
        except ImportError:
            log.warning(NAME, _('Could not import smbus.'))

        if self.bus is not None:
            self.pcf = set_counter(self.bus)  # set pcf8583 as counter

        log.clear(NAME)
        send = False  # send email
        disable_text = True
        val = 0.0
        maxval = 0.0
        timer_reset = 0

        while not self._stop.is_set():
            try:
                if self.bus is not None and wind_options[
                        'use_wind_monitor']:  # if wind plugin is enabled
                    disable_text = True

                    puls = counter(
                        self.bus) / 10.0  # counter value is value/10sec

                    val = puls / (wind_options['pulses'] * 1.0)
                    val = val * wind_options['metperrot']

                    if val > maxval:
                        maxval = val

                    if timer_reset >= 86400:  # 1 day
                        timer_reset = 0
                        maxval = 0.0

                    self.status['meter'] = round(val, 2)
                    self.status['kmeter'] = round(val * 3.6, 2)

                    log.clear(NAME)
                    log.info(NAME, _('Please wait 10 sec...'))
                    log.info(
                        NAME,
                        _('Speed') + ' ' + str(round(val, 2)) + ' ' +
                        _('m/sec'))
                    log.info(
                        NAME,
                        _('Speed Peak 24 hour') + ' ' + str(round(maxval, 2)) +
                        ' ' + _('m/sec'))
                    log.info(
                        NAME,
                        _('Pulses') + ' ' + str(puls) + ' ' + _('pulses/sec'))

                    if val >= 42:
                        log.error(NAME, _('Wind speed > 150 km/h (42 m/sec)'))

                    if get_station_is_on():  # if station is on
                        if val >= int(
                                wind_options['maxspeed']
                        ):  # if wind speed is > options max speed
                            log.clear(NAME)
                            log.finish_run(None)  # save log
                            stations.clear()  # set all station to off
                            log.clear(NAME)
                            log.info(
                                NAME,
                                _('Stops all stations and sends email if enabled sends email.'
                                  ))
                            if wind_options[
                                    'sendeml']:  # if enabled send email
                                send = True

                else:
                    # text on the web if plugin is disabled
                    if disable_text:
                        log.clear(NAME)
                        log.info(NAME,
                                 _('Wind speed monitor plug-in is disabled.'))
                        disable_text = False

                if send:
                    TEXT = (datetime_string() + ': ' + _(
                        'System detected error: wind speed monitor. All stations set to OFF. Wind is'
                    ) + ': ' + str(round(val * 3.6, 2)) + ' km/h.')
                    try:
                        from plugins.email_notifications import email
                        email(TEXT)  # send email without attachments
                        log.info(NAME, _('Email was sent') + ': ' + TEXT)
                        send = False
                    except Exception:
                        log.clear(NAME)
                        log.error(
                            NAME,
                            _('Email was not sent') + '! ' +
                            traceback.format_exc())

                timer_reset += 10  # measure is 10 sec long

            except Exception:
                log.clear(NAME)
                log.error(
                    NAME,
                    _('Wind Speed monitor plug-in') + ':\n' +
                    traceback.format_exc())
                self._sleep(60)
                self.pcf = set_counter(self.bus)  # set pcf8583 as counter
Exemplo n.º 5
0
    def run(self):
        send = False

        once_text = True
        two_text = True
        three_text = True
        four_text = True
        five_text = True

        last_time = int(time.time())
        actual_time = int(time.time())

        while not self._stop.is_set():
            try:
                if pressure_options[
                        'use_press_monitor']:  # if pressure plugin is enabled
                    four_text = True
                    if get_master_is_on():  # if master station is on
                        three_text = True
                        if once_text:  # text on the web if master is on
                            log.clear(NAME)
                            log.info(NAME, _('Master station is ON.'))
                            once_text = False
                        if get_check_pressure():  # if pressure sensor is on
                            actual_time = int(time.time())
                            count_val = int(pressure_options['time'])
                            log.clear(NAME)
                            log.info(
                                NAME,
                                _('Time to test pressure sensor') + ': ' +
                                str(count_val - (actual_time - last_time)) +
                                ' ' + _('sec'))
                            if actual_time - last_time > int(
                                    pressure_options['time']
                            ):  # wait for activated pressure sensor (time delay)
                                last_time = actual_time
                                if get_check_pressure(
                                ):  # if pressure sensor is actual on
                                    #  options.scheduler_enabled = False                  # set scheduler to off
                                    log.finish_run(None)  # save log
                                    stations.clear()  # set all station to off
                                    log.clear(NAME)
                                    log.info(
                                        NAME,
                                        _('Pressure sensor is not activated in time -> stops all stations and send email.'
                                          ))
                                    if pressure_options[
                                            'sendeml']:  # if enabled send email
                                        send = True

                        if not get_check_pressure():
                            last_time = int(time.time())
                            if five_text:
                                once_text = True
                                five_text = False

                    if not get_master_is_on(
                    ):  # text on the web if master is off
                        if stations.master is not None:
                            if two_text:
                                log.clear(NAME)
                                log.info(NAME, _('Master station is OFF.'))
                                two_text = False
                                five_text = True
                            last_time = int(time.time())

                else:
                    once_text = True
                    two_text = True
                    if four_text:  # text on the web if plugin is disabled
                        log.clear(NAME)
                        log.info(NAME,
                                 _('Pressure monitor plug-in is disabled.'))
                        four_text = False

                if stations.master is None:  # text on the web if master station is none
                    if three_text:
                        log.clear(NAME)
                        log.info(NAME, _('Not used master station.'))
                        three_text = False

                if send:
                    TEXT = (datetime_string() + ': ' +
                            _('System detected error: pressure sensor.'))
                    try:
                        from plugins.email_notifications import email
                        email(TEXT)  # send email without attachments
                        log.info(NAME, _('Email was sent') + ': ' + TEXT)
                        send = False
                    except Exception:
                        log.error(
                            NAME,
                            _('Email was not sent') + '! ' +
                            traceback.format_exc())

                self._sleep(1)

            except Exception:
                log.error(
                    NAME,
                    _('Pressure monitor plug-in') + ':\n' +
                    traceback.format_exc())
                self._sleep(60)