How to use the oncall.db.connect function in oncall

To help you get started, we’ve selected a few oncall examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github linkedin / oncall / src / oncall / bin / notifier.py View on Github external
def mark_message_as_unsent(msg_info):
    connection = db.connect()
    cursor = connection.cursor()
    cursor.execute('UPDATE `notification_queue` SET `active` = 0, `sent` = 0 WHERE `id` = %s',
                   msg_info['id'])
    connection.commit()
    connection.close()
    cursor.close()
github linkedin / oncall / src / oncall / auth / modules / ldap_import.py View on Github external
ldap_contacts[key] = ldap_attrs.get(val)[0]
                        else:
                            ldap_contacts[key] = ldap_attrs.get(val)
                    else:
                        ldap_contacts[key] = val

            connection.simple_bind_s(auth_user, password)

        except ldap.INVALID_CREDENTIALS:
            return False
        except (ldap.SERVER_DOWN, ldap.INVALID_DN_SYNTAX) as err:
            logger.warn("%s", err)
            return None

        if self.import_user:
            connection = db.connect()
            cursor = connection.cursor(db.DictCursor)
            if user_exists(username, cursor):
                logger.info("user %s already exists, updating from ldap", username)
                update_user(username, ldap_contacts, cursor)
            else:
                logger.info("user %s does not exists. importing.", username)
                import_user(username, ldap_contacts, cursor)
            connection.commit()
            cursor.close()
            connection.close()

        return True
github linkedin / oncall / src / oncall / bin / notifier.py View on Github external
def poll():
    query = '''SELECT `user`.`name` AS `user`, `contact_mode`.`name` AS `mode`, `notification_queue`.`send_time`,
                      `user`.`time_zone`,`notification_type`.`subject`, `notification_queue`.`context`,
                      `notification_type`.`body`, `notification_queue`.`id`
               FROM `notification_queue` JOIN `user` ON `notification_queue`.`user_id` = `user`.`id`
                   JOIN `contact_mode` ON `notification_queue`.`mode_id` = `contact_mode`.`id`
                   JOIN `notification_type` ON `notification_queue`.`type_id` = `notification_type`.`id`
               WHERE `notification_queue`.`active` = 1 AND `notification_queue`.`send_time` <= UNIX_TIMESTAMP()'''
    logger.info('[-] start send task...')

    connection = db.connect()
    cursor = connection.cursor(db.DictCursor)
    cursor.execute(query)
    for row in cursor:
        send_queue.put(row)
    cursor.close()
    connection.close()