예제 #1
0
def handle_UpdateAll():
    try:
        houses = get_house_statuses_from_drona()
        blacklisted = BLACKLISTED
        for house in houses:
            if house['display_id'] in blacklisted:
                continue
            try:
                h = House.objects.get(house_id=house['display_id'])
            except:
                h = House.objects.create(house_id=house['display_id'])

            if (not house['master_status']) and h.status == 'ACTIVE':
                h.status = 'ERRORED' + " " + datetime.datetime.now(pytz.timezone('Asia/Calcutta')).strftime(
                    "%Y-%m-%d %H:%M:%S")
            if house['master_status']:
                h.status = 'ACTIVE'
            h.code_version = house['code_version']
            h.save()
        houses = House.objects.filter(to_update=True)
        alerts = {}

        for house in houses:
            dyfo_house = DyfoHouseHealth(house.house_id)
            data = dyfo_house.checkAstroRestarts(DAY_SECONDS)
            alert = handle_UpdateRestarts(data)
            if alert:
                if house.house_id not in alerts:
                    alerts[house.house_id] = {}
                    alerts[house.house_id]['name'] = house.house_name
                alerts[house.house_id]['Restarts'] = alert

            data = dyfo_house.checkQuickInterrupt(DAY_SECONDS)
            alert = handle_UpdateQInterrupts(data, house.house_id)
            if alert:
                if house.house_id not in alerts:
                    alerts[house.house_id] = {}
                    alerts[house.house_id]['name'] = house.house_name

                alerts[house.house_id]['Quick_Interrupts'] = alert

            data = dyfo_house.checkLongDisconnect()
            alert = handle_UpdateLongCutoff(data, house.house_id)
            if alert:
                if house.house_id not in alerts:
                    alerts[house.house_id] = {}
                    alerts[house.house_id]['name'] = house.house_name
                alerts[house.house_id]['Long_Disconnect'] = alert

        if alerts:
            send_alert(alerts)

        update_last_update()
    except Exception as e:
        logger.error("Exception in updating Houses. Exception " + str(e))
        raise e
예제 #2
0
def alert_status(users):
	for user in users:
		for item in user.url_users:
			scheduled_down = check_downtime(item.url.url_address, item.url.id, item.url.downtime_start, item.url.downtime_end)
			alert_threshold = item.url.alert_threshold
			if scheduled_down == 'no':
				status = orm.session.query(orm.Result).filter_by(url_id=item.url.id).order_by(desc(orm.Result.date_time_run)).all()
				latest_status_result = status[0]
				previous_status_result = status[1]
				if latest_status_result.result != '200':
					alerts.send_alert(user.email, latest_status_result.result, item.url.url_address)
					print 'Sent email to %s about %s with status code %s' % (user.email, item.url.url_address, latest_status_result.result)
				elif latest_status_result.page_load_time > alert_threshold:
					alerts.send_alert(user.email, latest_status_result.page_load_time, item.url.url_address)
					print 'Sent email to %s about %s page load time greater than %r seconds' % (user.email, item.url.url_address, alert_threshold)
				elif latest_status_result.result != '200' and previous_status_result.result != '200':
					alert_message = '%s has replied with a status code of %s. You should take a look at it.' % (item.url.url_address, latest_status_result.result)
					alerts.send_sms_alert(user.phone_number, alert_message)
					print 'Sent SMS to %s about %s with status_code %s' % (user.email, item.url.url_address, latest_status_result.result)
				elif latest_status_result.page_load_time > alert_threshold and previous_status_result.page_load_time > alert_threshold:
					alert_message = '%s took %r seconds to respond, which is greater than your threshold of %r. You should take at look at it.' % (item.url.url_address, latest_status_result.page_load_time, item.url.alert_threshold)
					alerts.send_sms_alert(user.phone_number, alert_message)
					print 'Sent SMS to %s about %s page load time greater than %r seconds' % (user.email, item.url.url_address, alert_threshold)
