예제 #1
0
    def __init__(self, **kwargs):
        self.content = {
            'title': kwargs.get('title', ''),
            'subtitle': kwargs.get('subtitle', ''),
            'icon': kwargs.get('icon') if kwargs.get('icon') else 'icon.png'
        }

        it = kwargs.get('icontype', '').lower()
        self.icon_type = it if it in ['fileicon', 'filetype'] else None

        valid = kwargs.get('valid', None)
        if isinstance(valid, (str, unicode)) and valid.lower() == 'no':
            valid = 'no'
        elif isinstance(valid, bool) and not valid:
            valid = 'no'
        else:
            valid = None

        self.attrb = {
            'uid': kwargs.get('uid', util.uid()),
            'arg': kwargs.get('arg', None),
            'valid': valid,
            'autocomplete': kwargs.get('autocomplete', None),
            'type': kwargs.get('type', None)
        }

        for key in self.content.keys():
            if self.content[key] is None:
                del self.content[key]

        for key in self.attrb.keys():
            if self.attrb[key] is None:
                del self.attrb[key]
예제 #2
0
    def __init__(self, **kwargs):
        self.content = {
            'title'     : kwargs.get('title', ''),
            'subtitle'  : kwargs.get('subtitle', ''),
            'icon'      : kwargs.get('icon') if kwargs.get('icon') else 'icon.png'
        }

        it = kwargs.get('icontype', '').lower()
        self.icon_type = it if it in ['fileicon', 'filetype'] else None

        valid = kwargs.get('valid', None)
        if isinstance(valid, (str, unicode)) and valid.lower() == 'no':
            valid = 'no'
        elif isinstance(valid, bool) and not valid:
            valid = 'no'
        else:
            valid = None

        self.attrb = {
            'uid'           : kwargs.get('uid', util.uid()),
            'arg'           : kwargs.get('arg', None),
            'valid'         : valid,
            'autocomplete'  : kwargs.get('autocomplete', None),
            'type'          : kwargs.get('type', None)
        }

        for key in self.content.keys():
            if self.content[key] is None:
                del self.content[key]

        for key in self.attrb.keys():
            if self.attrb[key] is None:
                del self.attrb[key]
예제 #3
0
    def handle(self, *args, **kwargs):
        while True:
            safe_print("[monitor] sleeping")
            time.sleep(random.uniform(config['sleep_interval'] * 2 / 3, config['sleep_interval'] * 4 / 3))

            if util.time() - self.last_cleanup >= 60000:
                self.last_cleanup = util.time()
                Check.objects.raw("UPDATE checks SET `lock` = '' WHERE TIMESTAMPDIFF(SECOND, last_locked, NOW()) >= 60")

                with recent_failures_lock:
                    for check_tuple in set(recent_failures):
                        if util.time() - check_tuple[1] >= 60000:
                            recent_failures.remove(check_tuple)

            uid = util.uid(16)
            free_threads = pool.free()

            update_query = "UPDATE checks SET `lock` = %s, last_locked = NOW() WHERE `lock` = '' AND (TIMESTAMPDIFF(SECOND, last_checked, NOW()) >= check_interval OR confirmations > 0)"
            params = [uid]

            with recent_failures_lock:
                if recent_failures:
                    update_query += " AND id NOT IN (" + ', '.join(['%s' for check_tuple in recent_failures]) + ")" 
                    params.extend([check_tuple[0] for check_tuple in recent_failures])

            update_query += " ORDER BY RAND() LIMIT %d" % (free_threads)
            safe_print("[monitor] fetching up to %d...", (free_threads))
            database.query(update_query, params)

            result = database.query("SELECT id, name, type, data, status, confirmations FROM checks WHERE `lock` = %s", (uid,))
            safe_print("[monitor] fetched %d checks", (result.rowcount))

            for row in result.fetchall():
                check_id = row['id']
                check_name = row['name']
                check_type = row['type']
                check_data = row['data']
                status = row['status']
                confirmations = row['confirmations']

                pool.queue(check_id, check_name, check_type, check_data, status, confirmations, uid)
예제 #4
0
last_cleanup = 0

while True:
	safe_print("[monitor] sleeping")
	time.sleep(random.uniform(config['sleep_interval'] * 2 / 3, config['sleep_interval'] * 4 / 3))

	if util.time() - last_cleanup >= 60000:
		last_cleanup = util.time()
		database.query("UPDATE checks SET `lock` = '' WHERE TIMESTAMPDIFF(SECOND, last_locked, NOW()) >= 60")

		with recent_failures_lock:
			for check_tuple in set(recent_failures):
				if util.time() - check_tuple[1] >= 60000:
					recent_failures.remove(check_tuple)

	uid = util.uid(16)
	free_threads = pool.free()

	update_query = "UPDATE checks SET `lock` = %s, last_locked = NOW() WHERE `lock` = '' AND (TIMESTAMPDIFF(SECOND, last_checked, NOW()) >= check_interval OR confirmations > 0)"
	params = [uid]

	with recent_failures_lock:
		if recent_failures:
			update_query += " AND id NOT IN (" + ', '.join(['%s' for check_tuple in recent_failures]) + ")"
			params.extend([check_tuple[0] for check_tuple in recent_failures])

	update_query += " ORDER BY RAND() LIMIT %d" % (free_threads)
	safe_print("[monitor] fetching up to %d...", (free_threads))
	database.query(update_query, params)

	result = database.query("SELECT checks.id, checks.name, check_type.name AS type, data, status, max_confirmations, confirmations FROM checks INNER JOIN check_type ON type=check_type.id WHERE `lock` = %s", (uid,))
예제 #5
0
    time.sleep(
        random.uniform(config['sleep_interval'] * 2 / 3,
                       config['sleep_interval'] * 4 / 3))

    if util.time() - last_cleanup >= 60000:
        last_cleanup = util.time()
        database.query(
            "UPDATE checks SET `lock` = '' WHERE TIMESTAMPDIFF(SECOND, last_locked, NOW()) >= 60"
        )

        with recent_failures_lock:
            for check_tuple in set(recent_failures):
                if util.time() - check_tuple[1] >= 60000:
                    recent_failures.remove(check_tuple)

    uid = util.uid(16)
    free_threads = pool.free()

    update_query = "UPDATE checks SET `lock` = %s, last_locked = NOW() WHERE `lock` = '' AND (TIMESTAMPDIFF(SECOND, last_checked, NOW()) >= check_interval OR confirmations > 0)"
    params = [uid]

    with recent_failures_lock:
        if recent_failures:
            update_query += " AND id NOT IN (" + ', '.join(
                ['%s' for check_tuple in recent_failures]) + ")"
            params.extend([check_tuple[0] for check_tuple in recent_failures])

    update_query += " ORDER BY RAND() LIMIT %d" % (free_threads)
    safe_print("[monitor] fetching up to %d...", (free_threads))
    database.query(update_query, params)