def alert_sys_bluusite_offline(user, bluusite, timestamp, period=None): """ Sends notification about device offline """ site = bluusite if (user_alerts_allowed(user, site) or dealer_alerts_allowed(user, site)): site_name = site.name timestamp = timestamp body = render_to_string('alerts/notifications/sys_bluusite_offline.html', { 'user': user, 'site_name': site_name, 'timestamp': timestamp, 'period': period }) subject = render_to_string('alerts/notifications/notification_title.html', dict(site_name=site_name, alert_name=_('site offline'))) if user.email: logger.info('Sys bluusite offline alert' ' sent to {0} for device {1}'.format( user.email, bluusite.name)) msg = BluuMessage(subject, body, user.email) msg.send() if user.cell_text_email: logger.info('Sys bluusite offline text alert sent to {0} for' ' device {1}'.format( user.cell_text_email, bluusite.name)) msg = BluuMessage(subject, body, user.cell_text_email) msg.send()
def alert_sys_tamper(user, device, timestamp): """ Sends notification about tamper """ site = device.bluusite if (user_alerts_allowed(user, site) or dealer_alerts_allowed(user, site)): device_name = device.name room = device.room site_name = site.name timestamp = timestamp body = render_to_string('alerts/notifications/sys_tamper.html', { 'user': user, 'device_name': device_name, 'room': room, 'site_name': site_name, 'timestamp': timestamp, }) subject = render_to_string('alerts/notifications/notification_title.html', dict(site_name=site_name, alert_name=_('tamper'))) if user.email: logger.info('Sys tamper alert sent to {0} for device {1}'.format(user.email, device_name)) msg = BluuMessage(subject, body, user.email) msg.send() if user.cell_text_email: logger.info('Sys tamper text alert sent to {0} for device {1}'.format( user.cell_text_email, device_name)) msg = BluuMessage(subject, body, user.cell_text_email) msg.send()
def alert_open(uad, status): user = uad.user site = uad.device.bluusite # check here because this alert isn't called via alert runner if (user_alerts_allowed(user, site) or dealer_alerts_allowed(user, site)): device_name = uad.device.name room = uad.device.room.name site_name = uad.device.bluusite.name timestamp = status.timestamp body = render_to_string('alerts/notifications/open.html', { 'user': user, 'device_name': device_name, 'room': room, 'site_name': site_name, 'timestamp': timestamp }) subject = render_to_string( 'alerts/notifications/notification_title.html', dict(site_name=site_name, alert_name=_('device open'))) if uad.email_notification: logger.info( 'Open alert sent to {0} for device {1}'.format(user.email, device_name)) msg = BluuMessage(subject, body, user.email) msg.send() if uad.text_notification: logger.info('Open text alert sent to {0} for device {1}'. format(user.cell_text_email, device_name)) msg = BluuMessage(subject, body, user.cell_text_email) msg.send()
def alert_su(uas, status): """ Sends notification that scale has been used """ user = uas.user site = uas.device.bluusite if (user_alerts_allowed(user, site) or dealer_alerts_allowed(user, site)): device_name = uas.device.name room = uas.device.room.name site_name = uas.device.bluusite.name timestamp = status.timestamp body = render_to_string('alerts/notifications/su.html', { 'user': user, 'device_name': device_name, 'room': room, 'site_name': site_name, 'timestamp': timestamp, }) subject = render_to_string('alerts/notifications/notification_title.html', dict(site_name=site_name, alert_name=_('scale used'))) if uas.email_notification: logger.info('SU alert sent to {0} for device {1}'.format(user.email, device_name)) msg = BluuMessage(subject, body, user.email) msg.send() if uas.text_notification: logger.info('SU text alert sent to {0} for device {1}'.format( user.cell_text_email, device_name)) msg = BluuMessage(subject, body, user.cell_text_email) msg.send()
def alert_nomotion_greater_than(runner): uar = runner.user_alert_room user = uar.user room = uar.room.name site_name = uar.room.bluusite.name duration = uar.duration unit = uar.get_unit_display() timestamp = runner.since body = render_to_string('alerts/notifications/motion_nmirgt.html', { 'user': user, 'room': room, 'site_name': site_name, 'timestamp': timestamp, 'duration': duration, 'unit': unit }) subject = _(u'%(site_name)s alert - %(alert_name)s') % \ {'site_name': site_name, 'alert_name': _('no motion in room for too much time')} if uar.email_notification: logger.info('NMIRGT alert sent to {0} for room {1}'.format( user.email, room)) msg = BluuMessage(subject, body, user.email) msg.send() if uar.text_notification: logger.info('NMIRGT text alert sent to {0} for room {1}'.format( user.cell_text_email, room)) msg = BluuMessage(subject, body, user.cell_text_email) msg.send()
def alert_closed_greater_than(runner): uad = runner.user_alert_device user = uad.user device_name = uad.device.name room = uad.device.room.name site_name = uad.device.bluusite.name duration = uad.duration unit = uad.get_unit_display() timestamp = runner.since body = render_to_string('alerts/notifications/closed_gt.html', { 'user': user, 'device_name': device_name, 'room': room, 'site_name': site_name, 'timestamp': timestamp, 'duration': duration, 'unit': unit }) subject = _(u'%(site_name)s alert - %(alert_name)s') % \ {'site_name': site_name, 'alert_name': _('device closed too long')} if uad.email_notification: logger.info('CGT alert sent to {0} for device {1}'. \ format(user.email, device_name)) msg = BluuMessage(subject, body, user.email) msg.send() if uad.text_notification: logger.info('CGT text alert sent to {0} for device {1}'. \ format(user.cell_text_email, device_name)) msg = BluuMessage(subject, body, user.cell_text_email) msg.send()
def alert_mirlt(uar, timestamp): """ Sends notification about motion in room less than """ site = uar.room.bluusite user = uar.user if (user_alerts_allowed(user, site) or dealer_alerts_allowed(user, site)): room = uar.room.name site_name = site.name duration = uar.duration unit = uar.get_unit_display() period = settings.ALERT_PERIOD / 60 body = render_to_string('alerts/notifications/motion_mirlt.html', { 'user': user, 'room': room, 'site_name': site_name, 'timestamp': timestamp, 'duration': duration, 'unit': unit, 'period': period, 'period_unit': _('hours') }) subject = render_to_string('alerts/notifications/notification_title.html', dict(site_name=site_name, alert_name=_('to much motion in room'))) if user.email: logger.info('MIRLT alert sent to {0} for device {1}'.format( user.email, room)) msg = BluuMessage(subject, body, user.email) msg.send() if user.cell_text_email: logger.info('MIRLT text alert sent to {0} for device {1}'.format( user.cell_text_email, room)) msg = BluuMessage(subject, body, user.cell_text_email) msg.send()
def alert_wgt(uas, status): """ Sends notification that weight is greater than """ user = uas.user site = uas.device.bluusite if (user_alerts_allowed(user, site) or dealer_alerts_allowed(user, site)): device_name = uas.device.name room = uas.device.room.name site_name = uas.device.bluusite.name timestamp = status.timestamp weight = '{:.2f}'.format(status.float_data) weight_guard = uas.weight body = render_to_string('alerts/notifications/wgt.html', { 'user': user, 'device_name': device_name, 'room': room, 'site_name': site_name, 'timestamp': timestamp, 'weight': weight, 'weight_guard': weight_guard }) subject = render_to_string('alerts/notifications/notification_title.html', dict(site_name=site_name, alert_name=_( 'weight greater than expected'))) if uas.email_notification: logger.info('WGT alert sent to {0} for device {1}'.format(user.email, device_name)) msg = BluuMessage(subject, body, user.email) msg.send() if uas.text_notification: logger.info('WGT text alert sent to {0} for device {1}'.format( user.cell_text_email, device_name)) msg = BluuMessage(subject, body, user.cell_text_email) msg.send()
def alert_mir(uar, status): """ Sends MOTION IN ROOM alert. This one is send immediately after a motion status arrives """ user = uar.user site = status.device.bluusite # check here because this alert isn't called via alert runner if (user_alerts_allowed(user, site) or dealer_alerts_allowed(user, site)): device_name = status.device.name room = uar.room.name site_name = status.device.bluusite.name timestamp = status.timestamp body = render_to_string('alerts/notifications/mir.html', { 'user': user, 'device_name': device_name, 'room': room, 'site_name': site_name, 'timestamp': timestamp }) subject = render_to_string('alerts/notifications/notification_title.html', dict(site_name=site_name, alert_name=_('motion in room'))) if uar.email_notification: logger.info('Motion in room {0} alert sent to {1} for device {2}'. format(room, user.email, device_name)) msg = BluuMessage(subject, body, user.email) msg.send() if uar.text_notification: logger.info('Motion in room {0} text alert sent to {1} for device {2}'. format(room, user.cell_text_email, device_name)) msg = BluuMessage(subject, body, user.cell_text_email) msg.send()
def alert_active_in_period_greater_than(runner): uad = runner.user_alert_device user = uad.user device_name = uad.device.name room = uad.device.room.name site_name = uad.device.bluusite.name duration = uad.duration unit = uad.get_unit_display() timestamp = runner.since body = render_to_string('alerts/notifications/open_aipgt.html', { 'user': user, 'device_name': device_name, 'room': room, 'site_name': site_name, 'timestamp': timestamp, 'duration': duration, 'unit': unit, 'period': settings.ALERT_PERIOD / 60 }) subject = _(u'%(site_name)s alert - %(alert_name)s') % \ {'site_name': site_name, 'alert_name': _('active greater than expected in a period')} if uad.email_notification: logger.info('AIPGT alert sent to {0} for device {1}'.format(user.email, device_name)) msg = BluuMessage(subject, body, user.email) msg.send() if uad.text_notification: logger.info('AIPGT text alert sent to {0} for device {1}'. format(user.cell_text_email, device_name)) msg = BluuMessage(subject, body, user.cell_text_email) msg.send()