예제 #3
0
def check_liquid_levels():
    """Reads the sensor data from the scales attached to the Pi's GPIO ports
    then reads the weight of just the liquid of each when its full and the weight
    of the container when its empty from a JSON file created by the 
    set_liquid_weights() function
  """
    water_weight = GPIO.input(water_scale)
    nutrient_weight = GPIO.input(nutrient_scale)
    ph_weight = GPIO.input(ph_scale)

    with open('<path to json file>') as weights_chart:
        weights = json.load(weights_chart)

    ph_full_weight = weights['ph']['liquid_wieght']
    ph_empty_weight = weights['ph']['empty_weight']
    nutrient_full_weight = weights['nutrient']['liqiud_weight']
    nutrient_empty_weight = weights['nutrient']['empty_weight']
    water_full_weight = weights['water']['liquid_weight']
    water_empty_weight = weights['water']['empty_weight']

    ph_percentage = int(((ph_weight - ph_empty_weight) / ph_full_weight) * 100)
    nutrient_percentage = int(
        ((nutrient_weight - nutrient_empty_weight) / nutrient_full_weight) *
        100)
    water_percentage = int(
        ((water_weight - water_empty_weight) / water_full_weight) * 100)

    # TODO Decide on percentages for alerting, should probably be editable and saved in the
    # JSON as well so they can be updated as we learn or the computer learns
    if water_percentage < 50:
        alerts.send_alert('water-level', water_percentage)
    if nutrient_percentage < 50:
        alerts.send_alert('nutrient-level', water_percentage)
    if ph_percentage < 50:
        alerts.send_alert('ph-level', water_percentage)

    return water_percentage, nutrient_percentage, ph_percentage
예제 #4
0
def dilute_nutrients(nutrient_level, nutrient_high):
    """Needs to either alert user to add water to container or create system to
    automatically add water from either a seperate reservoir or spiget
  """
    alerts.send_alert('dilute-nutrients', nutrient_level)
from alerts import send_alert

user = db.users.find_one({"id" : TEST_USER})
photo = db.photos.find_one({})

if not 'badge' in user['custom_fields']:
    user['custom_fields']['badge'] = 0

if user['custom_fields']['language'] == 'ru':
    message = "%s обнаружил радугу возле %s" % (photo['user']['username'], photo['custom_fields']['name_ru'])
else:
    message = "%s spotted a rainbow near %s" % (photo['user']['username'], photo['custom_fields']['name_en'])

send_alert({
    "channel": "raduga_predictions",
    "to_ids": [user['id']],
    "payload": {
        "alert": message,
        "type": "rainbow_spotted",
        "sound": "default",
        "vibrate": True,
        "username": photo['user']['username'],
        "name_en": photo['custom_fields']['name_en'],
        "name_ru": photo['custom_fields']['name_ru'],
        "photo_id": photo['id'],
        "badge": user['custom_fields']['badge'] + 1
    }
 })

db.users.update({"id" : TEST_USER}, {'$inc': {'custom_fields.badge': 1}})
예제 #6
0
    parser.add_argument('--grating_step',
                        type=int,
                        default=0,
                        help='Blazed grating slope. DEFAULT="0"')
    parser.add_argument(
        '--num_initial_metrics',
        type=int,
        default=500,
        help=
        'Number of uniform mask measurements to average over for initial metric values. DEFAULT="100"'
    )
    try:
        main(parser.parse_args(), folder)
    except Exception as e:
        print('caught error')
        send_alert(message=str(e))
        try:
            with open(os.path.join(folder, 'status.txt'), 'a') as statusfile:
                statusfile.write(
                    str(time.strftime('-----------------------\n\n')))
                statusfile.write(
                    str(time.strftime("%a, %d %b %Y %H:%M:%S")) + '\n\n')
                statusfile.write(str(e) + '\n')
                statusfile.write(traceback.format_exc() + '\n')
                print(traceback.format_exc())
        except Exception as a:
            send_alert(message=str(a))

    # run complete
    send_alert(message='', subject='Lab430 Run Ended.')
    try:
예제 #7
0
                        help='Blazed grating slope. DEFAULT="0"')
    parser.add_argument(
        '--num_initial_metrics',
        type=int,
        default=50,
        help=
        'Number of uniform mask measurements to average over for initial metric values. DEFAULT="100"'
    )

    main_error = False
    try:
        main(parser.parse_args(), folder)
    except Exception as e:
        print('caught error')
        main_error = True
        send_alert(message=str(e))
        try:
            with open(os.path.join(folder, 'status.txt'), 'a') as statusfile:
                statusfile.write(
                    str(time.strftime('-----------------------\n\n')))
                statusfile.write(
                    str(time.strftime("%a, %d %b %Y %H:%M:%S")) + '\n\n')
                statusfile.write(str(e) + '\n')
                statusfile.write(traceback.format_exc() + '\n')
                print(traceback.format_exc())
        except Exception as a:
            send_alert(message=str(a))

    # run complete
    if not main_error:
        send_alert(message='Lab 118 Run ended without error.',