async def get_all_contact_groups( dbcon: DBConnection) -> Iterable[object_models.ContactGroup]: q = """select id, name, active from contact_groups""" contact_groups = [ object_models.ContactGroup(*row) for row in await dbcon.fetch_all(q) ] return contact_groups
async def get_contact_groups_for_monitor_group( dbcon: DBConnection, id: int) -> Iterable[object_models.ContactGroup]: q = """select cg.id, cg.name, cg.active from contact_groups as cg, monitor_group_contact_groups where cg.id=monitor_group_contact_groups.contact_group_id and monitor_group_contact_groups.monitor_group_id=%s""" return [ object_models.ContactGroup(*row) for row in await dbcon.fetch_all(q, (id, )) ]
async def get_contact_groups_for_metadata( dbcon: DBConnection, meta_key: str, meta_value: str) -> Iterable[object_models.ContactGroup]: q = """select cg.id, cg.name, cg.active from contact_groups as cg, object_metadata as meta where meta.key=%s and meta.value=%s and meta.object_type="contact_group" and meta.object_id=cg.id""" q_args = (meta_key, meta_value) return [ object_models.ContactGroup(*row) for row in await dbcon.fetch_all(q, q_args) ]
async def get_contact_group( dbcon: DBConnection, id: int) -> Any: # Use any because optional returns suck. """Get a single contact if it exists. Return a list of dicts, one dict describing each contacts information. """ q = """select id, name, active from contact_groups where id=%s""" row = await dbcon.fetch_row(q, (id, )) contact = None if row: contact = object_models.ContactGroup(*row) return contact
async def get_contact_groups_for_active_monitor( dbcon: DBConnection, monitor_id: int) -> Iterable[object_models.ContactGroup]: """Get contact groups for an active monitor.""" q = """select contact_groups.id, contact_groups.name, contact_groups.active from active_monitor_contact_groups, contact_groups where active_monitor_contact_groups.active_monitor_id = %s and active_monitor_contact_groups.contact_group_id = contact_groups.id""" return [ object_models.ContactGroup(*row) for row in await dbcon.fetch_all(q, (monitor_id, )) ]